VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Auto Date generation at runtime. This code generate date in dd/MM/yyyy format just after typing in

by Ashish Deo (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 14th May 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

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



    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


Download this snippet    Add to My Saved Code

Auto Date generation at runtime. This code generate date in dd/MM/yyyy format just after typing in Comments

No comments have been posted about Auto Date generation at runtime. This code generate date in dd/MM/yyyy format just after typing in . Why not be the first to post a comment about Auto Date generation at runtime. This code generate date in dd/MM/yyyy format just after typing in .

Post your comment

Subject:
Message:
0/1000 characters