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

    • rudi
      By rudi
      Hello.
      I'm too stupid to see my mistake:
      To investigate the internal "dictionary" of TIFF files I'd like to read in the files in binary mode and to check, if there are more than one pages "in" this TIFF.
      Notepad++, "View as Hex" is presenting the first bytes as "49 49 2a 20 08 20 20 20 12" for the TIF attached to this posting
      The "TIFF Header Format" is easy:
      Offset 00h, 2 Byte = Byte Order, "II"=intel, "MM"=motorola. (I = 0x49)
      --> II
      Offset 02h, 2 Byte = Version Nr.
      Offset 04h, 4 Byte = pointer to first IFD entry
      Description of TIFF header: https://www.awaresystems.be/imaging/tiff/faq.html#q3
       

      Howto read and analyse the binary content correctly? This is my messy, not operational code:
       
      $sampleTiff="H:\daten\tif\11\11\111111.TIF" $h=FileOpen($sampleTiff,16) $content=FileRead($h) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console FileClose($h) $type=VarGetType($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $type = ' & $type & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $ToString=BinaryToString($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ToString = ' & $ToString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & @CRLF) $content=StringTrimLeft($content,2) ; cut off the leading "0x" ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console for $i = 1 to 8 step 8 $next=StringMid($content,$i,2) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $next = ' & $next & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $Chr=BinaryToString($next) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Chr = ' & $Chr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & "---" & @CRLF) Next Regards, Rudi.
      111111.TIF
    • Skeletor
      By Skeletor
      MS Splash Screens
      The office 2016/17 office suite has made many people turn heads with its functions and especially their splash screen.
      I now present to you, the MS Style Splash Screen. For Rookies, Novices and anyone who wants a ready made splash screen for your gui application.

      You can now download it and also try it out yourself.
      You have three colors to choose from:
      Blue
      Red
      Green
      All three colours are from the famous programs.
      I also included the KODA form to you can have freedom with this splash screen.
      Note: the KODA form does not have the three colours as well as the correct blue. 

      Have fun and enjoy.
      Note:
      I will update the splash to add the automated 3 dots animation at a later stage. 
       
       
    • Skeletor
      By Skeletor
      A gui splash screen. Themed after the famous MS Office Suite.
      Three colours to choose from, Red, Blue and Green.
      You can change the labels to your own application.

      Also bundled with this is the KODA form. So you can open up and see the basic structure of this splash screen.
       
      Splash Screen GUI.zip
    • BlazerV60
      By BlazerV60
      Hello all,
      I've been trying to figure out how to launch Google Chrome in the background (hidden) but it doesn't seem possible. I've tried the following methods:
      ShellExecute("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "", "", "", @SW_HIDE) Also I've tried:
      ShellExecute(@ComSpec, "/c start chrome.exe","","",@SW_HIDE) Lastly I tried:
      RunWait('"'&@ProgramFilesDir&'\Google\Chrome\Application\chrome.exe" --silent-launch',@ScriptDir)  
      But all of them launch my chrome browser without hiding it. Does anyone know a workaround for this or if AutoIT just can't Chrome? 
      Bonus points if you know how to make it launch chrome hidden and make it go to https://www.autoitscript.com
       
      Thank you,
      Brian
    • SteveJM
      By SteveJM
      I have a working program currently driven largely through menu selections. I would like to add a toolbar where most of the tollbar button actions are basically the same as menu items, but quicker to access. I have been wading around in toolbar examples, MSDN pages etc, it's clearly going to be a bit of a slog to get everything right, including tooltips etc. I thought I would start with something simple to prove the principle.
      Using bits from the help file examples I have a small program that successfully displays a toolbar. However, what seemed like the most elegant way to deal with the button commands does not seem to work. My understanding was that a toolbar button fires a WM_COMMAND message, with the command Id set by the second parameter in the call to
      _GUICtrlToolbar_AddButton ( $hWnd, $iID, $iImage)
      so I though it would be a good idea to set this Id to the same value as my menu item Id; then it would run the same task which is what I wanted. This did not work. I am using message loop mode and would like to stick with this because some of my scripts run hardware at the same time as the gui; it is easier if I don't have to worry about code being interrupted with the hardware in an unknown state . So I added a handler for WM_COMMAND, with some cribbed display code to try and see why. The toolbar button defintely fired a WM_COMMAND message and the Id looked the same, so no explanation there.
      I guess the issue is with GUIGetMsg() which may be constructed to ignore all but a limited number of control handles, i.e. those made with the GuiCtrlCreate... commands; this is speculation.
      I would dearly love to find a tidy way to get around this. Having some controls handled in the message loop and some in a WM_COMMAND handler, performing the same task, feels ugly. I would be very grateful for further insight from someone experienced with handling a toolbar. Perhaps I should be trying to fire the menu item. I have attached a code snippet to try and illustrate the issue.
       
       
       
      ToolbarTrial.au3