It is currently Fri Mar 24, 2017 3:02 am



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: A more tolerant VAL()
Unread postPosted: Thu Oct 22, 2015 7:55 pm 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 408
These aren't perfect, but I use readnumber(s$) to pull out numerical values from a string rather than risk getting an error from VAL()

Code:
FN.DEF isadigit(s$)
FN.RTN IS_IN(s$, "-0123456789.")
FN.END

FN.DEF hasdigits(s$)
LET I=1
LET Found=0
DO
  found=isadigit(MID$(s$, I, 1))
  I++
UNTIL i>LEN(s$) | found
FN.RTN found
FN.END

! extract number from s$
FN.DEF readnumber(s$)
LET N$=""
FOR i=1 TO LEN(s$)
  LET C$=MID$(s$, I, 1)
  IF isadigit(c$) THEN N$+=c$
NEXT i
IF LEN(n$) >0 THEN FN.RTN VAL(n$)
FN.RTN 0
FN.END


Top
 Profile  
 
 Post subject: Re: A more tolerant VAL()
Unread postPosted: Sun Nov 22, 2015 5:22 pm 
Offline

Joined: Sat Nov 21, 2015 8:27 pm
Posts: 27
Cool. But in some countries comma is used as decimal separator, maybe update so it can be used?


Top
 Profile  
 
 Post subject: Re: A more tolerant VAL()
Unread postPosted: Sun Nov 22, 2015 10:17 pm 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5446
Location: Paris, France
Not in computer languages.
In BASIC! you need to write your decimal numbers like 3.14 not 3,14 so as in any other language that I know.

_________________
- Creator of the Android BASIC! Compiler


Top
 Profile  
 
 Post subject: Re: A more tolerant VAL()
Unread postPosted: Mon Nov 23, 2015 1:13 am 
Offline

Joined: Sat Nov 21, 2015 8:27 pm
Posts: 27
I was thinking more along the lines of changing commas into periods, so 3,14 becomes 3.14, in the string then doing conversion so both can be used.


Top
 Profile  
 
 Post subject: Re: A more tolerant VAL()
Unread postPosted: Mon Nov 23, 2015 2:49 am 
Offline
User avatar

Joined: Tue Sep 13, 2011 4:58 am
Posts: 718
Location: Sao Paulo, Brasil
Good idea, but will the app know it? Track usage of . and , and change accordingly?

_________________
Alfredo Peine

-------------

Hisense Sero 7 Pro (Tegra 3 7" rooted tablet - Android 4.4.4) / Moto G 3rd Gen (5" quad core rooted phone - Android 6.0).


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred