Results 1 to 14 of 14

Thread: DTPicker Please Replace it

  1. #1

    Thread Starter
    Member
    Join Date
    May 2003
    Posts
    54

    Angry 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...

  2. #2
    Lively Member Harvester's Avatar
    Join Date
    May 2002
    Location
    God's Country
    Posts
    124

    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

  3. #3
    Hyperactive Member Radames's Avatar
    Join Date
    Feb 2001
    Location
    Tech Tropics
    Posts
    360

    Wink

    Actually Harvester, that will return false because you are using the forward slash! For dates you use the backward slash.

  4. #4
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    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.

  5. #5
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    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:
    1. Private Sub Text1_KeyPress(KeyAscii As Integer)
    2.     'only allow numbers in our textbox
    3.     Select Case KeyAscii
    4.     Case 48 To 57, 8
    5.         'numbers 0-9 and Backspace
    6.     Case Else
    7.         KeyAscii = 0
    8.     End Select
    9. End Sub
    10. Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
    11.     Select Case KeyCode
    12.     Case 8  'Backspace
    13.     Case 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 96 To 105 '0 to 9
    14.         Dim lngTextPos As Long
    15.         Dim strText As String
    16.        
    17.         'save where the user's cursor was
    18.         lngTextPos = Text1.SelStart
    19.         'adjust position for slashes
    20.         If lngTextPos = 2 Then lngTextPos = 3
    21.         If lngTextPos = 5 Then lngTextPos = 6
    22.        
    23.         strText = Text1.Text
    24.        
    25.         'first lets get just the numbers
    26.         strText = Replace(strText, "/", "")
    27.         'there can only be 6 numbers!
    28.         strText = Left$(strText, 6)
    29.        
    30.         'now let's put the slashes back in where they belong
    31.         Select Case Len(strText)
    32.         Case 0 To 1
    33.             strText = strText
    34.         Case 2
    35.             strText = strText & "/"
    36.         Case 3
    37.             strText = Left$(strText, 2) & "/" & Right$(strText, 1)
    38.         Case 4
    39.             strText = Left$(strText, 2) & "/" & Right$(strText, 2) & "/"
    40.         Case 5
    41.             strText = Left$(strText, 2) & "/" & Mid$(strText, 3, 2) & "/" & Right$(strText, 1)
    42.         Case 6
    43.             strText = Left$(strText, 2) & "/" & Mid$(strText, 3, 2) & "/" & Right$(strText, 2)
    44.         End Select
    45.        
    46.         'replace the text in the textbox with
    47.         ' our "formatted" text
    48.         Text1.Text = strText
    49.        
    50.         'return to where the user's cursor was
    51.         Text1.SelStart = lngTextPos
    52.     End Select
    53. End Sub
    54. Private Sub Text1_LostFocus()
    55.     If IsDate(Text1) = False Then
    56.         MsgBox "Invalid Date", vbOKOnly, "Invalid Date"
    57.         Text1.SetFocus
    58.     End If
    59. 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.

  6. #6

    Thread Starter
    Member
    Join Date
    May 2003
    Posts
    54
    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

  7. #7
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    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:
    1. Public Function Valid_Date(ByVal sDate As String) As Boolean
    2.     Dim nMonth As Integer
    3.     Dim nDay As Integer
    4.     Dim sYear As String
    5.     Dim Valid As Boolean
    6.     Dim nNumOfDays(1 To 12) As Integer
    7.     On Error GoTo ErrHandler
    8.     Valid = True
    9.    
    10.     If Len(sDate) <> 8 Then
    11.          Valid = False
    12.     Else
    13.         nMonth = CInt(Left$(sDate, 2))
    14.         nDay = CInt(Mid$(sDate, 4, 2))
    15.         sYear = Right$(sDate, 2)
    16.  
    17.         nNumOfDays(1) = 31
    18.         'check if year is leap year
    19.         If IsDate("02/29/" & sYear) Then
    20.             nNumOfDays(2) = 29
    21.         Else
    22.             nNumOfDays(2) = 28
    23.         End If
    24.         nNumOfDays(3) = 31
    25.         nNumOfDays(4) = 30
    26.         nNumOfDays(5) = 31
    27.         nNumOfDays(6) = 30
    28.         nNumOfDays(7) = 31
    29.         nNumOfDays(8) = 31
    30.         nNumOfDays(9) = 30
    31.         nNumOfDays(10) = 31
    32.         nNumOfDays(11) = 30
    33.         nNumOfDays(12) = 31
    34.  
    35.         If nMonth < 1 Or nMonth > 12 Then
    36.             Valid = False
    37.         ElseIf nDay < 1 Or nDay > nNumOfDays(nMonth) Then
    38.             Valid = False
    39.         End If
    40.   End If
    41.   Valid_Date = Valid
    42.  
    43. ErrHandler:
    44.     If Err.Number <> 0 Then
    45.         ErrorTrap Err.Number, Err.Description, "Functions", "Valid_Date"
    46.         Exit Function
    47.     End If
    48. End Function
    Motto: Anything for a laugh.

    Getting second place only means you are the first loser to cross the finish line.

  8. #8
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    Oh and if you do want users to enter the day as dd/MM/yy then do this.

    VB Code:
    1. 'change this code
    2. nMonth = CInt(Left$(sDate, 2))
    3. nDay = CInt(Mid$(sDate, 4, 2))
    4.  
    5. 'to this
    6. nDay = CInt(Left$(sDate, 2))
    7. 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.

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  10. #10
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    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.

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  12. #12
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    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.

  13. #13
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    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.

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Click Here to Expand Forum to Full Width