Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with val function

Status
Not open for further replies.

nivini

Programmer
Mar 24, 2004
64
0
0
I have this code
Code:
if instr(1, text1.text, "TEMP") then
valTEXT=val(text1.text)
end if

text1.text contain TEMP8003
not as expected, the valTEXT variable gets 0 instead of 8003
can you solve this mistery to me?
nivini
 
From MSDN

The Val function stops reading the string at the first character it can't recognize as part of a number.

so since T isnt a number it returns 0.

if the format is to always be TEMP<Number> then you can use

Code:
if instr(1, text1.text, "TEMP") then
valTEXT=val(mid(text1.text,5)
end if

If somethings hard to do, its not worth doing - Homer Simpson
 
ADoozer
Many thanks
nivini
 
From MSDN? Heck, it is documented in VB's online help files, often a good place to look for help on VB ...

F1 is your friend
 
[1] Recall to a recent discussion.

[2] Slightly generalize prefix+num+... structure as posted.
[tt]
if instr(1, text1.text, "<prefix>") then
valTEXT=val(mid(text1.text,instr(1,text1.text,"<prefix>")+len("<prefix>")))
end if
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top