|
-
May 24th, 2002, 10:56 AM
#1
Thread Starter
Junior Member
Like Operator
I am currently extracting some information out of a long string of text and one of the variables I am extracting is plain numbers approx 6 charaacters in length.
Unfortunatly some people have put in strings such as 00:20 which causes a Type Mismatch as I only want to output numbers.
Therefore I am trying the like operator to capture these but I have a problem:
currently using :
---------------------------------------------------------------------------
varUserErr = strTime Like "[0-9]"
If varUserErr = False Then
msgbox "Another idiot has put the wrong info in!"
End If
---------------------------------------------------------------------------
The problem is that if they put in 20 or anything else with more than 1 digit it returns False,
Therefore how can I check for 6 characters of just numbers?
-
May 24th, 2002, 11:03 AM
#2
Frenzied Member
Try the IsNumeric function and the <> 6 in an If..Then...Else statement.
Something like
If IsNumeric(strTime) and StrTime <> 6 Then
your code
else
whatever
end if
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
May 24th, 2002, 11:04 AM
#3
Frenzied Member
Try the IsNumeric Function:
VB Code:
varUserErr = IsNumeric(strTime)
If varUserErr = False Then
msgbox "Another idiot has put the wrong info in!"
End If
MicroBasic
Dragon Shadow Trainer
There is no good or evil in the world...only programmers and fools .
-
May 24th, 2002, 11:15 AM
#4
well, this is fairly time consuming, but, lacking any better answer:
Code:
Function NumStuff(PasdString as string, _
Optional NumLen as integer, _
Optional NoLeadingZero as Boolean, _
Optional PosOnly as Boolean, _
Optional IntOnly as Boolean) as Long
dim xstr as string, lstr as integer, i as integer
dim Ret_Val as long
if NumLen<=0 then
xNumLen=6
else
xNumLen=NumLen
endif
lstr = len(PasdString)-xNumLen
for i = 1 to lstr
xstr = mid$(PasdString,i,xNumLen)
if isnumeric(xstr) then
Ret_Val = val(xstr)
if NoLeadingZero and Ret_Val<val("1" & string$(xNumLen-1,"0") then
goto NxtI
endif
if PosOnly and Ret_Val<0 then goto NxtI
if IntOnly and instr(xstr,".") >0 then goto NxtI
goto Xit_NumStuff
endif
NxtI:
next i
Xit_NumStuff:
NumStuff = Ret_Val
end Function
If I haven't made any really stupid errors, the above should
work. Note that the number of digits is variable, the leading zero
operator is variable, you can restrict it to positive numbers
only, it can be restricted to Integers only.
HTH
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|