Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Format date to dd/mm/yyyy in textbox
Author:
Geoff Poole
E-mail:
Click to e-mail author
Submitted:
5/31/2004
Version:
VB6
Compatibility:
VB3, VB4, VB5, VB6
Category:
Date/Time
Views:
133094
Routine to automatically format a date to dd/mm/yyyy. User types in 251204, 25/12/2004 is displayed.
Declarations:
To be used in textbox control set to maxlength 10.
Code:
Public Function TextBoxDateFormat(DAscii As Integer, DTBox As TextBox) 'Set error trapping on On Error GoTo ErrorHandler 'Inserts '/' into date TextBoxDateFormat = DAscii 'Check code If IsNumeric(Chr(DAscii)) Then 'Format If ((Len(DTBox.Text) = 2) Or (Len(DTBox.Text) = 5)) And (IsNumeric(Chr(DAscii))) Then 'Add a / DTBox.Text = DTBox.Text + "/" DTBox.SelStart = Len(DTBox.Text) ElseIf Len(DTBox.Text) = 7 Then 'Format DTBox.Text = Format(DTBox + Chr(DAscii), "dd/mm/yyyy") TextBoxDateFormat = 0 DTBox.SelStart = 10 End If ElseIf DAscii <> 8 Then 'Do not allow the keystroke TextBoxDateFormat = 0 End If 'Exit Exit Function ErrorHandler: 'Process error 'WriteToErrorLog "ModHelperRoutines", "TextBoxDateFormat", Err.Number, Err.Description Resume Next End Function
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement