Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Can a sub return more than 1 value ?


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-11-2008, 06:42 PM
Knows the basics
 
Join Date: Apr 2008
Location: Duesseldorf, Germany
Posts: 71
Default Can a sub return more than 1 value ?

Hello,

i'm asking me if that's possible, without the use of globals.

Return value

can only transport one value, right..?

Cheers

TWELVE
Reply With Quote
  #2 (permalink)  
Old 05-11-2008, 07:04 PM
Cableguy's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: N 41º11'30.30" W 8º39'46.60"
Posts: 1,003
Default

Sure seems like it...
I triyed to pass 3 values to a sub, ok, on that...but not so easy to return them....
could not find a way to do it...but it would be a great adicion, to pass more than one value, on a return keyword....
__________________
Paulo Gomes
Porto, Portugal

PC: Dual-Core 1,8Ghz, 2GB RAM, 80GB HD
PPC: Qtek9000, 1GB SD
Reply With Quote
  #3 (permalink)  
Old 05-11-2008, 07:17 PM
taximania's Avatar
Senior Member
 
Join Date: May 2007
Posts: 186
Default

Can't a sub return an array ??

Sorry for the short answer, just turning the computer off but saw this question.
__________________
Avoiding lawyers

O2 XDA Artemis Touch Flo 4.02 Full Cube Rom WM6.1

http://www.taximania.net
Reply With Quote
  #4 (permalink)  
Old 05-11-2008, 07:21 PM
Cableguy's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: N 41º11'30.30" W 8º39'46.60"
Posts: 1,003
Default

not unless it is declared in globals, as all arrays should be, but we are talking of single local variables...I think...
__________________
Paulo Gomes
Porto, Portugal

PC: Dual-Core 1,8Ghz, 2GB RAM, 80GB HD
PPC: Qtek9000, 1GB SD
Reply With Quote
  #5 (permalink)  
Old 05-11-2008, 09:23 PM
Knows the basics
 
Join Date: Apr 2008
Location: Duesseldorf, Germany
Posts: 71
Default

Quote:
Can't a sub return an array ??
I believe it can, but makes no sense in that context because if a variable is global i can access it everytime without the need to return it from a sub.

With a return value you can use your subs as functions/procedures like this:

if ParseMyData(inputstring) = "myexpectedstring" then

or

if DoIHaveMail(value) = true then


Globals make everything work, but i prefer to avoid globals whenever i can - for several known reasons:

- if a variable gets the wrong value i have to look into every sub that's using it

- each variable can only be used one time in the entire code

- subs can't be used as functions

Certainly there are more reasons not to use globals.


The use of the return value as function would also prevent the return of more than one value...if mysub(value) ...condition..then would have more than one parameter and cannot make a decision then.

So the use of an array as return value would be the solution here...if there were not the caveat that every array has to be global in B4P.

Furthermore as far as i remember, there seem to be restrictions if the optimized compiling is used..?


cheers

TWELVE
Reply With Quote
  #6 (permalink)  
Old 05-12-2008, 10:19 AM
specci48's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Germany
Posts: 520
Default

Quote:
Originally Posted by TWELVE View Post
So the use of an array as return value would be the solution here.
There is no restriction on this, because the return value is always a (single) object. So any type (even structures) will do...

Quote:
Originally Posted by TWELVE View Post
if there were not the caveat that every array has to be global in B4P.
This seems to be a design restriction of basic4ppc. Even user defined structures have to be globals.


specci48
Reply With Quote
  #7 (permalink)  
Old 05-12-2008, 11:18 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,175
Awards Showcase
Forum Contributer 
Total Awards: 1
Default

Quote:
Originally Posted by specci48 View Post
There is no restriction on this, because the return value is always a (single) object. So any type (even structures) will do...
I am afraid that this is not the case for the optimising compiler. Due to the way internal Subs are declared in optimised code "Return" can return only Value types i.e array elements such as "Array(2)" but not array references such as "Array()." It is possible for libraries to return Array/struct references that can be assigned to already "Dimmed" arrays but this is a special case.

I seem to be missing the point of the original question. I know of no computer language that can return more than one result from a function.
Reply With Quote
  #8 (permalink)  
Old 05-12-2008, 11:39 AM
RandomCoder's Avatar
Basic4ppc Veteran
 
Join Date: May 2007
Location: UK
Posts: 441
Default

The easiest way to return more than one value is to hide them in a string....
Return "true,false,26,AnythingElse?"

Then you just need to interegate the returned value using string manipulation.

Regards,
RandomCoder
__________________
Desktop: Pentium D 920 (2.8GHz, 4MB L2 Cache, 800MHz FSB), 1024MB, 256MB Radeon X600, 250GB HD.
Device : Axim X51v XScale 624MHz, 3.7" VGA, 64MB SDRAM, 256MB Flash ROM + 1Gb SD.

"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
  #9 (permalink)  
Old 05-12-2008, 04:19 PM
specci48's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Germany
Posts: 520
Default

Quote:
Originally Posted by agraham View Post
I am afraid that this is not the case for the optimising compiler.
Thanks for this additional info. Haven't realized that yet.

Quote:
Originally Posted by agraham View Post
I know of no computer language that can return more than one result from a function.
That's true, but in most "modern" languages the "one" result can be an object which contains several different information.
Reply With Quote
  #10 (permalink)  
Old 05-13-2008, 06:22 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 2,563
Default

Currently a sub can only return one "regular" variable.
This limitation will be removed in the future (not too far), together with local arrays / structures.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
All hail GeoTrail's return RandomCoder Chit Chat 1 02-17-2008 12:14 PM
Return value from Form ghislain Questions & Help Needed 5 12-23-2007 07:34 AM
return issue Cableguy Questions & Help Needed 1 09-21-2007 06:01 AM


All times are GMT. The time now is 10:07 AM.


Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0