Jump to content

Recommended Posts

Posted

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?

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
Posted

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:

Posted

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)

Posted

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.

  • Administrators
Posted

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...