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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy?... How do I create a number variable to check if number is 0 -9

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am new to this ... so please forgive my ignorance.<br>I am creating a program and have only one hitch to this point. I need to check if the next item in the $ is a digit<br>between 0 and 9. Then I will check the next item in the $ to and add it to the text$. I'm sure this is easy to do...but not when you don't know how.<br>Thanks,<br>Dan
 
What your going to have to use is the val() function, which gets a actual number value from a string, like, &quot;3&quot;. But I don't understand your question. Do you want to check 2 characters in a string, and if they are numbers, add them up and place them at the end of the string? Or what? All I can give you right now is how to check a character in a string and see if it is a number 0-9.

While val will get a value from a string, if it finds that
the string has a letter, like &quot;g&quot;, then it will return 0. Since you want to check for a number 0-9, we first have to find out if the text is a number or a letter.

'48-57 are the ascii codes for 0-9
IF ASC(MID$(string$, x, 1)) >= 48 and ASC(MID$(string$, x, 1)) <= 57 THEN
IF VAL(MID$(string$, x, 1)) >= 0 and VAL(string$, x) <=9 THEN
'This is a number 0-9, so do whatever you wanted to do with it
END IF
END IF

And, x is what part of the string you are looking at, for example: If x=3 and string$=&quot;abcd&quot; then the program would be looking at &quot;c&quot;. That is how the MID$ works.

Hope I wasn't to confusing.
 
Have you ever heard &quot;Do your own homework?&quot;

Cause that's what it sounds like. Ask your instructor/teacher/whomever for tips as to what you should look into instead of relying on others to just simply give you the code.

You'll find yourself learning more from discoverying the information yourself than just being told the answer.

You should look into MID$, ASCII Codes, and VAL().

Good Luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top