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!

strings manipulating

Status
Not open for further replies.

vlad123

Programmer
Jun 22, 2005
37
0
0
DE
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


?testnosandlets("12DS")
Letters - True: Numbers - True
?testnosandlets("1234")
Letters - False: Numbers - True
?testnosandlets("asDS")
Letters - True: Numbers - False
 
You may also play with the IsNumeric function and the Like operator.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
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.


Regards,
Mike
 
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!
 
Post several examples of input strings covering the range of possibilities.

Mike
 

"... 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]
[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top