Jump to content

Function Question


Recommended Posts

Maybe I am trying this all wrong, but hope someone can help. I have a GUI and want to click a button which will start a function to get a folder location. Then I need to pass that location to a variable to use outside the function. Here is a sample of the code;It prompts to choose a file location and the message box displays the choice but that is all inside the function. I need to pass the path selected outside the function. OR need a different way of doing this, maybe my approach is wrong.

$Label_Drive=GUICtrlCreateLabel("Use the select button and choose where profiles will be stored.", 15, 120, 240, 25)
$BTN_Set_BKP_Path = GUICtrlCreateButton("Select Location", 250, 120, 90, 30) ;left,top,width,heigth
GUICtrlSetOnEvent($BTN_Set_BKP_Path, "Location")

 

Func Location()
$BKP_Path = FileSelectFolder("Select a folder where profiles will be stored.", "c:\")
MsgBox(0,"Select Path", "You set the path as " & $BKP_Path)
EndFunc

 

$Label_BKP_Path=GUICtrlCreateLabel("Current path is " & $BKP_Path & ".", 15, 150, 300, 25)

 

 

Link to comment
Share on other sites

Have a look at Return or make $BKP_Path a Global variable (outside the function) then it will retain its value for example:

;Example1
Global $sExample1 = Example1()
    MsgBox(0,"Select Path", "You set the path as " & $sExample1)

Func Example1()
    Local $BKP_Path = FileSelectFolder("Select a folder where profiles will be stored.", "c:\")
    If @error Then Return "Nothing selected"
    Return $BKP_Path
EndFunc

;~ Example2
Global $sExample2
    Example2()
    MsgBox(0,"Select Path", "You set the path as " & $sExample2)

Func Example2()
    $sExample2 = FileSelectFolder("Select a folder where profiles will be stored.", "c:\")
    If @error Then $sExample2 = "Nothing selected"
EndFunc

 

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...