Auto Date generation at runtime. This code generate date in dd/MM/yyyy format just after typing in
Auto Date generation at runtime. This code generate date in dd/MM/yyyy format just after typing in the TextBox.
API Declarations
‘copy this code
‘call the given procedure in Keypress event of related textbox.
‘pass the text box and keyascii as parameters.
Dim i As Integer
Dim t1 As String
Dim t2 As String
Rate Auto Date generation at runtime. This code generate date in dd/MM/yyyy format just after typing in
(2(2 Vote))
If Val(keyasci) = 8 Then
If TextBoxName.Text = Empty Then
i = 0
Else
i = i - 1
End If
Exit Sub
End If
i = i + 1
If i = 3 Then
t1 = Mid(TextBoxName.Text, 1, 2)
t2 = Mid(TextBoxName.Text, 3, 1)
TextBoxName.Text = Trim$(t1) & "/" & t2
TextBoxName.SelStart = 4
t2 = Empty
ElseIf i = 6 Then
t1 = Mid(TextBoxName.Text, 1, 5)
t2 = Mid(TextBoxName.Text, 6, 1)
TextBoxName.Text = Trim$(t1) & "/" & t2
TextBoxName.SelStart = 7
't1 = Mid(TextBoxName.Text, 1, 7)
'TextBoxName.Text = t1
End If
If i = 11 Then Exit Sub
End Sub
‘Call DateValidation function in lostfocus event of the textbox for which you have written the above code
Public Function DateValidation(TextBoxName as TextBox) As Boolean
If IsDate(Trim$(TextBoxName.Text)) = False Then
MsgBox "Enter valid date in dd/mm/yyyy format.", vbInformation, "System Info.."
TextBoxName.SetFocus
DateValidation = False
ElseIf Not Len(Trim$(TextBoxName.Text)) = 10 Then
MsgBox "Enter valid date in dd/mm/yyyy format.", vbInformation, "System Info.."
TextBoxName.SetFocus
DateValidation = False
Else
DateValidation = True
End If
End Function
Auto Date generation at runtime. This code generate date in dd/MM/yyyy format just after typing in Comments
No comments yet — be the first to post one!
Post a Comment