Sign in to follow this  
Followers 0
WeMartiansAreFriendly

demostration: return string and array

4 posts in this topic

#1 ·  Posted (edited)

ok this isn't udf it just shows how you can return an array, and a string at the same time, unfortunetly uncommented it justs returns an array of an array, and a string..

$a = _ArrStr()

MsgBox(0,'String',$a[1])

$a = $a[0]

For $x =1 to UBound($a)-1
    MsgBox(0,'Array',$a[$x])
Next

Func _ArrStr()
    Local $retArray[2]
    Local $aArray[11]
    Local $sString
    
    For $x = 1 to 10
        $aArray[$x] = $x
        $sString &= $x 
    Next
    
    $retArray[0] = $aArray
    $retArray[1] = $sString
    
    Return $retArray
EndFunc
Edited by mrRevoked

Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

Share this post


Link to post
Share on other sites



I guess that would work, but isn't that what ByRef is for?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I guess that would work, but isn't that what ByRef is for?

well yes, and no.. no.. when you set byref, the input has to be a variable and it overwrites the variable with new data if you use it..

you could use it like this.. but it's more of an array swap than anything..

local $a[5] = [0,1,2,3,4]

func _text(byref $a)
$string = '12345'

local $b[5] = [6,7,8,9,0]
$a = $b
return string
endfunc

just use your imagination..

Edited by mrRevoked

Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Here is your code from the first post rewritten with a ByRef

#include <array.au3>
Dim $a[1]
$s = _ArrStr($a)

MsgBox( 0, "String", $s )
_ArrayDisplay($a, "Array" )

Func _ArrStr(ByRef $aArray)
    ReDim $aArray[11]
    Local $sString
    
    For $x = 1 to 10
        $aArray[$x] = $x
        $sString &= $x 
    Next
    
    Return $sString
EndFunc

Either way works and both return the same string and array.

Edited by Gabburd

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