Results 1 to 4 of 4

Thread: Like Operator

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2000
    Location
    London
    Posts
    19

    Cool 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?

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    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

  3. #3
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    Try the IsNumeric Function:

    VB Code:
    1. varUserErr = IsNumeric(strTime)
    2.  
    3. If varUserErr = False Then
    4. msgbox "Another idiot has put the wrong info in!"
    5. End If


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  4. #4
    DerFarm
    Guest
    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
  •  



Click Here to Expand Forum to Full Width