rm4453

File Selection Dialog That Grabs File Path And Saves As Variable

4 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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

 

Share this post


Link to post
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

 

Share this post


Link to post
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

Share this post


Link to post
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

  • Similar Content

    • anusha
      By anusha
      Hi I have jus started using auto-it . Please correct me if I'm wrong.
      I need to read data from an input in text box and search in excel file and return value in next column of matched cell on GUI.
      I have written below code but i cannot use variable which has data stored. it works only when search string is hard coded.
      Please help out.
       
      Example()
      Func Example()
      Local $GuiMain = GUICreate("EXCEL TEST", 399, 180) ;creates main GUI
      ;~ Local $idOK = GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
      Local $iWidthCell = 70
      Local $idLabel = GUICtrlCreateLabel("PART NUMBER", 10, 30, $iWidthCell,50)
      Local $RUN_1 = GUICtrlCreateButton("OK", 70, 70, 85, 25)
      Local $Input_1 = GUICtrlCreateInput("PART NUMBER", 100, 20, 120, 20)
      Local $sMenutext = GUICtrlRead($Input_1, 1)
      GUISetState(@SW_SHOW, $GuiMain)

          While 1
          $MSG = GUIGetMsg()
          Select
              Case $MSG = $GUI_EVENT_CLOSE
                  Exit
              Case $MSG = $RUN_1
                  Local $oAppl = _Excel_Open()

      Local $sFilePath1 = "D:\Anu_WorkFolder\Components.xlsx"
      Local $oWorkbook = _Excel_BookOpen($oAppl, $sFilePath1, Default, Default, True)
      Local $aResult = _Excel_RangeFind($oWorkbook, $sMenutext , Default, Default, $xlWhole)
    • X_xkijux_x
      By X_xkijux_x
      Ok so im using this program. clarify for school. I would like to have a program that takes every word i type in microsoft word and searches on it in claryfi. is this possible. I would like to have the program not stopping me from typing more after that word. Like when i type a word it auto search it on clarify without making me stop typing and if i want to change i can do that and if im fine that word i can just keep typing and it will search after the next word. 
    • Miliardsto
      By Miliardsto
      Is this possible to make program works like in diagram? There is so much encryption methods and UDFs are they give security? If the $Address will be crypted with some encryption algorithm could be possible to get the value of $Address in easy way? Of course We know its easy too look into autoit code and get value of variable and so We dont want to anyone see $Address value - there are functions Could func1.au3, func2.au3.. be for example func1.php or other type of file? As we know .php files are unnable to see. For example func1 would be read by FileRead() and then Execute() Is this generally possible to do?
      Will it give secure?
      What do you think about? Maybe there is something wrong in this concept or missed.

    • JaredStroeb
      By JaredStroeb
      I need to open an application and send it keys in Session 0.  I have exe's working locally, I can see the application open in session 0 through interactive services, but my send commands do not go to the application.  The following article running-autoit-session-0, directs me to use ControlSend() however my application has no controls that can be identified by AutoIt v3 Window Info.  Get All Windows Controls also returned nothing for the application's handle.  
      What are my options?  
      Can this be done with AutoIt?
      Is there a different "relatively simple" library/tool to use? (I am familiar with C# if there is a viable library there )

       
    • Miliardsto
      By Miliardsto
      Hello.
      Drag option works only on parent window but as we can see on the parent gui is showed up child gui (on the right side with the color).
      Desired action is when we want to drag whole program we can also drag child gui and child gui will drag with parent gui.
      How to do this?
       
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> GUIRegisterMsg($WM_NCHITTEST, "_NCHITTEST") $hGUI = GUICreate("Test", 500, 500, -1, -1) $cButton_0 = GUICtrlCreateButton("Child 0", 10, 10, 80, 30) $cButton_1 = GUICtrlCreateButton("Child 1", 10, 50, 80, 30) $cButton_2 = GUICtrlCreateButton("Child 2", 10, 90, 80, 30) GUISetState(@SW_SHOW, $hGUI) ; guis Global $hChild_[3] Global $countGUI = UBound($hChild_) - 1 ;MsgBox("","",$countGUI) ; licznik dla GUI Global $gui = 0 $hChild_[0] = GUICreate("Child 0", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0xFF0000) GUISetState(@SW_SHOW, $hChild_[0]) $hChild_[1] = GUICreate("Child 1", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0x00FF00) GUISetState(@SW_HIDE, $hChild_[1]) $hChild_[2] = GUICreate("Child 2", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0x0000FF) GUISetState(@SW_HIDE, $hChild_[2]) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton_0 _All_Hide() GUISetState(@SW_SHOW, $hChild_[0]) $gui = 0 Case $cButton_1 _All_Hide() GUISetState(@SW_SHOW, $hChild_[1]) $gui = 1 Case $cButton_2 _All_Hide() GUISetState(@SW_SHOW, $hChild_[2]) $gui = 2 EndSwitch WEnd Func _All_Hide() GUISetState(@SW_HIDE, $hChild_[0]) GUISetState(@SW_HIDE, $hChild_[1]) GUISetState(@SW_HIDE, $hChild_[2]) EndFunc Func _NCHITTEST($hWnd, $uMsg, $wParam, $lParam) If $hWnd = $hGUI Then Local $aPos = WinGetPos($hWnd) If Abs(BitAND(BitShift($lParam, 16),0xFFFF)- $aPos[1]) < 500 Then Return $HTCAPTION EndIf Return $GUI_RUNDEFMSG EndFunc