Jump to content

Recommended Posts

Posted

Hello everyone!

I've encountered a strange problem while adding files (or rather file names) to a ListView.
Mechanics are simple:
1. Select files to add (FileOpenDialog + Multiselect)
2. Split selected string (filepath) into array (StringSplit)
3. File names appear on ListView (GUICtrlCreateListViewItem)

Writing starts from second array (since 0 is array size, and 1 is filepath).
Problem occurs when I try to add one file. Then, no filenames are added.
As far as I know, selecting one file generates only 2 strings (0 and 1) to split, therefore no string is written into ListView.
 

Is there any way / workaround to make this thing work properly?

Some code here:

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
        ExitLoop

        Case $idAddTest
               $sMessage = "Select test cases to load:"
               $sFileOpenDialog = FileOpenDialog($sMessage, @WorkingDir & "\data\tests\", "All (*.*)", $FD_FILEMUSTEXIST & $FD_MULTISELECT)
                If @error Then
                MsgBox($MB_SYSTEMMODAL, "", "No test(s) were selected.")
                FileChangeDir(@ScriptDir)
            Else
               FileChangeDir(@ScriptDir)
               $aFileList = StringSplit($sFileOpenDialog, "|", @CRLF)
                    For $i = 2 to $aFileList[0]

                        MsgBox( 0, "test", $aFileList[$i]) ;just for testing purposes

                    GUICtrlCreateListViewItem($aFileList[$i], $idTestCaseList)
                    Next
            EndIf
    EndSwitch
 WEnd

 

And nothing more spectacular from ListView side:

Global $idTestCaseList = GUICtrlCreateListView("List of Tests             ", 24, 24, 225, 502, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
        GUICtrlSetTip(-1, "List of test cases."& @CRLF &"Hold CTRL to select multiple lines.")

 

Any help appreciated!

Posted

Check for an array after the StringSplit line, and if it's not an array, it's a single file and process accordingly, if it is an array, then continue using the present method.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted
15 hours ago, BrewManNH said:

Check for an array after the StringSplit line, and if it's not an array, it's a single file and process accordingly, if it is an array, then continue using the present method.

Hey!

Took me some time, but I've managed to find magical _PathSplit function :)
That's how it looks right now, and is working properly :)
Thanks for help!
 

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
        ExitLoop

        Case $idAddTest
               Local $cFilepath
               Local $cFilename
               Local $cDrivepath
               Local $cDirpath
               Local $cExtension
               $sMessage = "Select test cases to load:"
               $sFileOpenDialog = FileOpenDialog($sMessage, @WorkingDir & "\data\tests\", "All (*.*)", $FD_FILEMUSTEXIST & $FD_MULTISELECT)
                If @error Then
                MsgBox($MB_SYSTEMMODAL, "", "No test(s) were selected.")
                FileChangeDir(@ScriptDir)
            Else
               FileChangeDir(@ScriptDir)
               $aFileList = StringSplit($sFileOpenDialog, "|", @CRLF)
                If $aFileList[0] = 1 Then
                    _PathSplit($aFileList[1], $cDrivepath, $cDirpath, $cFilename, $cExtension)
                    GUICtrlCreateListViewItem($cFilename & $cExtension, $idTestCaseList)
                ElseIf $aFilelist[0] >2 Then
                For $i = 2 to $aFileList[0]

                        MsgBox( 0, "test", $aFileList[$i])

                    GUICtrlCreateListViewItem($aFileList[$i], $idTestCaseList)
                Next
                EndIf
            EndIf
          (...)
     EndSwitch
WEnd

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...