Jump to content

can we pass a variable with GUICtrlSetOnEvent?


guwguw
 Share

Recommended Posts

Is it possible to pass a variable with GUICtrlSetOnEvent?

I tried some "tricky" syntax, like

GUICtrlSetOnEvent(-1, "Slider1Change(" & $variable & ")")
but only got syntax error messages.

My intention: From a list of connections (which can be anywhere from 10 to 80), I try to give each a volume slider. I'm reading the list in a loop, creating the needed GUI code for each slider. In case some slider setting changed, I would like to pass that setting to some function, which saves the changed setting.

Here is a simplified, symbolic part of the code, reading related data from a database (but could be an INI file as well)

Opt("GUIOnEventMode", 1)

$portList = GUICtrlCreateListView("    Port Name       |Prty|Owner|Balance|TrafficRate|", 160, 80, 699, 249, 0x0); BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_EX_FULLROWSELECT, $WS_HSCROLL, $WS_VSCROLL))

$list_of_ports = "All Ports|" 
$droplist_of_ports = "All Ports|" 

With $data
    $acounter = 0
    $row_val = 99
    While Not .EOF
        $acounter += 1
        $row_val += 14
        $list_of_ports = $list_of_ports & .Fields ("portname"  ).value & "|" 
        $droplist_of_ports = $droplist_of_ports & .Fields ("portname"  ).value & "|" 
; ... other assignments (left out for simplification)
        
;   MsgBox(0, 'ports now deals with', .Fields ("portname").value & "|  balance " & StringFormat ( "%5.2f", .Fields ("balance").value) &  @CRLF)
                       $thisone = .Fields ("portname"  ).value & "|" & .Fields ("priority"  ).value & "|" & StringFormat("%5.2f", .Fields ("balance"  ).value) & "|" & StringFormat("   %.2f", .Fields ("owner"  ).value) & "|" & StringFormat("     %.2f", .Fields ("trafficrate"  ).value))
        $CheckboxClickVar = "CheckboxClick" & $acounter
        $Checkbox1 = GUICtrlCreateCheckbox($CheckATbox, 124, 103 + ($acounter - 1) * 14, 16, 16); was $acounter - 1
        GUICtrlSetOnEvent(-1, "CheckboxClick")
        GUICtrlSetTip(-1, "Check to activate this port ID= " & .Fields ("acct_id"  ).value)
        $portlist_0 = GUICtrlCreateListViewItem($thisone, $portList)
; GUICtrlSetBkColor(-1,0x00ff00); Green

;---------->>>; this is the crucial part:
        $VolumeSlider1 = GUICtrlCreateSlider(860, $row_val, 129, 16, $GUI_SS_DEFAULT_SLIDER)
        GUICtrlSetOnEvent(-1, "portVolSlider1Change")
;---------->>>  ; end of crucial part
        GUICtrlSetLimit(-1, 100, 0)     
        GUICtrlSetData(-1, .Fields ("volume_level" ).value)
        GUICtrlSetTip(-1, "Set desired volume level for port " & .Fields ("portname" ).value & " (updates db directly)")

        .MoveNext
    WEnd
EndWith

Func portVolSlider1Change()
    $newVolume = GUICtrlRead($VolumeSlider1)
    MsgBox(0, "Volume Setting Changed to " & $newVolume & " in " & $acounter, "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle, 2)

          ; here starts some updating procedure into database or INI file
; $ariskvar = _Query ($SQLconnect, "UPDATE `all_ports` SET volume_level = "& $newVolume &" WHERE 'acct_id' = " & $acct_id & ";")
          ;... 
EndFunc ;==>portVolSlider1Change

My question: Is there a way to inform Func portVolSlider1Change() of the affected portname or ID?

I know in a direct call, I could call the function with the variable, like in

portVolSlider1Change($identificationVariable)

... I hope it's not too confusing :)

Edited by guwguw
Link to comment
Share on other sites

@GUI_CtrlId, @GUI_CtrlHandle, @GUI_WinHandle

If you speak english: Could you post some example showing how the GUICtrl stuff you are suggesting will pass a variable?

Handles and ID of the GUICtrl are known, but how would you pass the variable ($acct_id in this case) to the function portVolSlider1Change() ?

Link to comment
Share on other sites

It's not so much that you pass the variable to the function, rather,

you check these macros once in the function, to find out which control was activated..

for $i = $first_control to $last_control
  if $i = @GUI_CtrlId then
    ; do stuff here
  endif
next

;o)

(or

Edited by corz

nothing is foolproof to the sufficiently talented fool..

Link to comment
Share on other sites

It's not so much that you pass the variable to the function, rather,

you check these macros once in the function, to find out which control was activated..

for $i = $first_control to $last_control
  if $i = @GUI_CtrlId then
    ; do stuff here
  endif
next

;o)

(or

Thanks for your participation!

I think you might've given me an idea: since the amount of ports is not fixed, but dynamically changes, I would have to register the @GUI_CtrlId at setup time (when running the loop) and linking the proper $acct_id or $port_id to this @GUI_CtrlId - clumsy, but it'll work. I love working with arrays anyway, lol.

... unless we get another hint for passing the variable directly?

I'll run some tests and tell you (in case someone else has a similar need) how it worked.

Link to comment
Share on other sites

To be honest, I didn't look at your code; I usually don't bother unless it's a complete listing and I can just chuck it into my test script; I simply noticed that you were having trouble understanding how to utilize AutoIt macros.

You probably want to check the AutoIt manual for GUICtrlRead() or ControlGetText();. used in conjunction with the macro, there's no need to build arrays, or set values, it's all automatic.

Remember, control ID's are just numbers; if the macro returns "23", then you can do stuff to/reteive stuff from that control, because you know its ID. Getting its text, "port ID", or whatever, should be trivial.

;o)

(or

nothing is foolproof to the sufficiently talented fool..

Link to comment
Share on other sites

Could you post some example showing how the GUICtrl stuff you are suggesting will pass a variable?

Handles and ID of the GUICtrl are known, but how would you pass the variable ($acct_id in this case) to the function portVolSlider1Change() ?

Here is the solution: At creation time
$VolumeSlider1 = GUICtrlCreateSlider(860, $row_val, 129, 16, $GUI_SS_DEFAULT_SLIDER)
        GUICtrlSetOnEvent(-1, "portVolSlider1Change")
the variable $VolumeSlider1 contains the ID, which then can be logged together with all the other program variables related to that port/account.
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

  • Recently Browsing   0 members

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