Jump to content

Return() on more then one Variable


avery
 Share

Recommended Posts

Hello,

I've been at it all day and night having a blast coding in some Autoit while my Girl Friend is pulling a double at work.

I am almost certain the answer to my question is my brain is fried from the aforementioned statement and the only solution to my madness is sleep.

I am trying to set more then one local var from a function returning values. Example.

Func _main()
    local $ins = "install_location"
    Local $inf, $level = _inf($ins)
EndFunc

Func _inf($ins)
    ...
    ...
    Return($inf, $level)
EndFunc

The error I get us unbalanced quotes.

Do I have to return an Array or something or can I do multiple returns?

ADVthanksANCE

avery

www.abox.orgAvery HowellVisit My AutoIt Websitehttp://www.abox.org
Link to comment
Share on other sites

You'd only be able to return one variable without an array. (which it's not the best practice to return arrays due to the coping). However maybe more what you need is to use the variables in the function Byref.

Func myFunc(ByRef $x,ByRef $y)

Then as the variables change in the function they are changed outside the function as well.

Link to comment
Share on other sites

Hello,

I've been at it all day and night having a blast coding in some Autoit while my Girl Friend is pulling a double at work.

I am almost certain the answer to my question is my brain is fried from the aforementioned statement and the only solution to my madness is sleep.

I am trying to set more then one local var from a function returning values. Example.

Func _main()
    local $ins = "install_location"
    Local $inf, $level = _inf($ins)
EndFunc

Func _inf($ins)
    ...
    ...
    Return($inf, $level)
EndFunc

The error I get us unbalanced quotes.

Do I have to return an Array or something or can I do multiple returns?

ADVthanksANCE

avery

Here is an example of stampy's suggestion using ByRef.

_main()

Func _main()
    Local $ins = "install_location"
    Local $inf, $level
    _inf($level, $inf, $ins)
    MsgBox(0, "", "$level contains " & $level & @CRLF & "$inf contains " & $inf)
EndFunc  ;==>_main

Func _inf(ByRef $level, ByRef $inf, $ins)
    $level = $ins & "  Level in inf()"
    $inf = "$inf in inf()"
    Return
EndFunc  ;==>_inf
Link to comment
Share on other sites

Here is an example of stampy's suggestion using ByRef.

_main()

Func _main()
    Local $ins = "install_location"
    Local $inf, $level
    _inf($level, $inf, $ins)
    MsgBox(0, "", "$level contains " & $level & @CRLF & "$inf contains " & $inf)
EndFunc ;==>_main

Func _inf(ByRef $level, ByRef $inf, $ins)
    $level = $ins & "  Level in inf()"
    $inf = "$inf in inf()"
    Return
EndFunc ;==>_inf
Thank you very much for that example. It works perfect.

I have a related question to these variable and do not understand the internals of AutoIt at all. I'd like to post it here and give it a shot, maybe someone else already knows the answer.

Global vs. ByRef vs going out of your way to keep variables in the smallest scope possible (local). Is it for Memory purposes and how much of a difference does it make?

Thanks,

avery

www.abox.orgAvery HowellVisit My AutoIt Websitehttp://www.abox.org
Link to comment
Share on other sites

Thank you very much for that example. It works perfect.

I have a related question to these variable and do not understand the internals of AutoIt at all. I'd like to post it here and give it a shot, maybe someone else already knows the answer.

Global vs. ByRef vs going out of your way to keep variables in the smallest scope possible (local). Is it for Memory purposes and how much of a difference does it make?

Thanks,

avery

Global is not related to ByRef. If a variable is Global it will sit in memory all the time somewhere. If it is Local then it will disappear when the function ends. If you use ByRef then the function is using the variable that has been already declared somwhere else. It might actaully be copied to a local variable while the function operates but that is up to the developers to worry about. The reason to use ByRef is only for the reason you have used it; that is so that you can pass a variable to a function and have it modified. Memory considerations don't come into it IMO.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...