Sign in to follow this  
Followers 0
Ultracasual

$array = Function?

5 posts in this topic

Hello :)

Seemingly basic question. I need help defining an array as a function!

Using GUICtrlRead if there are certain options selected it will execute certain code based upon that or return a message box if there's no radio selected.

_ExampleOne() -- Works

_ExampleTwo() -- Does not

I have tried setting a Global dimension on the arrays for _ExampleTwo() and when I start the script they immediately become executed ;)

If I set a Local dimension inside the Function, when it's called they are executed in the same fashion completely bypassing the "If...Else..." statements.

While what I am after can be accomplished by lots of typing, is there a simpler way to define a function as an array instead?

I am not looking for someone to hold my hand even pointing me to an article would suffice as I'm new. Thank you!

Func _ExampleOne()

   If BitAnd(GUICtrlRead($Radio14),$GUI_CHECKED) = $GUI_CHECKED Then
    Send ("{F1}")
   Else
   If BitAnd(GUICtrlRead($Radio15),$GUI_CHECKED) = $GUI_CHECKED Then
    Send ("{F2}")
   Else
   If BitAnd(GUICtrlRead($Radio16),$GUI_CHECKED) = $GUI_CHECKED Then
    Send ("{F3}"))
   Else
    MsgBox ( 0, "", "No option selected!")
   EndIf
  EndIf
EndIf
EndFunc

Func _ExampleTwo()

Local $array1 = Send ("{F4}")
Local $array2 = Send ("{F5}")
Local $array3 = Send ("{F6}")
Local $array4 = Send ("{F7}")

  If BitAnd(GUICtrlRead($Radio9),$GUI_CHECKED) = $GUI_CHECKED Then
   Execute ( "$array1" & "$array2" & "$array3")
  Else
  If BitAnd(GUICtrlRead($Radio10),$GUI_CHECKED) = $GUI_CHECKED Then
   Execute ( "$array1" & "$array3" & "$array4")
  Else
  If BitAnd(GUICtrlRead($Radio11),$GUI_CHECKED) = $GUI_CHECKED Then
   Execute ( "$array3" & "$array4" & "$array2")
                Else
   MsgBox ( 0, "", "No option selected!")
  EndIf
EndIf
EndIf
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Execute is wrong. It would need to be

Execute("$array1" & @LF & "$array2" & @LF & "$array3")

edit: I'm wrong. Sorry about that

Edited by Beege

Share this post


Link to post
Share on other sites

Something like this is much more readable for me

Func _ExampleOne()
If Not _isChecked($Radio14) And Not _isChecked($Radio15) And Not _isChecked($Radio16) Then
  MsgBox(0, "", "No option selected!")
  Return 0
EndIf
If _isChecked($Radio14) Then Send("{F1}")
If _isChecked($Radio15) Then Send("{F2}")
If _isChecked($Radio16) Then Send("{F3}")
EndFunc   ;==>_ExampleOne
Func _isChecked($cID)
If BitAND(GUICtrlRead($cID), $GUI_CHECKED) = $GUI_CHECKED Then Return 1
Return 0
EndFunc   ;==>_isChecked
Func _sendA()
Send("{F4}")
Send("{F5}")
Send("{F6}")
EndFunc   ;==>_sendA
Func _sendB()
Send("{F4}")
Send("{F5}")
Send("{F7}")
EndFunc   ;==>_sendB
Func _sendC()
Send("{F4}")
Send("{F7}")
Send("{F5}")
EndFunc   ;==>_sendC
Func _ExampleTwo()
If Not _isChecked($Radio14) And Not _isChecked($Radio15) And Not _isChecked($Radio16) Then
  MsgBox(0, "", "No option selected!")
  Return 0
EndIf
If _isChecked($Radio9) Then _sendA()
If _isChecked($Radio10) Then _sendB()
If _isChecked($Radio11) Then _sendC()
EndFunc   ;==>_ExampleTwo

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Xenobiologist is correct in the way you should go about it.

Just to clarify what was wrong with your first script, all execute statements need to be strings. Otherwise the send() function gets executed and the return value from it gets stored in $array.

Something along the same line as what you were trying to do might be something like this:

Local $array[4]
$array[0] = 'Send("A")'
$array[1] = 'Send("B")'
$array[2] = 'Send("C")'
$array[3] = 'Send("D")'
For $i = 0 To 4
     Execute($array[$i])
Next

But again, I recommend using the method Xenobiologist described.

Share this post


Link to post
Share on other sites

Beege and Xeno thank you very much. Xeno's looks more applicable but yours gave me a few ideas, thank you both this is what I needed to hear :)

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