Jump to content

MultiSelect frustration


Recommended Posts

I have always had this problem -- I can't get MultiSelect to work when I know it should.

Example:

GUICtrlSetData($file,"")
                $dirInit = RegRead("HKEY_CURRENT_USER\SOFTWARE\packJPG Options", "LastUsedDir")
                $var =  FileOpenDialog("Choose a File", $dirInit, "JPG & Compressed JPG (*.jpg;*.pjg)", 2 + 4)
                If @error Then
                    MsgBox(4096,"","No File(s) chosen")
                Else
                    $var = StringReplace($var, "|", @CRLF)
                    MsgBox(4096,"","You chose " & $var)
                    GUICtrlSetData($file,$var)
                ; Write a single REG_SZ value
                    RegWrite("HKEY_CURRENT_USER\SOFTWARE\packJPG Options", "LastUsedDir", "REG_SZ", @workingdir)
                EndIf

If I select a single file it's fine. If I select multiple files they show up as line item files but don't process.

Any and all help much appreciated. I must be close??

Mike Lee

Link to comment
Share on other sites

I have always had this problem -- I can't get MultiSelect to work when I know it should.

Example:

GUICtrlSetData($file,"")
                $dirInit = RegRead("HKEY_CURRENT_USER\SOFTWARE\packJPG Options", "LastUsedDir")
                $var =  FileOpenDialog("Choose a File", $dirInit, "JPG & Compressed JPG (*.jpg;*.pjg)", 2 + 4)
                If @error Then
                    MsgBox(4096,"","No File(s) chosen")
                Else
                    $var = StringReplace($var, "|", @CRLF)
                    MsgBox(4096,"","You chose " & $var)
                    GUICtrlSetData($file,$var)
            ; Write a single REG_SZ value
                    RegWrite("HKEY_CURRENT_USER\SOFTWARE\packJPG Options", "LastUsedDir", "REG_SZ", @workingdir)
                EndIf

If I select a single file it's fine. If I select multiple files they show up as line item files but don't process.

Any and all help much appreciated. I must be close??

Mike Lee

If this script below does not list the files selected and you are holding down the shift key or Ctrl key with a mouse left click to multi-select the files, and you are using AutoIt 3.2.12.1 version or later, I don't know what's wrong.

From help file under FileOpenDialog

Success: Returns the full path of the file(s) chosen. Results for multiple selections are "Directory|file1|file2|..."

It should be easier to process the file names from an array.

local $sContents
$var = FileOpenDialog("Choose a File", "", "JPG & Compressed JPG (*.jpg;*.pjg)", 2 + 4)
If @error Then
    MsgBox(4096, "", "No File(s) chosen")
Else
    $aVar = StringSplit($var, "|")
    for $x = 2 to UBound($aVar)-1
        $sContents &= $aVar[1] & "\" & $aVar[$x] & @CRLF        
    next
    
    $sContents &=  @CRLF & "or" & @CRLF & @CRLF 
    
    for $x = 0 to UBound($aVar)-1
        $sContents &= "$aVar["& $x & "]  = " &  $aVar[$x] & @CRLF       
    next
    
    MsgBox(4096, "", "You chose :-" & @CRLF & $sContents)

EndIf

I hope this helps.

Link to comment
Share on other sites

If I select multiple files they show up as line item files but don't process.

I'm not sure what you mean by this, what are "line item files"? What doesn't process??

You do know the format of returning multi-selected files right? It looks like this: Directory|File1|File2|File3|File4

So if I am in my system folder and select several files, the return will look like this: C:\WINDOWS\System32|cmd.exe|logonui.exe|mspaint.exe|notepad.exe

So maybe just replacing the | with @CRLF is not doing what you want in your situation, because you're getting something like this?

C:\WINDOWS\System32
cmd.exe
logonui.exe
mspaint.exe
notepad.exe

But as far as your code goes, it's working fine for me, I see the multiple files I selected.

Link to comment
Share on other sites

Malkey and Rob:

I am selecting the files with Shift or Ctrl and they do show up as

You chose C:\Documents and Settings\Lee\Desktop\New Folder
test_image1.jpg
test_image2.jpg
test_image3.jpg

So Rob you are correct - but what do I change to have them Directory|File1|File2|File3?

Malkey, I tried your array code and it "almost" worked, reporting the full path for each file, but not as Directory|File1|File2|File3

(I have never used such array code before.)

I am using AutoIt 3.2.10. Should this make a difference?

You both recognize the issue. I believe the solution is near. I need more help please.

Mike

Link to comment
Share on other sites

So Rob you are correct - but what do I change to have them Directory|File1|File2|File3?

Malkey, I tried your array code and it "almost" worked, reporting the full path for each file, but not as Directory|File1|File2|File3

(I have never used such array code before.)

I am using AutoIt 3.2.10. Should this make a difference?

You both recognize the issue. I believe the solution is near. I need more help please.

Mike

The only difference I could find was in version 3.2.12.0 (16th May, 2008) (Release), an added parent window parameter to the FileOpenDialog() function.

So there should be no difference in the return values between your AutoIt version an the current version.

If you want the return value format that is mentioned in the help, namely Directory|File1|File2|File3, do not change the the contents of the return variable of the FileOpenDialog() function before displaying it in the MsgBox() function.

See example.

$var = FileOpenDialog("Choose a File", "", "JPG & Compressed JPG (*.jpg;*.pjg)", 2 + 4)
If @error Then
    MsgBox(4096, "", "No File(s) chosen")
Else
    ;$var = StringReplace($var, "|", @CRLF) ;<-- Changes the contents of variable $var
    MsgBox(4096, "", "You chose " & $var)

EndIf
Link to comment
Share on other sites

Rob,

I am trying to fill a GUICtrlCreateInput window with the file names (values). I got it to display Directory|File1|File2|File3|File4 (as it should?) but anything over one value and it fails. I know positively that the executable accepts multiples files by drag and drop so that is not an issue. I shoot to off to you while you are still on-line.

Mike

Link to comment
Share on other sites

Well Input has no MultilineStyle. you have to use GUICtrlCreateEdit :P

And you didn't post the Code how you run your executable. I think, there must be the Error.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Got your email Mike Lee, but I'm going to reply here just because the forum will format the code I have a little better. :P

One little thing I noticed is you forgot to #include <ButtonConstants.au3> at the top and you use $BS_ICON, but I'll chalk that up to simple typo or something. :(

And another little thing that doesn't necessarily affect your script is that you're using double equals (==) for a number comparison when it's only really necessary for case sensitive string comparison (where you're checking if the checkboxes are marked, ie: GUICtrlRead($checkoverwrite)== $GUI_CHECKED).

Now down to the important part. First off, I'm not completely sure if this is what you want, but it appears that you're looking to be able to select multiple files, then have the packJPG process all of them. That's where you were running into trouble, correct? If that's the case you're going to have to go about this just a little differently.

First off, I would recommend switching the input control for an edit control, it's bigger and allows for multiple lines, which would be the best way to display multiple files, but you'll have to change some other stuff then too, so for now we'll just stick with the input control.

Next you need to reinterpret the results from FileOpenDialog, you were on the right track but it's not as simple as you'd hoped I'm guessing. The best way to do this is to separate the result into an array, then pair up each File with the Folder it was in, then write that to the control. Something like this:

$var =  FileOpenDialog("Choose File(s) (use Ctrl or Shift to select multiple files)", $dirInit, "JPG & Compressed JPG (*.jpg;*.pjg)", 2 + 4)
If @error Then
    MsgBox(4096,"","No File(s) chosen")
Else
    If StringInStr($var, "|") Then; First we check to see if there were multiple files selected.
        $fileOutput = ""; We'll start this variable as a place to put the eventual contents of the edit control
        $fileArray = StringSplit($var, "|"); This will split up the string into separate array entries, so each chunk of string between | marks is now more like a separate variable
        $folder = $fileArray[1]; The first part of the return from FileOpenDialog was the folder, so we'll kind of set that aside here
        For $i = 2 to $fileArray[0]; Arrays always start at index 0, StringSplit sets the value of this index to the total number of elements that were created. We start at 2 ($i = 2) because 1 was already used for the folder path
            $fileOutput &= '"' & $folder & "\" & $fileArray[$i] & '" '; This will put each file with it's folder name into the $fileOutput variable, wrapped with quotation marks, and separated by spaces. packJPG will accept multiple files in this format
        Next
        MsgBox(4096,"","You chose " & $fileOutput)
        GUICtrlSetData($file, $fileOutput)
    Else
        MsgBox(4096,"","You chose " & $var)
        GUICtrlSetData($file,$var)
    EndIf
;$var = StringReplace($var, "|", @CRLF);<---another option which didn't work
    MsgBox(4096,"","You chose " & $var)
    GUICtrlSetData($file,'"' & $var & '"')
; Write a single REG_SZ value
EndIf

I took out the registry stuff just to make it a little cleaner.

Anyway, then all you should have to do is modify the Run() line a little bit to take out the quotations you were adding (since they'll be part of the overall variable now)

So this:

Run ( $prog &'  '&$option&'   '  &' "'&GUICtrlRead($file)&'"',"",@SW_HIDE)

Becomes this:

Run ( $prog &'  '&$option&'   '  & GUICtrlRead($file),"",@SW_HIDE)

Let me know how that works out for you, though it

Link to comment
Share on other sites

Rob,

Your explanation and example of how an array would better suit my needs were very helpful. Things now work as I wanted them to. I have learned a lot about arrays from your commented code. I am sure I'll be implementing it more often. Many thanks.

Mike

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...