Sign in to follow this  
Followers 0
zzpot

Passing on Variables thru a Gui

4 posts in this topic

Hello Everyone

I think this may be the first post I have made in this section.

After starting into Autoit about 2 years ago I have come to the part now where I need a GUI for setting variables in the program

that I have written.

I would like for the GUI to be the first thing the user access so they may choose settings on how the program will run.

A sample:

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("Starting With One", 633, 447, 193, 115)

$Combo1 = GUICtrlCreateCombo("Choose Game Stakes", 432, 64, 137, 25)

GUICtrlSetData($Combo1, "$0.25/$0.50|$0.50/$1.00");Whatever the user would choose here I would like for it to be passed along to the main program that would be below this.

;Main Program as a Global Variable(That would be my first question)

$Button1 = GUICtrlCreateButton("Start", 440, 360, 145, 49, 0)

;Second question is how to start the next program using this Start button and close this gui so that it cannot be accessed again

;until this program has been started over by the user.

GUICtrlSetState(-1, $GUI_FOCUS)

GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

EndSwitch

WEnd

;Rem main program or script would start here.....using the passed on variables from GUI..

;Im not lazy going thru each command one at a time and looking at all examples.....

Thanks

steve

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hello Everyone

I think this may be the first post I have made in this section.

After starting into Autoit about 2 years ago I have come to the part now where I need a GUI for setting variables in the program

that I have written.

I would like for the GUI to be the first thing the user access so they may choose settings on how the program will run.

A sample:

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("Starting With One", 633, 447, 193, 115)

$Combo1 = GUICtrlCreateCombo("Choose Game Stakes", 432, 64, 137, 25)

GUICtrlSetData($Combo1, "$0.25/$0.50|$0.50/$1.00");Whatever the user would choose here I would like for it to be passed along to the main program that would be below this.

;Main Program as a Global Variable(That would be my first question)

$Button1 = GUICtrlCreateButton("Start", 440, 360, 145, 49, 0)

;Second question is how to start the next program using this Start button and close this gui so that it cannot be accessed again

;until this program has been started over by the user.

GUICtrlSetState(-1, $GUI_FOCUS)

GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

EndSwitch

WEnd

;Rem main program or script would start here.....using the passed on variables from GUI..

;Im not lazy going thru each command one at a time and looking at all examples.....

Thanks

steve

Maybe something like this

#include <GUIConstants.au3>
Global $button1,$button2,$Combo1
$MainForm = Showform()

$stage = 1
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
    Case $GUI_EVENT_CLOSE
        Exit
    Case $button2
        GUIDelete($MainForm)
        $stage = 2

EndSwitch

If $stage = 2 Then ExitLoop
WEnd
MsgBox(0,'We have gone to the next level','Get ready to exit')

Func ShowForm()
    #Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Starting With One", 633, 447, 193, 115)
$Combo1 = GUICtrlCreateCombo("Choose Game Stakes", 432, 64, 137, 25)
GUICtrlSetData($Combo1, "$0.25/$0.50|$0.50/$1.00");Whatever the user would choose here I would like for it to be passed along to the main program that would be below this.
;Main Program as a Global Variable(That would be my first question)
$Button1 = GUICtrlCreateButton("Start", 440, 360, 145, 49, 0)
$button2 = GUICtrlCreateButton("next step",440,400,145,49)
;Second question is how to start the next program using this Start button and close this gui so that it cannot be accessed again
;until this program has been started over by the user.

GUICtrlSetState(-1, $GUI_FOCUS)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
Return $Form1
#EndRegion ### END Koda GUI section ###
    
EndFunc

BTW it makes it easier to read your code if you put tags around it. Use [ code ] before and [ /code ] after, or [ autoit ] before and [ /autoit ] after,

but I have inserted spaces inside the brackets so you can read what I've typed. There is also a button for 'wrap in code tags' for highlighted text.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Hello Martin

Thanks alot for taking the time to look at this.

I almost teared up when I saw your reply !!!!!!

I tried testing the passing on of the Variable that was set Global and called $Combo1!

Adjusted the message window

MsgBox(0,'We have gone to the next level','Get ready to exit')

With

MsgBox(0,'We have gone to the next level',$Combo1)

The result did not bring back the selected or selection.

I not slacking on you im running thru the commands trying the GuiCreteRead and anything else that might set this variable before it leaves our menu.

Thank you again for the help if you have any ideas about carring this further please jump right on in.

Steve

Share this post


Link to post
Share on other sites

ALWAYS you will get the value of a control by using GUICtrlRead

So - instead of using $Combo1 ... use GUICtrlRead($Combo1) ... and always remember this (you have to read that control to get its value).


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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  
Followers 0