[Gambas-user] Returning multiple values from a function

Rolf-Werner Eilert eilert-sprachen at ...221...
Thu Apr 3 11:40:53 CEST 2008


This is just the way I do it. But when I have more than 2 values to 
separate, I'll use another string[] to have them splitted (though I like 
to use a Tab (chr$(9)). This runs incredibly fast in Gambas.

Let's assume you receive a string like "10|cat|male|black" I would do

dim partstring as new string[]

partstring = split(sResult, "|")

'and now you can examine the part-strings:

if val(partstring[0]) = 10 then...

if partstring[1] = "cat" then...

Rolf


Jaap Cramer schrieb:
> 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
> -------------------------------------------------------------------------
> 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
> 





More information about the User mailing list