Sign in to follow this  
Followers 0
youtuber

About a return command

8 posts in this topic




@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

 

1 person likes this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
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 this post


Link to post
Share on other sites

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.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I want to do something like

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

 

Edited by youtuber

Share this post


Link to post
Share on other sites

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

 

1 person likes this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
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 this post


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

 

1 person likes this

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

  • Similar Content

    • RC86
      By RC86
      Afternoon!
      I have a requirement to return both a string and an array from a function so as a result I put them both into an array and returned that.  I can access them in their entirety after returning them but then I can't seem to access the array elements after this.  Should I be able to or is there a prettier way?
      #include <Array.au3> ;Memory info returned as a string and an array $memoryInfo = _getMemoryInfo() msgbox(0,"Memory Info",$memoryInfo[0]) _ArrayDisplay($memoryInfo[1],"Memory as an Array") Local $newArray[7] $memoryInfo[1] = $newArray msgbox(0,"Test element",$newArray[0]) _ArrayDisplay($newArray) Func _getMemoryInfo() Local $newArray[7] Local $array = MemGetStats() $newArray[0] = $array[0] ;% of memory in use $newArray[1] = Round($array[1]/1024 * 0.001,2) ;Total physical RAM $newArray[2] = Round($array[2]/1024 * 0.001,2) ;Availaible physical RAM $newArray[3] = Round($array[3]/1024 * 0.001,2) ;Total pagefile $newArray[4] = Round($array[4]/1024 * 0.001,2) ;Available pagefile $newArray[5] = Round($array[5]/1024 * 0.001,2) ;Total virtual $newArray[6] = Round($array[6]/1024 * 0.001,2) ;Available virtual $memoryUsage = $newArray[1] - $newarray[2] $pagefileUsage = $newArray[3] - $newarray[4] ;Output/Return Local $returnArray[2] $returnArray[0] = "Memory: " & $memoryUsage & " GB/" & $newArray[1] & " GB " & @CRLF & "Pagefile: " & $pagefileUsage & " GB/" & $newArray[3] & " GB " $returnArray[1] = $newArray return $returnArray EndFunc A bit messy but hopefully it's understandable what I'm trying to achieve.
      Thanks!
    • PEscobar
      By PEscobar
      #Region ### START Koda GUI section ### Form=c:\users\paulo\documents\gui.kxf Global $Form1_1 = GUICreate("Test", 499, 196, -1127, 323) Global $Amount = GUICtrlCreateLabel("Amount", 176, 80, 40, 17) Global $AmountInput = GUICtrlCreateInput("", 224, 80, 57, 21) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $x = This one is just a test, but I want the value of $x to be whatever numbers the user types in. 
    • Simpel
      By Simpel
      Hi.
      If I embedd a compiled autoit script into my new script, is there a possibility to pass some data from the compiled embedded exe to my script?
      I know it's possible with an ini or txt-file. But is there something without creating a file? I plan to return an array or an unformatted string of datas with delimiters inside.
      Any ideas?
      Regards, Conrad
    • Xibalba
      By Xibalba
      Maybe I'm just too tired, but I came across this and didn't quite know how to solve it at once:
      Func myFunc() If $something Then StopTimer() Return 0 ElseIf $somethingElse Then StopTimer() Return 1 Else StopTimer() Return 2 EndIf EndFunc My idea was to make a return function to get rid of all the StopTimer() lines:
      Func MyFunc_Return($val) StopTimer() Return $val EndFunc And then use it like so:
      If $something Then MyFunc_Return(0) ElseIf $somethingElse Then... But then the problem persists of course - how do we get MyFunc to actually return and exit the function?
      In my real script there is lots of returns...
      Edit: bleh typo... how do I change topic title?
    • jrumbaug
      By jrumbaug
      I created a GUI UDF() I called PickList() that returns the chosen value from the "pick list".

      Is there a prefered way to RETURN a value from the GUI and use GuiDelete() ?

      If I simply issue the GuiDelete() before RETURN, my return value is lost.

      OR

      Am I worring too much about using GUIDelte()?. The GUI does go away when the UDF is finished without using GuiDelete(), but I thought it is considered good form to call GuiDelete() at the end of a program to "clean up".


      thanks in advance.

      Jim Rumbaugh