|
-
Aug 15th, 2003, 06:16 AM
#1
Thread Starter
Member
DTPicker Please Replace it
I am unable to understand why Microsoft did not offer HANDLE of this control, it's EDIT box is s***
Is there any other Control (FREE) which do the same as DTPicker but also give User, handy way of enter date, NOT enter DD value and then use arrow key to go MM area for entry.
If there is no such type control, then please any one can guide me to How to validate Date other than CDate function, i mean Leap Year, days in the month like these...
Thanks in advance...
Looking forward to your help, suggestion any thing...
-
Aug 15th, 2003, 07:37 AM
#2
Lively Member
isDate
Is the dropdown on the dtPicker not enough? I don't know of any other free controls.
If you end up having to do your own validation use the isDate Function.
isDate("02\29\2000")
'Returns true
-
Aug 15th, 2003, 08:55 AM
#3
-
Aug 15th, 2003, 12:31 PM
#4
Fanatic Member
How are they going to be entering a date? DD/MM/YY? Or do you have four position for year?
Last edited by Maldrid; Aug 18th, 2003 at 10:21 AM.
Motto: Anything for a laugh.
Getting second place only means you are the first loser to cross the finish line.
-
Aug 15th, 2003, 12:48 PM
#5
Fanatic Member
Well this is something you can try to work with. Just create a text box and the user will enter a date in the textbox. Let me know if you need any other help.
VB Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
'only allow numbers in our textbox
Select Case KeyAscii
Case 48 To 57, 8
'numbers 0-9 and Backspace
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 8 'Backspace
Case 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 96 To 105 '0 to 9
Dim lngTextPos As Long
Dim strText As String
'save where the user's cursor was
lngTextPos = Text1.SelStart
'adjust position for slashes
If lngTextPos = 2 Then lngTextPos = 3
If lngTextPos = 5 Then lngTextPos = 6
strText = Text1.Text
'first lets get just the numbers
strText = Replace(strText, "/", "")
'there can only be 6 numbers!
strText = Left$(strText, 6)
'now let's put the slashes back in where they belong
Select Case Len(strText)
Case 0 To 1
strText = strText
Case 2
strText = strText & "/"
Case 3
strText = Left$(strText, 2) & "/" & Right$(strText, 1)
Case 4
strText = Left$(strText, 2) & "/" & Right$(strText, 2) & "/"
Case 5
strText = Left$(strText, 2) & "/" & Mid$(strText, 3, 2) & "/" & Right$(strText, 1)
Case 6
strText = Left$(strText, 2) & "/" & Mid$(strText, 3, 2) & "/" & Right$(strText, 2)
End Select
'replace the text in the textbox with
' our "formatted" text
Text1.Text = strText
'return to where the user's cursor was
Text1.SelStart = lngTextPos
End Select
End Sub
Private Sub Text1_LostFocus()
If IsDate(Text1) = False Then
MsgBox "Invalid Date", vbOKOnly, "Invalid Date"
Text1.SetFocus
End If
End Sub
[edit]
Make sure to set the textbox to 8 max length
Last edited by Maldrid; Aug 15th, 2003 at 12:54 PM.
Motto: Anything for a laugh.
Getting second place only means you are the first loser to cross the finish line.
-
Aug 16th, 2003, 12:36 AM
#6
Thread Starter
Member
Thank you... very much... this is really a goooood help.... Thank you..
But what about the leap year checking ... for example I give '30/02/01' to the text and it still validate it correctly, also when i give '31/09/03' this date it also validate it, even '31' is not available in the September month.
How i a can figure out these, my first thinking is that i creat an Array and put DAYS count in it and check it accordingly, but what about the leap year, YEAR divided by 4 .... could not figuring out... i am working on it, if u give me any idea... it wil be helpful...
Thanx in advance to alllllllllll
-
Aug 18th, 2003, 10:16 AM
#7
Fanatic Member
Oh you know what, I expect people to enter the day as MM/dd/yy. Ok but here is something I do besides using IsDate to validate my dates.
VB Code:
Public Function Valid_Date(ByVal sDate As String) As Boolean
Dim nMonth As Integer
Dim nDay As Integer
Dim sYear As String
Dim Valid As Boolean
Dim nNumOfDays(1 To 12) As Integer
On Error GoTo ErrHandler
Valid = True
If Len(sDate) <> 8 Then
Valid = False
Else
nMonth = CInt(Left$(sDate, 2))
nDay = CInt(Mid$(sDate, 4, 2))
sYear = Right$(sDate, 2)
nNumOfDays(1) = 31
'check if year is leap year
If IsDate("02/29/" & sYear) Then
nNumOfDays(2) = 29
Else
nNumOfDays(2) = 28
End If
nNumOfDays(3) = 31
nNumOfDays(4) = 30
nNumOfDays(5) = 31
nNumOfDays(6) = 30
nNumOfDays(7) = 31
nNumOfDays(8) = 31
nNumOfDays(9) = 30
nNumOfDays(10) = 31
nNumOfDays(11) = 30
nNumOfDays(12) = 31
If nMonth < 1 Or nMonth > 12 Then
Valid = False
ElseIf nDay < 1 Or nDay > nNumOfDays(nMonth) Then
Valid = False
End If
End If
Valid_Date = Valid
ErrHandler:
If Err.Number <> 0 Then
ErrorTrap Err.Number, Err.Description, "Functions", "Valid_Date"
Exit Function
End If
End Function
Motto: Anything for a laugh.
Getting second place only means you are the first loser to cross the finish line.
-
Aug 18th, 2003, 10:20 AM
#8
Fanatic Member
Oh and if you do want users to enter the day as dd/MM/yy then do this.
VB Code:
'change this code
nMonth = CInt(Left$(sDate, 2))
nDay = CInt(Mid$(sDate, 4, 2))
'to this
nDay = CInt(Left$(sDate, 2))
nMonth = CInt(Mid$(sDate, 4, 2))
Motto: Anything for a laugh.
Getting second place only means you are the first loser to cross the finish line.
-
Aug 18th, 2003, 10:33 AM
#9
syedhassan4:
May I ask why you started out asking about the handle for the dtp?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 18th, 2003, 10:35 AM
#10
Fanatic Member
I am guessing he was trying to subclass it.
Motto: Anything for a laugh.
Getting second place only means you are the first loser to cross the finish line.
-
Aug 18th, 2003, 10:46 AM
#11
If subclassing, why not just use FindWindow?
Then during subclassing you can manipulate it however you want?
That is, if this is what he was thinking of doing.
Check out my banked code for DTPs dropdown by code.
DTP DropDown by code
DTPs are better than using Textboxes.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 18th, 2003, 10:53 AM
#12
Fanatic Member
How would you use FindWindow for a control? Also your example has nothing to do with subclassing, but it is still pretty nice stuff.
Motto: Anything for a laugh.
Getting second place only means you are the first loser to cross the finish line.
-
Aug 18th, 2003, 10:57 AM
#13
Fanatic Member
But I don't understand why he mentioned that it doesn't not have a handle, because the way I see it, it does.
Motto: Anything for a laugh.
Getting second place only means you are the first loser to cross the finish line.
-
Aug 18th, 2003, 11:08 AM
#14
Thanks.
Every "control" is created upon a "window" or nested "windows"
and every control has a handle. You just need to know how to
obtain it.
If you subclass you will need to know if the messages are
pertaining to the correct control you want.
You would use something like FindWindow, FindowWindowEx,
and GetWindowLong. These will help you get the ControlID of the
control to make sure you are working on the right control during
subclassing.
Also, the wParam and lParam contain valuable info too.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|