jeroen96

How to make these funcs shorter

5 posts in this topic

Hello, I want to know if there is a shorter way to write this:

 

Func mouse_co ()
   $a += 1
   If $a = 1 Then
      Global $m1 = MouseGetPos ()
   ElseIf $a = 2 Then
      Global $m2 = MouseGetPos ()
   ElseIf $a = 3 Then
      Global $m3 = MouseGetPos ()
   ElseIf $a = 4 Then
      Global $m4 = MouseGetPos ()
   ElseIf $a = 5 Then
      Global $m5 = MouseGetPos ()
   ElseIf $a = 6 Then
      Global $m6 = MouseGetPos ()
   ElseIf $a = 7 Then
      Global $m7 = MouseGetPos ()
   ElseIf $a = 8 Then
      Global $m8 = MouseGetPos ()
   ElseIf $a = 9 Then
      Global $m9 = MouseGetPos ()
   ElseIf $a = 10 Then
      Global $m10 = MouseGetPos ()
   ElseIf $a = 11 Then
      Global $m11 = MouseGetPos ()
   ElseIf $a = 12 Then
      Global $m12 = MouseGetPos ()
   EndIf
EndFunc

Func mouse_co2 ()
   If $a >= 1 Then
      Send ("(" & $m1[0] & "," & $m1[1] & ")" & @CRLF)
      If $a >= 2 Then
         Send ("(" & $m2[0] & "," & $m2[1] & ")" & @CRLF)
         If $a >= 3 Then
            Send ("(" & $m3[0] & "," & $m3[1] & ")" & @CRLF)
            If $a >= 4 Then
               Send ("(" & $m4[0] & "," & $m4[1] & ")" & @CRLF)
               If $a >= 5 Then
                  Send ("(" & $m5[0] & "," & $m5[1] & ")" & @CRLF)
                  If $a >= 6 Then
                     Send ("(" & $m6[0] & "," & $m6[1] & ")" & @CRLF)
                     If $a >= 7 Then
                        Send ("(" & $m7[0] & "," & $m7[1] & ")" & @CRLF)
                        If $a >= 8 Then
                           Send ("(" & $m8[0] & "," & $m8[1] & ")" & @CRLF)
                           If $a >= 9 Then
                              Send ("(" & $m9[0] & "," & $m9[1] & ")" & @CRLF)
                              If $a >= 10 Then
                                 Send ("(" & $m10[0] & "," & $m10[1] & ")" & @CRLF)
                                 If $a >= 11 Then
                                    Send ("(" & $m11[0] & "," & $m11[1] & ")" & @CRLF)
                                    If $a >= 12 Then
                                       Send ("(" & $m12[0] & "," & $m12[1] & ")" & @CRLF)
                                    EndIf
                                 EndIf
                              EndIf
                           EndIf
                        EndIf
                     EndIf
                  EndIf
               EndIf
            EndIf
         EndIf
      EndIf
   EndIf
EndFunc

 

I want to use this to a max $a but in this way it costs a lot of time

thanks

Share this post


Link to post
Share on other sites



Use Arrays and Switch instead of multiple If/Then/Else.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Don't declare Global variables inside a function - that's not the best way to write code. I don't understand the purpose of this.

Share this post


Link to post
Share on other sites

Thank you for your responses, i foud a way to do this :)

Func mouse_co ()
   $m = MouseGetPos ()
   $coord = $coord & "The coordinations are: (" & $m[0] & "," & $m[1] & ")" & @CRLF
   MsgBox (0,"",$coord)
EndFunc

 

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