Jump to content

About a return command


Recommended Posts

  • 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

How to get your question answered on this forum!

Link to comment
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

 

Link to comment
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

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

So something like this:

ShellExecute(Example(12))

Func Example($iVal)
    Local $sApp

    Switch $iVal
        Case 4
            $sApp = "notepad.exe"
        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

How to get your question answered on this forum!

Link to comment
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
            $sApp = "notepad.exe"
        Case 8
            $sApp = "mspaint.exe"
        Case 12
            $sApp = "calc.exe"
    EndSwitch

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

    Return $sApp
EndFunc

 

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

×
×
  • Create New...