Jump to content

File Selection Dialog That Grabs File Path And Saves As Variable


rm4453
 Share

Recommended Posts

I am using Koda to create a gui that will be used to login to a site and post a listing. I need to find a way to get Koda to add a file select button that opens the file selection window, and saves all of the images file paths that are selected, and keeps track of how many there were. That way it can paste the file path into the site along with a description of the image, and click submit for each of the images selected. I need it to store these variables in a .ini if possible as well that way everything will load back up exactly how it was, if it was to ever be closed. Here is the code that Koda has generated for me so far... "See attached for actual Koda Import File"

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=*******
$Form1 = GUICreate("Form1", 615, 437, 340, 172)
$Email = GUICtrlCreateInput("Email", 24, 35, 145, 21)
$Password = GUICtrlCreateInput("Password", 24, 61, 145, 21)
$Submit = GUICtrlCreateButton("Submit", 59, 88, 75, 25)
$LoginInfo = GUICtrlCreateGroup("LoginInfo", 8, 8, 177, 113)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$ListingInfo = GUICtrlCreateGroup("ListingInfo", 200, 8, 401, 417)
$Price = GUICtrlCreateInput("Price", 232, 40, 137, 21)
$Title = GUICtrlCreateInput("Title", 232, 72, 137, 21)
$Description = GUICtrlCreateEdit("", 232, 200, 337, 105)
GUICtrlSetData(-1, "Description")
$ListingType = GUICtrlCreateGroup("ListingType", 376, 24, 193, 81)
$For_Sale = GUICtrlCreateRadio("For_Sale", 384, 39, 193, 21)
$Item_Wanted = GUICtrlCreateRadio("Item_Wanted", 384, 71, 193, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Business_or_Private = GUICtrlCreateGroup("Business_or_Private", 232, 112, 337, 65)
$Business_Listing = GUICtrlCreateRadio("Business_Listing", 248, 136, 153, 25)
$Private_Listing = GUICtrlCreateRadio("Private_Listing", 408, 136, 153, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$ContactInfo = GUICtrlCreateGroup("ContactInfo", 232, 312, 337, 73)
$Phone1 = GUICtrlCreateInput("801", 237, 330, 33, 21)
$Phone3 = GUICtrlCreateInput("1080", 317, 330, 33, 21)
$Phone2 = GUICtrlCreateInput("808", 277, 330, 33, 21)
$Address = GUICtrlCreateInput("Address", 360, 328, 201, 21)
$City = GUICtrlCreateInput("City", 360, 352, 49, 21)
$State = GUICtrlCreateInput("State example: UT", 416, 352, 97, 21)
$Zip = GUICtrlCreateInput("Zip", 520, 352, 41, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$SubmitListing = GUICtrlCreateButton("SubmitListing", 456, 392, 113, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

 

Listing Gui Layout.kxf

Edited by rm4453
Remove Personal Data
Link to comment
Share on other sites

Can anyone confirm if this will work?

 

Func OpenImages()
$message = "Hold down Ctrl or Shift to choose multiple files."

$var = FileOpenDialog($message, @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4 )

If @error Then
    MsgBox(4096,"","No File(s) chosen")
Else
    $varsplit = StringSplit($var, "|")
    $filePath = $varsplit[0] & "\" ; Do this because it returns first part of filepath without file name in slot 0, and 1 will be first images name.
EndIf
EndFunc

 

Link to comment
Share on other sites

No it can't work:

Quote

Returns an array, by default the first element ($aArray[0]) contains the number of strings returned

see remarks in helfile to stringsplit. When using flag $STR_NOCOUNT it works but only if >1 file(s) selected. So do it like this:

Func OpenImages()
    $message = "Hold down Ctrl or Shift to choose multiple files."

    $var = FileOpenDialog($message, @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4)

    If @error Then
        MsgBox(4096, "", "No File(s) chosen")
    Else
        $varsplit = StringSplit($var&"|", "|")
        $filePath = $varsplit[0] & "\" ; Do this because it returns first part of filepath without file name in slot 0, and 1 will be first images name.
        ;_ArrayDelete($varsplit[0]) ;removing empty string if file(s) needed 
    EndIf
EndFunc   ;==>OpenImages

 

Link to comment
Share on other sites

6 hours ago, AutoBert said:

No it can't work:

see remarks in helfile to stringsplit. When using flag $STR_NOCOUNT it works but only if >1 file(s) selected. So do it like this:

Func OpenImages()
    $message = "Hold down Ctrl or Shift to choose multiple files."

    $var = FileOpenDialog($message, @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4)

    If @error Then
        MsgBox(4096, "", "No File(s) chosen")
    Else
        $varsplit = StringSplit($var&"|", "|")
        $filePath = $varsplit[0] & "\" ; Do this because it returns first part of filepath without file name in slot 0, and 1 will be first images name.
        ;_ArrayDelete($varsplit[0]) ;removing empty string if file(s) needed 
    EndIf
EndFunc   ;==>OpenImages

 

I did this and it works just fine... had to change $filePath = $varsplit[0] to $filepath = $varsplit[1]  (see ex)

 

Func OpenImages()
$message = "Hold down Ctrl or Shift to choose multiple files."

$var = FileOpenDialog($message, @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4 )

If @error Then
    MsgBox(4096,"","No File(s) chosen")
Else
    $varsplit = StringSplit($var, "|")
    $filePath = $varsplit[1] & "\" ; Do this because it returns first part of filepath without file name in slot 1, and 2 will be first images name.
    $filepathmsg = MsgBox("Path","Here is File Path", $filepath)
EndIf
EndFunc
$1 = 1
while 1 = $1
    OpenImages()
    $1 = 2
WEnd

THANKS FOR ALL THE HELP! :D

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

×
×
  • Create New...