Hi!
How to check that a label contains only numbers and dots (like in date)? eg. "12.5.1999"
I have VB6 in Win98.
Printable View
Hi!
How to check that a label contains only numbers and dots (like in date)? eg. "12.5.1999"
I have VB6 in Win98.
Try this
UsageCode: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
[Edited by Vlatko on 10-28-2000 at 07:50 AM]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
Vlatko, nice code, works well too.
But I've a few suggestions (learned from Kedaman :))
Hope you don't see this as an assault because it isn't at all, I think it's just handy to learn!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
Jop:
Nice touch.
:D
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.
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 :))