# How to make these funcs shorter

## Recommended Posts

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 on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-08-19 - Version 1.4.13.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (NEW 2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Taks Scheduler (NEW 2019-10-09 - Version 0.9.0.0) - Download - General Help & Support - Wiki

Tutorials:

##### 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 on other sites

Without a real example how these functions are used, it will be difficult to offer any further advice without wasting time.

Monkey's are, like, natures humans.

##### 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```

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...