Hi!
How can I verify if a string contains numbers or only letters?!
and, if its possible, to verify if the numbers contained in this string are in a specified interval,
like 0 < x < 100.000
Thanks!
This is one solution for the first bit.
The test for number values in a range is obviously possible to code but I'm not about to do it.
Function TestNosandlets(vString As String)
Dim HasNos As Boolean
Dim HasLets As Boolean
Dim x As Integer
Dim y As Integer
Dim ss As String
HasLets = False
HasNos = False
TestNosandlets = "Letters - " & HasLets & ": Numbers - " & HasNos
y = Len(vString)
If y = 0 Then Exit Function
For x = 1 To y
ss = Asc(Mid(vString, x, 1))
If ss >= 65 And ss <= 90 Then HasLets = True
If ss >= 97 And ss <= 127 Then HasLets = True
If ss >= 48 And ss <= 57 Then HasNos = True
If HasLets And HasNos Then Exit For
Next x
TestNosandlets = "Letters - " & HasLets & ": Numbers - " & HasNos
End Function
Function TestNumber (rec as variant) as boolean
'Takes a received variant and test it to see
'if the string is numeric test it to see if it is in range.
if isnumeric(rec) then
if val(rec) > 0 and val(rec) < 100000 then
testnumber = true
else
testnumber = false
end if
else
testnumber = false
end if
end function
If the return of this function is false, either the value of the string is numeric but outside the range or it contains alpha characters. If it is true then it is a number and within the range.
Andy Baldwin
"Testing is the most overlooked programming language on the books!
I think you need to be more specific. For example, what if the string contains multiple numerals separated by alpha characters? What "number" would you compare to your allowed range? Or, is the string always in a particular format or formats? A custom function could be coded to do exactly what you want but requires a well-defined specification of the inputs and desired results.
if , for ex. , I have a statement containing the word 'income'. I want to extract the numeric value from this statement just if this value is greater than 10.000.
something like this.
so first I need to see if I have a numeric value in this statement and then to check if this value is in a specific interval.
of course, if I have more than one value, then I need to verify for every numeric value to put maybe another condition , like to have currency sign.(for ex.$ or Eur)
I am sorry if I cant explain exactly what I need but I am still looking for writting the corect rules for this extraction.
thank you very much for all your answers!
"... I have a statement containing the word 'income'. ..."
"...extract the numeric value from this statement just if this value is greater than 10.000.
..."
"..of course, if I have more than one value..."
I think that you need to supply a variety of examples of the data that you will be encountering and the corresponding logic.
What are the TEXT values that are used in the logic?
What is the LOGIC assiciated with each different text string?
What is/are the FORMAT(s) of the text string that needs to be evaluated?
Skip,
[sub] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal... PULLEMALL![/sub]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.