View Single Post
 
Old February 22nd, 2009, 12:23 AM
bnil53 bnil53 is offline
Registered User
 
Join Date: Feb 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Enter Date without Masking (VB6)

PLACE A TESTBOX & COPY & PASTE THE FOLLOWING CODE... THERE IS NO VALIDATION

Code:
Option Explicit
Private Const GWL_STYLE = (-16)
Private Const ES_NUMBER As Long = &H2000&
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" 
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" 
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Sub Form_Load()
'set the textbox to accept numbers only
Dim lStyle As Long
lStyle = GetWindowLong(Text1.hwnd, GWL_STYLE)
lStyle = lStyle Or ES_NUMBER
SetWindowLong Text1.hwnd, GWL_STYLE, lStyle
End Sub

Private Sub Text1_Change()
'insert slash character at appropriate position
If Len(Text1.Text) = 2 Or Len(Text1.Text) = 5 Then
Text1.SelLength = Len(Text1.Text)
Text1.SelText = "/"
End If
End Sub