VB6 Find a number in a String
Eric
-
teebo Posted messages 33585 Registration date Status Contributor Last intervention -
teebo Posted messages 33585 Registration date Status Contributor Last intervention -
Hello,
I need help. I have to find out if a string starts with a digit (0,1,2,3..) without performing the test 10 times.
Thank you in advance.
Eric
I need help. I have to find out if a string starts with a digit (0,1,2,3..) without performing the test 10 times.
Thank you in advance.
Eric
4 answers
-
If you create a SQL database with your strings, you will perform queries on it and SQL will give you the results without fail.
Otherwise, you filter your string to extract the first character and you test its type (or its value) if the value of the first 8 or 4 (depending on the program) is counted between 0 and 9, it's a digit which is also their ASCII code I believe, so there is no possible confusion.-
There is no SQL database; it's a recurring variable on a text control that I want to test.
An user enters a word that can contain but not start with a digit.
I have to do:
variable = left(variable,1) ' to isolate the first character
If Val(variable) ... and a test to know if it's a number (still to be defined how, but I will figure it out).
Ok, but I have a vague memory of
If left(variable,1) is numeric ...
of course, that doesn't work. I asked the question hoping for a response like this.
Thank you for your contribution.
Eric
-
-
Go here
http://www.vbasic.org and you can find a code that unlocks you
A hand ties a package and two several.
Where do you ask Mboo if you dance? -
Select case left(variable,1)
Case "1","2","3","4","5","6","7","8","9","0"
MsgBox "User sale, read the doc for fuck's sake"
Case Else
MsgBox "Congratulations, you know the difference between a number and a letter
End select
In principle, but I think there are other solutions too...
. .
\_/ -
Otherwise it should also work
If variable Like "[0-9]*" then MsgBox "RTFM"
. .
\_/