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
  #11 (permalink)  
Old 12-13-2009, 07:55 AM
taximania's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire. UK
Posts: 585
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Here's a starter for you. If you haven't done it already.

Code:
Sub VAL(s)
temp = 
""
temp2=
0
flag = 
0
If StrLength(s) = 0 Then
    
Return 0
Else
    len = StrLength(s)
    
For a = 0 To len -1
        
If IsNumber(StrAt(s,a)) Then
            temp = temp & StrAt(s,a)
        
Else
            
If StrAt(s,a) = "." Then
                
If flag = 0 Then
                    flag = 
1
                    temp = temp & 
"."
                
End If
            
End If
        
End If
    
Next
    
If temp = "" OR temp = "." Then
        
Return 0
    
Else
        temp2 = temp2 + temp
        
Return temp2
    
End If
End If
End Sub
Returns 0 for no number found.
The first '.' found is treat as a decimal point. All others are ignored.
Trims excessive leading and trailing '0's.
__________________
.
.
.
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
  #12 (permalink)  
Old 12-13-2009, 12:07 PM
Senior Member
 
Join Date: Nov 2009
Posts: 153
Default

That's pretty neat, Taximania, thanks.

Saves me having to switch my brain on! (It lasts longer in standby mode.)

Sarah
Reply With Quote
  #13 (permalink)  
Old 12-13-2009, 08:22 PM
taximania's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire. UK
Posts: 585
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Just trying to help the Basic4ppc community if I can
__________________
.
.
.
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
  #14 (permalink)  
Old 09-10-2010, 02:48 PM
Newbie
 
Join Date: Sep 2010
Posts: 2
Smile

I agree that it would be very useful.

Here is a typical use for Val():

A User types a time into a textbox, say "18:36".

I extract the hours portion using stringsex.mid to give a string called (say) MyHours holding "18".

Now I can code

if val(MyHours)<12 then
.......
end if

See how the computation is treating the string "18" as the value 18.

Voila!

I use this Val() function in VB6 a lot.

Is this helpful?
Reply With Quote
  #15 (permalink)  
Old 09-10-2010, 02:55 PM
derez's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Posts: 918
Awards Showcase
Beta Tester Competition Winner 
Total Awards: 2
Default

It can be done like this also without the Val sub:
if MyHours + 0 < 12 then... because the operation on the string converts it to a number.
__________________
David Erez
Ramat Hasharon, Israel
Reply With Quote
  #16 (permalink)  
Old 09-10-2010, 02:56 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 beacon View Post
See how the computation is treating the string "18" as the value 18.
As Basic4ppc is untyped, or more accurately does automatic type conversion, a numeric string is treated the same a numeric literal so Val is not needed in this case.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #17 (permalink)  
Old 09-10-2010, 04:11 PM
Basic4ppc Expert
 
Join Date: May 2008
Location: Berkshire, UK
Posts: 762
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by agraham View Post
As Basic4ppc is untyped, or more accurately does automatic type conversion, a numeric string is treated the same a numeric literal so Val is not needed in this case.
But there is a trap there that I fell into a few days ago. I was wishing to "correct" a "North" bearing value that is delivered by my GPS via NMEA as "360.0" which is not a valid value. (The GPS actually prevents me from entering that value via its user interface!)

So I wrote:
Code:
If headingDirection = 360 Then headingDirection = 0
What was in my head was that Basic4PPC would convert to numeric for the comparison but it doesn't and finds that "360.0" is not equal to 360. I would have used a Val() if Basic4PPC had one.

Mike.
Reply With Quote
  #18 (permalink)  
Old 09-10-2010, 04:37 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
What was in my head was that Basic4PPC would convert to numeric for the comparison but it doesn't and finds that "360.0" is not equal to 360.
Yes, I'm afraid that the Basic4ppc rule for logical comparisons is not documented but it seems that all comparisons are made as strings and typed variables are converted to a string for the comparison.
Quote:
I would have used a Val() if Basic4PPC had one.
Int or Abs would work in your situation.

As an aside there is an "interesting" difference between .NET and Java(Android) that I have encountered. In .NET a Double and an Integer containing the same integer value both convert to identical strings. e.g. "360". In Java the Double conversion always ends with a decimal place, even for an integer value so the resulting strings are not the same. e.g "360.0" for a Double and "360" for an Integer.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #19 (permalink)  
Old 09-11-2010, 05:24 AM
ceaser's Avatar
Basic4ppc Veteran
 
Join Date: May 2008
Location: Paarl, South Africa
Posts: 306
Default

Hi

How abot having a little as follows:

'S = String to be checked for a number

N=""
For i=0 to StrLength(s)
i1=Asc(SubString(S,i,1))
if i1=46 or (i1>=48 and i1<=57) then
N=N & i1
end if
Next i
Msgbox(N)

I have not checked it, but along this line should work.

Regards
Michael
Reply With Quote
  #20 (permalink)  
Old 09-11-2010, 10:29 AM
Basic4ppc Expert
 
Join Date: May 2008
Location: Berkshire, UK
Posts: 762
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by ceaser View Post
'S = String to be checked for a number ...
It would be (slightly!) interesting to know if the built-in automatic conversions can cope with all the number representations that can be generated by the Format() function... (Scientific notation; "." and "," separators; etc.)

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
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:53 PM.


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