[Gambas-user] Returning multiple values from a function

Jaap Cramer jaap_cramer at ...67...
Thu Apr 3 10:52:53 CEST 2008


When I need multiple returnvalues I use an array
Mostly of the string[] type. 
When it contains different things, like an integer and a string, I put them in 1 string, and split them

sResult = DoSomething()   ' call the function
result is "10|cat"               ' i use a pipe to divide my string

sInteger = val(left(sResult, instr(sResult, "|")-1))
sString = mid(sResult, instr(sResult, "|")+1)

I think this should work...

----------------------------------------
> From: rterry at ...1822...
> To: gambas-user at lists.sourceforge.net
> Date: Thu, 3 Apr 2008 13:37:48 +1100
> Subject: [Gambas-user] Returning  multiple values from a function
> 
> Hope this is not too ambiguous or dumb:
> 
> Is it possible to return more than 1 value from a function?
> 
> 
> This works:
> 
> function  DoSomething(name as string) as integer[]
>  Dim numbers as integer[2]
> 
> 'do whatever in here
> numbers[0]=10
> numbers[1] = 20
> return numbers
> 
> 
> however seems a bit clumbsy
> 
> doing this:
> 
> function  Dosomething(name as string) as integer,string
> 
> REturn   10,"cat"
> 
> Dosn't
> 
> Probably a stupid question. I guess if you want back non identical types 
> one would just use a variant array?
> 
> 
> 
> thanks
> 
> Richard
> 
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user

_________________________________________________________________
Probeer Live Search: de zoekmachine van de makers van MSN!
http://www.live.com/?searchOnly=true



More information about the User mailing list