B4J Question How do I get the numeric value of a string?

Mikelgiles

Active Member
Licensed User
Longtime User
What is the proper replacement for the VB6 VAL command? ie num=VAL("1234") that works in VB6

Is there a VB6 B4J cross reference anywhere?
 

sorex

Expert
Licensed User
Longtime User
just dim your destination (num) as int

in some cases you might need parseInt
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
i do not know VB6 but B4J.

you may use:

B4X:
if isnumber("123456") then
'This will work.
dim num as int = "123456"
end if

now that i think of it. B4x language easiest the transformation for strings and integers, in JAVA that would be impossible to do.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
sure, when working with string seperations it sometimes doesn't work as expected while it works fine with regex.

B4X:
Dim txt="12345"
Log(5*txt.CharAt(3))  <- doesn't compile
Log(5*Bit.ParseInt(txt.CharAt(3),10))  <- works fine

using an extra int variable is the workaround ofcourse.
 
Upvote 0

Mikelgiles

Active Member
Licensed User
Longtime User
Thanks guys. Sometimes I just need to remember that just because VB6 needs something doesn't mean that B4J does. Sometimes it is easier to figure out the hard things than it is to figure out the easy things! I like that the VAL function is not needed and it makes perfect sense.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…