## Recommended Posts

2 writes and how returning?

```\$var1 = "1.variable"
\$var2 = "2.variable"
\$var3 = "3.variable"

For \$i = 1 To 3 Step 1
Next

For \$i = 1 To 3 Step 1
Next

If (\$var2 = 2) Then Return \$var1

For \$i = 1 To 3 Step 1
Next```

##### Share on other sites

• Moderators

@youtuber you use Return to exit a function with the desired value. I'm not sure what you're trying to do from your code, but a typical return would be something like this:

```#include <MsgBoxConstants.au3>

MsgBox(\$MB_OK, "Example", Example(8))

Func Example(\$iVal)
Local \$x = 0

Switch \$iVal
Case 4
\$x = "Four"
Case 8
\$x = "Eight"
Case 12
\$x = "Twelve"
EndSwitch

Return "You chose the number " & \$x
EndFunc```

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

##### Share on other sites

@JLogan3o13 Thank you

I understand better now thanks to the return command

then how can I get value if?

```#include <MsgBoxConstants.au3>

MsgBox(\$MB_OK, "Example", Example(8))

If Example = 4 Then
MsgBox(0,"test","Example 4")
ElseIf Example = 8 Then
MsgBox(0,"test","Example 8")
ElseIf Example = 12 Then
MsgBox(0,"test","Example 12")
EndIf

Func Example(\$iVal)
Local \$x = 0

Switch \$iVal
Case 4
\$x = "Four"
Case 8
\$x = "Eight"
Case 12
\$x = "Twelve"
EndSwitch

Return "You chose the number " & \$x
EndFunc```

##### Share on other sites

• Moderators

I still don't understand what you're trying to do. The String returned from the function will be "You chose the number" and then the string representation of whatever number you pass to the function. So Example is never going to = 4 or 8. You need to explain in detail what you're trying to accomplish, as you aren't being very clear.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

##### Share on other sites

I want to do something like

```If Example = 4 Then
else
Run("mspaint.exe")```

##### Share on other sites

• Moderators

So something like this:

```ShellExecute(Example(12))

Func Example(\$iVal)
Local \$sApp

Switch \$iVal
Case 4
Case 8
\$sApp = "mspaint.exe"
Case 12
\$sApp = "calc.exe"
EndSwitch

Return \$sApp
EndFunc```

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

##### Share on other sites

yes you can show this, but I want to return with an if statement

Can you show me an example of the if statement thank you

##### Share on other sites

```#include <MsgBoxConstants.au3>

\$test = Example(12)
Switch \$test
Case "qsdsqdqsdqsd.exe"
;...
Case Else
MsgBox(0,"test","Example " & \$test)
EndSwitch

Func Example(\$iVal)
Local \$sApp

Switch \$iVal
Case 4
Case 8
\$sApp = "mspaint.exe"
Case 12
\$sApp = "calc.exe"
EndSwitch

MsgBox(\$MB_OK, "Example", \$iVal)

Return \$sApp
EndFunc```

## Create an account

Register a new account

• ### Similar Content

• #### @error lost on Return without SetError? 1 2

By AGlassman,

• 29 replies
• 722 views
• #### [Solved] regex: replace line breaks except double

By Simpel,

• 3 replies
• 1,250 views
• #### Return Nested Array

By RC86,

• 11 replies
• 2,075 views
• #### How do I get a variable to equal the number entered in a text box?

By PEscobar,

• 1,316 views
• #### [Solved] returning data from compiled script

By Simpel,

• 16 replies
• 4,649 views
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...