Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) 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
Senior Member
 
Join Date: Apr 2008
Location: Duesseldorf, Germany
Posts: 154
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: 2,344
Awards Showcase
Forum Contributer 
Total Awards: 1
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 - Living/Working in France
Mobile Device: Samsung Galaxy S, Android 2.3.4 CUstom ROM
Laptop: Toshiba NB100-130 (running on Win7Ultimate)

My Posts helped you? Consider Buying me a Porto Glass!
Reply With Quote
  #3 (permalink)  
Old 05-11-2008, 07:17 PM
taximania's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire. UK
Posts: 592
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Can't a sub return an array ??

Sorry for the short answer, just turning the computer off but saw this question.
__________________
.
.
.
Don't ask, I'm fine, honest. !!
.
.
.
Just a little crazy at times



O2 XDA, GW Evo 2.1 UC WWE Rom, WM6.1
Radio Ver 03.34.90
With Basic4ppc V6.80


http://www.taximania.co.uk
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: 2,344
Awards Showcase
Forum Contributer 
Total Awards: 1
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 - Living/Working in France
Mobile Device: Samsung Galaxy S, Android 2.3.4 CUstom ROM
Laptop: Toshiba NB100-130 (running on Win7Ultimate)

My Posts helped you? Consider Buying me a Porto Glass!
Reply With Quote
  #5 (permalink)  
Old 05-11-2008, 09:23 PM
Senior Member
 
Join Date: Apr 2008
Location: Duesseldorf, Germany
Posts: 154
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: 1,057
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
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: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
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 Expert
 
Join Date: May 2007
Location: Derbyshire, UK
Posts: 623
Awards Showcase
Beta Tester 
Total Awards: 1
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
__________________
"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: 1,057
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
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: 15,733
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
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 Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
return codes of a shell command pmu5757 Questions (Windows Mobile) 18 06-15-2008 07:33 PM
All hail GeoTrail's return RandomCoder Chit Chat 1 02-17-2008 12:14 PM
Return value from Form ghislain Questions (Windows Mobile) 5 12-23-2007 07:34 AM
return issue Cableguy Questions (Windows Mobile) 1 09-21-2007 06:01 AM


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


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0