Sign in to follow this  
Followers 0
tamir

set function to control

9 posts in this topic

i have a function

Func test($var)
MsgBox(0, "", $var)
EndFunc

i want to make 2 buttons:

1 that calls to test("a") and the other that calls to test("b").

after i made the 2 buttons, how do i make them call to the function with the variables?

the second is if i can let the user select more then 1 option in GUICtrlCreateList?

Share this post


Link to post
Share on other sites

#2 ·  Posted (edited)

like this ? (from helpfile and me)

GUICreate("My GUI Button") ; will create a dialog box that when displayed is centered

Opt("GUICoordMode",2)
$a= GUICtrlCreateButton ("A",  10, 30, 50)
$b= GUICtrlCreateButton ( "B",  0, -1)

GUISetState ()    ; will display an  dialog box with 2 button

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $msg= $a then MsgBox (0, "A", "A")
    If $msg= $b then MsgBox (0, "B", "B")
Wend
Edited by layer

FootbaG

Share this post


Link to post
Share on other sites

well, not exactly but from your code i know how to do this...

i forgot about GUIGetMsg(). thanks.

now i need to know about the second question :idiot:

Share this post


Link to post
Share on other sites

hehe, no problem, whats your second problem?


FootbaG

Share this post


Link to post
Share on other sites

it's written in the topic...

and i have another problem:

what's wrong with this?

$par_a = ""
$par = "a"
$open = "text"
Eval("par_" & $par) = $open

i get the error:

Illegal text at the end of statement (one statement per line)

Share this post


Link to post
Share on other sites

The only thing Eval does is return the value of the variable.

You can't assign a value to a variable using Eval.

You will need to use Assign for that.

$par_a = ""
$par = "a"
$open = "text"
Assign("par_" & $par, $open)

If you get an error message, check the help file for more info.

If that's not enough, ask here.

Share this post


Link to post
Share on other sites

You can also use the Event mode rather than GuiGetMsg which is sometimes easier to understand:

Look up GuiCtrlSetOnEvent which gives this example:

#include <GUIConstants.au3>

Opt("GUICoordMode",2)
Opt("GuiOnEventMode", 1)

$parent1 = GuiCreate("Parent1")

$ok1 = GUICtrlCreateButton ("OK",  10, 30, 50)
GUICtrlSetOnEvent(-1, "OKPressed")

$cancel1 = GUICtrlCreateButton ( "Cancel",  0, -1)
GUICtrlSetOnEvent(-1, "CancelPressed")

GuiSetState(@SW_SHOW)

; Just idle around
While 1
    Sleep(10)
Wend


; END


Func OKPressed()
    MsgBox(0, "OK Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE & " CtrlHandle=" & @GUI_CTRLHANDLE)
EndFunc


Func CancelPressed()
    MsgBox(0, "Cancel Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE & " CtrlHandle=" & @GUI_CTRLHANDLE)
EndFunc

You can only specify a function to call (no parameters) but for your case you could easily do something like this,

Func TestA()
  Test("a")
EndFunc

Func TestB()
  Test("b")
EndFunc

Func Test($var)
  MsgBox(0, "", $var)
EndFunc

Share this post


Link to post
Share on other sites

i know but the GUIGetMsg is better in my opinion

Share this post


Link to post
Share on other sites

umm can any1 answer my first question plz?

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