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

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

Basic4ppc Wishlist Missing any feature?

Subs parameters

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-20-2010, 12:17 PM
Junior Member
 
Join Date: Sep 2009
Posts: 18
Default Subs parameters

Hello

I would like to have some way to return from Sub more then one value.
For example:

Sub min_max(a,b,min,max)
If a<b Then
min=a
max=b
Else
min=b
max=a
End If
End Sub

Calling as:
min_max(no1,no2,minimum,maximum)

I would expect after run filled out variables minimum and maximum with right values.

Thnx
Reply With Quote
  #2 (permalink)  
Old 01-20-2010, 02:15 PM
derez's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Posts: 918
Awards Showcase
Beta Tester Competition Winner 
Total Awards: 2
Default

Your wish can be answered in two options :
1. to define min and max as global, then they are changed by the sub and you can refer to their value outside of the sub (and they should not be in the arguments list).
2. to return one variable which is a string : min & "," & max, and then use an array of 2 to split it
Code:
Dim mix(2)

sub min_max(a,b)
...
...
return min & "," & max
end sub

mix() = strsplit(min_max(a,b) , 
",")
min = mix(0)
max = mix(1)
__________________
David Erez
Ramat Hasharon, Israel

Last edited by derez : 01-20-2010 at 02:20 PM.
Reply With Quote
  #3 (permalink)  
Old 01-20-2010, 03:10 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 3,827
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

I agree with merli.
I had this wish to pass parameters to subroutines also by reference and not only by value, some time ago.

Erel's answer:
Quote:
It will be supported in a future version too (not sure when though).
here : http://www.basic4ppc.com/forum/quest...n-1-value.html

Unfortunately it was not in the wishlist, but in a 'Question & Help needed' thread.

Best regards.
__________________
Klaus
Switzerland
Reply With Quote
  #4 (permalink)  
Old 01-20-2010, 07:22 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Passing variables by reference will be supported in the next version (its release date is not set yet).
__________________
Basic4android documentation
Reply With Quote
  #5 (permalink)  
Old 01-20-2010, 07:26 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 3,827
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

That sounds like good news.

Thank you Erel.

Best regards.
__________________
Klaus
Switzerland
Reply With Quote
  #6 (permalink)  
Old 01-21-2010, 07:08 AM
Junior Member
 
Join Date: Sep 2009
Posts: 18
Default

Quote:
Originally Posted by derez View Post
Your wish can be answered in two options :
1. to define min and max as global, then they are changed by the sub and you can refer to their value outside of the sub (and they should not be in the arguments list).
2. to return one variable which is a string : min & "," & max, and then use an array of 2 to split it
Code:
Dim mix(2)

sub min_max(a,b)
...
...
return min & "," & max
end sub

mix() = strsplit(min_max(a,b) , 
",")
min = mix(0)
max = mix(1)
Nice workaround, but you still have to have arrays global declared. Erel, is it planned to have posibility declare arrays localy?
Reply With Quote
  #7 (permalink)  
Old 01-21-2010, 10:04 AM
Basic4ppc Expert
 
Join Date: May 2008
Location: Berkshire, UK
Posts: 762
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by merli View Post
Nice workaround, but you still have to have arrays global declared. Erel, is it planned to have posibility declare arrays locally?
How would that work, except by having arrays (or other variables) passed by reference so that the names are local to the Sub but the data that is manipulated is external to the Sub? (Which is what we are promised for a future version.)

Using globals is so clunky because to operate on varied data each has to be loaded into the global(s) before calling the Sub and then "unloaded" afterwards. This doesn't help with the readability of the code.

Mike.
Reply With Quote
  #8 (permalink)  
Old 01-22-2010, 08:05 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Quote:
Nice workaround, but you still have to have arrays global declared. Erel, is it planned to have posibility declare arrays localy?
Declaring local arrays and structures was initially planned for the next version. Though I believe it will only be added in the following version.
__________________
Basic4android documentation
Reply With Quote
  #9 (permalink)  
Old 01-22-2010, 08:09 AM
Junior Member
 
Join Date: Sep 2009
Posts: 18
Default

Quote:
Originally Posted by mjcoon View Post
How would that work, except by having arrays (or other variables) passed by reference so that the names are local to the Sub but the data that is manipulated is external to the Sub? (Which is what we are promised for a future version.)

Using globals is so clunky because to operate on varied data each has to be loaded into the global(s) before calling the Sub and then "unloaded" afterwards. This doesn't help with the readability of the code.

Mike.
You are right, but there is another problem when I want to use in Sub some helping temporary array which won't be used after return. I still have to now define this array Global
Reply With Quote
  #10 (permalink)  
Old 01-22-2010, 09:50 AM
Basic4ppc Expert
 
Join Date: May 2008
Location: Berkshire, UK
Posts: 762
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by merli View Post
... when I want to use in Sub some helping temporary array which won't be used after return. I still have to now define this array Global
Yes, the relaxed implicit-variant treatment of local variables does not work for arrays. This is because all elements of the array have to have the same variant for the indexing mechanism to work (I suppose), so the easy way out is to require all arrays to be declared in a "Dim" before they are used.

Erel has mentioned making variables more sophisticated in the past, so perhaps including a local "Dim" could be introduced for local arrays.

Mike.
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
Passing arrays to Subs. jesb4ppc Questions (Windows Mobile) 12 04-24-2009 10:05 AM
IDE subs list width klaus Beta Versions 1 09-28-2008 04:56 AM
How to use timer to clock speed of subs? Stellaferox Questions (Windows Mobile) 4 02-28-2008 08:07 AM
Passing references to tables to subs LineCutter Questions (Windows Mobile) 5 05-31-2007 09:27 PM


All times are GMT. The time now is 10:10 PM.


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