Jump to content
Sign in to follow this  
Merchants

FileOpenDialog problem

Recommended Posts

Merchants

got a problem here it is so that start the program enter by "name" some text like: profile1

and by "path" some text tike: test123 and press ok that works fine.

but if i fill in by name: profile1

and i want to select a file and press ok it does not work some how

need some help!

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUICoordMode", 1)

Global $name, $Button_1, $Button_2, $Button_3, $msg, $sTmpFile, $Locations, $i

Add()
Func Add()
    $GUI = GUICreate("Test program", 495, 135)
    GUICtrlCreateLabel("Name:", 18, 18)
    $name = GuiCtrlCreateInput("", 54, 16, 200, 20)
    GuiCtrlCreateGroup("Locations Settings",12,45,473,52)
    GUICtrlCreateLabel("Path:", 25, 67)
    $Locations = GuiCtrlCreateInput(IniRead("Settings.ini", "Locations", "Path", ""), 54, 65, 390, 20)
    $Button_1 = GuiCtrlCreateButton("...", 450, 65, 27, 20)
    $Button_2 = GuiCtrlCreateButton("Cancel", 412, 103, 74, 26)
    $Button_3 = GuiCtrlCreateButton("Ok", 335, 103, 74, 26)
    GUISetStyle($WS_CAPTION, $WS_BORDER)
    GUISetState()
    While 1
        $msg = GUIGetMsg($GUI)
        Select
            Case $msg =  $GUI_EVENT_CLOSE
                GUIDelete($GUI)
                Exit
            Case $msg = $Button_2
                GUIDelete($GUI)
                Exit
            Case $msg = $Button_1
                $sTmpFile = FileOpenDialog("Select File:", @DesktopDir, "Internet (*.exe)")
                GUICtrlSetData($Locations, $sTmpFile)
            Case $msg = $Button_3
                $i = IniRead("Settings.ini", "account", "count", "0")
                $i = $i + 1
                IniWrite("Settings.ini", "account", "count", $i)
                IniWrite("Settings.ini", "Locations", "Path", GUICtrlRead($Locations))
                IniWrite("Settings.ini", "account", "Name" & $i, GUICtrlRead($name))
                GUIDelete($GUI)
                Exit
        EndSelect
    WEnd
EndFunc
Edited by Merchants

Share this post


Link to post
Share on other sites
picaxe

It's good practice to use full file paths because FileOpenDialog changes the working directory. This works for me.

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUICoordMode", 1)

Global $name, $Button_1, $Button_2, $Button_3, $msg, $sTmpFile, $Locations, $i, $sIniFile = @ScriptDir & "\Settings.ini"

Add()
Func Add()
    $GUI = GUICreate("Test program", 495, 135)
    GUICtrlCreateLabel("Name:", 18, 18)
    $name = GuiCtrlCreateInput("", 54, 16, 200, 20)
    GuiCtrlCreateGroup("Locations Settings",12,45,473,52)
    GUICtrlCreateLabel("Path:", 25, 67)
    $Locations = GuiCtrlCreateInput(IniRead($sIniFile, "Locations", "Path", ""), 54, 65, 390, 20)
    $Button_1 = GuiCtrlCreateButton("...", 450, 65, 27, 20)
    $Button_2 = GuiCtrlCreateButton("Cancel", 412, 103, 74, 26)
    $Button_3 = GuiCtrlCreateButton("Ok", 335, 103, 74, 26)
    GUISetStyle($WS_CAPTION, $WS_BORDER)
    GUISetState()
    While 1
    $msg = GUIGetMsg($GUI)
    Select
    Case $msg = $GUI_EVENT_CLOSE
    GUIDelete($GUI)
    Exit
    Case $msg = $Button_2
    GUIDelete($GUI)
    Exit
    Case $msg = $Button_1
    $sTmpFile = FileOpenDialog("Select File:", @DesktopDir, "Internet (*.exe)")
    GUICtrlSetData($Locations, $sTmpFile)
    Case $msg = $Button_3
    $i = IniRead($sIniFile, "account", "count", "0")
    $i = $i + 1
    IniWrite($sIniFile, "account", "count", $i)
    IniWrite($sIniFile, "Locations", "Path", GUICtrlRead($Locations))
    IniWrite($sIniFile, "account", "Name" & $i, GUICtrlRead($name))
    GUIDelete($GUI)
    Exit
    EndSelect
    WEnd
EndFunc

Edit:

Btw should this

IniWrite($sIniFile, "Locations", "Path", GUICtrlRead($Locations))
be something like this
IniWrite($sIniFile, "Locations", "Path" & $i, GUICtrlRead($Locations))
Edited by picaxe

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
Sign in to follow this  

×