Results 1 to 6 of 6

Thread: Only numbers and dots... (easy one :)

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2000
    Posts
    47
    Hi!


    How to check that a label contains only numbers and dots (like in date)? eg. "12.5.1999"



    I have VB6 in Win98.


  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Try this
    Code:
    Function checkdots(lbl As Label) As Boolean
    Dim letter As String
    Dim i, count, ascn As Integer
    For i = 1 To Len(lbl.Caption)
    letter = Mid(lbl.Caption, i, 1)
    ascn = Asc(letter)
    If ascn > 47 And ascn < 58 Or ascn = 46 Then
    count = count + 1
    End If
    Next i
    If count = Len(lbl.Caption) Then
    checkdots = True
    Else
    checkdots = False
    End If
    End Function
    Usage
    Code:
    dim res as Boolean
    res = checkdots(Label1)
    'if there are only numbers and dots in label 1 it wil return true
    'else it returns false
    [Edited by Vlatko on 10-28-2000 at 07:50 AM]
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Vlatko, nice code, works well too.
    But I've a few suggestions (learned from Kedaman )

    Code:
    Function checkdots(lbl As Label) As Boolean
    Dim letter$ ' $ means As String
    'Dim i, count, ascn As Integer 'ouch, this doesn't mean dim them all as integer, only ascn so do it like this
    Dim i%, count%, ascn% '% means integer
    
    For i = 1 To Len(lbl.Caption)
    letter = Mid(lbl.Caption, i, 1)
    ascn = Asc(letter)
    If ascn > 47 And ascn < 58 Or ascn = 46 Then count = count + 1 'this is a bit shorter, not nessecary at all.
    Next i
    
    'Now here comes the tip I learned from Kedaman:
    'You can change all this:
    'If count = Len(lbl.Caption) Then
    'checkdots = True
    'Else
    'checkdots = False
    'End If
    'to:
    checkdots = (count = Len(lbl.Caption))
    End Function
    Hope you don't see this as an assault because it isn't at all, I think it's just handy to learn!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Jop:

    Nice touch.

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    No of course i don't think of this as an assault. That is
    a great trick from Kedaman. It will sure come handy sometimes.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  6. #6
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Ok cool Vlatko! some people see that kind of posts like a attempt 'to be better', but that's not how I post it

    Thanks for understanding me folks! (**** I'm drunk, just came back from a night going out )
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

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