Jump to content

GUICtrlSetOnEvent - passing parameter in function call


Recommended Posts

_SQLite_Open (@scriptdir & "\database\tgh.db")

                local $hQuery, $sMsg
                global $Arow
                _SQlite_Query (-1, "Select * from PcInfo;", $hQuery) ; the query
                        While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
                            $PCName1 = GUICtrlCreateListViewItem($aRow[1] & "|" & $aRow[2], $listview)

                                $contextmenu1 = GUICtrlCreateContextMenu($PCName1)
                                $infoitem1 = GUICtrlCreateMenuItem("Ping " & $aRow[1], $contextmenu1)
                                            GUICtrlSetOnEvent(-1, "_PingPC")
                        WEnd

                GUISetState(@SW_SHOW)

The problem I am having is that I can't seem to pass a variable in the command --> GUICtrlSetOnEvent(-1, "_PingPC($aRow[1])") Am I missing something? In short I have a listview that lists x number of devices and I am trying to create a Rightclick function which will allow me to ping the PC I selected.

Thanks!

Digital Chaos - Life as we know it today.I'm a Think Tank. Problem is, my tank is empty.The Quieter you are, the more you can HearWhich would you choose - Peace without Freedom or Freedom without Peace?Digital Chaos Macgyver ToolkitCompletely Dynamic MenuSQLIte controlsAD FunctionsEXCEL UDFPC / Software Inventory UDFPC / Software Inventory 2GaFrost's Admin Toolkit - My main competitor :)Virtual SystemsVMWAREMicrosoft Virtual PC 2007

Link to comment
Share on other sites

If $aRow is already a global variable why do you even need to pass it in with the guictrlsetonevent? Can't you just call it within the next function? Personally I've always found ways around passing info into functions like this, instead just dedicate a global variable to it and call it when needed within the function. PS Im not 100% sure about this, however the problem might also be that $aRow is an array.

Edited by fireryblaze
Link to comment
Share on other sites

you are correct that it is a global variable but i need to pass the correct one to the function. what happens if i don't is that i get an out of range subscript error.

Digital Chaos - Life as we know it today.I'm a Think Tank. Problem is, my tank is empty.The Quieter you are, the more you can HearWhich would you choose - Peace without Freedom or Freedom without Peace?Digital Chaos Macgyver ToolkitCompletely Dynamic MenuSQLIte controlsAD FunctionsEXCEL UDFPC / Software Inventory UDFPC / Software Inventory 2GaFrost's Admin Toolkit - My main competitor :)Virtual SystemsVMWAREMicrosoft Virtual PC 2007

Link to comment
Share on other sites

To get the size of the array just use the UBound function. With that you can avoid going beyond the arrays dimensions. However I did a bit more digging and found a udf made by martin that could work wonders for you.

functions with parameters in OnEvent and HotKeys UDF with simple example

This should help tremendously, though I wish I had it about 6 months ago. Making workarounds for these situations can be very difficult.

Link to comment
Share on other sites

So close. Thanks for the reference but the script doesn't pull the info correctly when I use the following code:

I tried paramByRef for the array and nothing, not sure if I can use it with a Menu Item or not???

$infoitem1 = GUICtrlCreateMenuItem("Ping " & $aRow[1], $contextmenu1)
SetOnEventA($infoitem1, "funcone", $paramByVal, "$aRow[1]");, $paramByVal, 2, $paramByVal, 37, $paramByVal, "battery", $paramByVal, "parm5")

To get the size of the array just use the UBound function. With that you can avoid going beyond the arrays dimensions. However I did a bit more digging and found a udf made by martin that could work wonders for you.

functions with parameters in OnEvent and HotKeys UDF with simple example

This should help tremendously, though I wish I had it about 6 months ago. Making workarounds for these situations can be very difficult.

Digital Chaos - Life as we know it today.I'm a Think Tank. Problem is, my tank is empty.The Quieter you are, the more you can HearWhich would you choose - Peace without Freedom or Freedom without Peace?Digital Chaos Macgyver ToolkitCompletely Dynamic MenuSQLIte controlsAD FunctionsEXCEL UDFPC / Software Inventory UDFPC / Software Inventory 2GaFrost's Admin Toolkit - My main competitor :)Virtual SystemsVMWAREMicrosoft Virtual PC 2007

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