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?

VAL keyword

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-10-2009, 08:33 PM
Senior Member
 
Join Date: Nov 2009
Posts: 153
Default VAL keyword

I would love a VAL keyword.

f = val(s)

Where f is floating point number and s is string.

Any numerical value found within the string is copied into float b.

(If no numerical value is found within string s then then f = 0)
Reply With Quote
  #2 (permalink)  
Old 12-10-2009, 09:15 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 3,826
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

You have the IsNumber keyword.

From the help file:

Return true if the string is a number.
Syntax: IsNumber (String)
Example:
If IsNumber(TextBox1.Text) = true Then
Msgbox (TextBox1.Text * 20)
End If

Best regards.
__________________
Klaus
Switzerland
Reply With Quote
  #3 (permalink)  
Old 12-10-2009, 09:19 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Yopu can easily synthesise Val with IsNumber.

Code:
Sub Val(str)
  
If IsNumber(str) Then
    
Return str
  
Else
    
Return 0
  
End If
End Sub
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #4 (permalink)  
Old 12-10-2009, 11:25 PM
Senior Member
 
Join Date: Nov 2009
Posts: 153
Default

Thank you guys.

But this code, and the isnumber keyword do not do what the old basic 'VAL' did.

I need a keyword that can parse a string and return the numeric value even if that value is part of an alphabetic string.

Take string: "COM4". Using the above code you will not get '4' as the numeric part, you will get a 'false' value (0).

I am sure the old programming keyword VAL ("COM4") would return the numeric value of '4'.

Yes, I could write a routine that parsed the string but given that the VAL keyword has always been part of basic since the early DOS days I would prefer it be part of the math subset of keywords in this version of basic. Very useful function and i miss it (although I don't miss MSDOS.

aGraham, your routine (below) would return a '0' if the string 'str' equaled: "COM4", whereas VAL(str) would return a '4'.

ub Val("COM4")
If IsNumber(str) Then
Return str
Else
Return 0 ...... RETURNS WITH '0' when it should return with '4'
End If
End Sub

FWIW: Your extra libraries are just excellent, Andrew. They have really enhanced b4ppc for me. Thank you so much.

Last edited by SarahWard : 12-10-2009 at 11:46 PM.
Reply With Quote
  #5 (permalink)  
Old 12-11-2009, 02:23 AM
Senior Member
 
Join Date: Apr 2007
Location: Arlington, Washington USA
Posts: 176
Default

Actually, that is not how the VB Val function works. To quote the VB help file: "The Val function stops reading the string at the first character it can't recognize as part of a number."

I tried it, and Val("Com4") returns 0. Val("4Com") would return 4.

I got the same results in the old DOS QuickBasic, and I'm pretty sure the Val function worked this way in all flavors of DOS basic.
Reply With Quote
  #6 (permalink)  
Old 12-11-2009, 01:16 PM
Basic4ppc Expert
 
Join Date: May 2008
Location: Berkshire, UK
Posts: 762
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Returning zero as a fault condition is not very helpful, since it is a good numeric value. Is there not a "not a number" value instead? Or I think I would vote for an error condition (if given the chance!).
Reply With Quote
  #7 (permalink)  
Old 12-11-2009, 02:00 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by mjcoon View Post
Returning zero as a fault condition is not very helpful
It's not necessarily a fault depending upon the use required of the function. I've just run my 26 year old copy of GW-Basic and in that Val behaves as dfallen indicated as it also does in my copy of QuickBasic 4.5.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #8 (permalink)  
Old 12-11-2009, 10:20 PM
Senior Member
 
Join Date: Nov 2009
Posts: 153
Default

It was the VAL from QuickBasic 4.5 that I remembered. Also val from early visual basic.
DlFallen: I guess it didn't do exactly what I had presumed.

I agree with aGraham. Zero as a 'false' flag is good because we used to use zero as a 'false' flag before the age of VB.

I have needed the old VAL keyword several times recently in my various freeware programs.


I think, in practice, the numeric value was usually the only characters in the string. Often it was the string and VAL would simply convert it to a usable numeric value. I suppose IsNumber would do this as long as the string was pure numeric value.
Reply With Quote
  #9 (permalink)  
Old 12-12-2009, 06:13 AM
Senior Member
 
Join Date: Apr 2007
Location: Arlington, Washington USA
Posts: 176
Default

VAL had other "features" as well. For one, it would strip out spaces, linefeeds, and tabs. So, for example, VAL("12 34") woud return 1234.

One good thing is that it would recognize &H and &O as hex or octal numbers.

The bad news is that it only recognized the the period as the decimal separator so it was not useful in international applications.

As I recall, I had a custom VAL function that I used in my aplications. Not hard to code and it did what I wanted the way I wanted it done. When speed was important, I would code it in assembler. Of course, that was in the pre-Windows era and processors were slow. I have no inclination to program in assembler under Windows.
Reply With Quote
  #10 (permalink)  
Old 12-12-2009, 04:32 PM
Senior Member
 
Join Date: Nov 2009
Posts: 153
Default

Quote:
Originally Posted by dlfallen View Post
VAL had other "features" as well. For one, it would strip out spaces, linefeeds, and tabs. So, for example, VAL("12 34") woud return 1234.

One good thing is that it would recognize &H and &O as hex or octal numbers.

The bad news is that it only recognized the the period as the decimal separator so it was not useful in international applications.

As I recall, I had a custom VAL function that I used in my aplications. Not hard to code and it did what I wanted the way I wanted it done. When speed was important, I would code it in assembler. Of course, that was in the pre-Windows era and processors were slow. I have no inclination to program in assembler under Windows.
It still sounds like a really useful keyword.

Assembler under windows would be like building a coastal barrier my moving one pebble at a time.
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
Today keyword? JesseW Basic4ppc Wishlist 3 03-21-2009 11:26 AM
find keyword lijingtong Questions (Windows Mobile) 2 06-20-2008 10:05 AM
Auto Keyword im4retro Questions (Windows Mobile) 2 06-06-2008 04:45 PM
Comment after Do keyword Erel Bug Reports 1 07-24-2007 09:33 PM
filesearch keyword Cableguy Questions (Windows Mobile) 6 05-16-2007 06:44 PM


All times are GMT. The time now is 09:30 PM.


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