Results 1 to 18 of 18

Thread: best way to validate a date???

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    best way to validate a date???

    I need to validate a date and validate a time.. but they are in seperate textboxes... how can I do this to make sure they enter the right information???

  2. #2
    Addicted Member WALDO's Avatar
    Join Date
    Aug 2002
    Location
    Swing of Prussia, PA
    Posts
    244
    If it were me, I would use the format function on both, concatenate the two, then evaluate the string as a date.

  3. #3
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    If it was me, i'd use DTPicker not the text box.
    I do not understand why does anybody have to use Textbox for these things?

  4. #4
    Addicted Member WALDO's Avatar
    Join Date
    Aug 2002
    Location
    Swing of Prussia, PA
    Posts
    244
    Because if you want to reduce the size of your setup/headaches, you might want to consider distributing LESS extra components.

  5. #5

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by techyspecy
    If it was me, i'd use DTPicker not the text box.
    I do not understand why does anybody have to use Textbox for these things?
    people here type fast.. its all date entry.. it is faster for them to type a date and a time in than to pick it from the control... i did already distribute common controls 2 to their PCs but I would rather use the textbox... well anyway i used this code to validate it

    VB Code:
    1. If IsDate(txtDate.Text) = False Or (InStr(1, txtDate.Text, ":") <> 0 Or InStr(1, txtDate.Text, "/") = 0) Then
    2.         MsgBox "Please enter valid date EX (" & Format(Date, "mm/dd/yyyy") & ")", vbInformation
    3.         txtDate.SetFocus
    4.     ElseIf IsDate(txtTime.Text) = False Or (InStr(1, txtTime.Text, ":") = 0 Or InStr(1, txtTime.Text, "/") <> 0) Then
    5.         MsgBox "Please enter valid TIME ex(" & Format(Time, "hh:MM AMPM") & ")", vbInformation
    6.         txtTime.SetFocus
    7.     Else
    8.         'ALL GOOD
    9.     End If

    please let me know if you see a loophole...

  6. #6
    Addicted Member WALDO's Avatar
    Join Date
    Aug 2002
    Location
    Swing of Prussia, PA
    Posts
    244

    Maybe this?

    VB Code:
    1. Dim strTest As String
    2. strTest = _
    3.     Format$(txtDate.Text, "mm/dd/yyyy") & _
    4.     " " & Format$(txtTime.Text, "hh:nn:ss AM/PM")
    5.  
    6. If IsDate(strTest) Then
    7.     'OK
    8. End If

  7. #7

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Maybe this?

    Originally posted by WALDO
    VB Code:
    1. Dim strTest As String
    2. strTest = _
    3.     Format$(txtDate.Text, "mm/dd/yyyy") & _
    4.     " " & Format$(txtTime.Text, "hh:nn:ss AM/PM")
    5.  
    6. If IsDate(strTest) Then
    7.     'OK
    8. End If
    but what if the text in the textboxes aren't in a valid date format to be accepted by the format$ function with those parameters.. that is why i did the check all in 1 line to check if first that it is a valid date (or time) and then check to make sure it doesn't have a : in it for a date and doesnt have a / in it for the time... because if it passes the isdate function then it must have a : if its a time or a / if its a date right?

  8. #8
    Addicted Member WALDO's Avatar
    Join Date
    Aug 2002
    Location
    Swing of Prussia, PA
    Posts
    244

    Oh, I see

    Keep doin' what you're doin' then.
    Maybe break those if's into separate functions
    VB Code:
    1. Function IsValidDate(Test) As Boolean
    2.     IsValidDate = Not( _
    3.         IsDate(Test) = False Or _
    4.         (InStr(1, Test, ":") <> 0 Or _
    5.         InStr(1, Test, "/") = 0))
    6. End Function
    7.  
    8. IsValidTime(Test) As Boolean
    9.     IsValidTime = Not( _
    10.         IsDate(Test) = False Or _
    11.         (InStr(1, Test, ":") = 0 Or _
    12.         InStr(1, Test, "/") <> 0))
    13. End Function
    14.  
    15. '...
    16.  
    17. If Not IsValidDate(txtDate.Text) Then
    18.     MsgBox "Please enter valid date EX (" & Format(Date, "mm/dd/yyyy") & ")", vbInformation
    19.     txtDate.SetFocus
    20. ElseIf Not IsValidTime(txtTime.Text) Then
    21.     MsgBox "Please enter valid TIME ex(" & Format(Time, "hh:MM AMPM") & ")", vbInformation
    22.     txtTime.SetFocus
    23. Else
    24.     'ALL GOOD
    25. End If

  9. #9
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    Originally posted by WALDO
    Because if you want to reduce the size of your setup/headaches, you might want to consider distributing LESS extra components.
    Obviously you do not know what you are talking about ....
    DTPicker requires no extra setup creation neither it creates any headaches. Its a standard windows component.

  10. #10

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by techyspecy
    Obviously you do not know what you are talking about ....
    DTPicker requires no extra setup creation neither it creates any headaches. Its a standard windows component.
    is it? i thought it was part of MSCOMCT2.OCX...

  11. #11
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    Originally posted by kleinma
    is it? i thought it was part of MSCOMCT2.OCX...
    yes it is, Does not matter if you install VB or not. You will get this component with windows.

    As far as your typing thingy goes, i believe your users can still type in DTpicker !!!! Its just a matter of time before they(users) get used to it.

  12. #12
    Lively Member mdsoren's Avatar
    Join Date
    Apr 2002
    Location
    Iowa, USA
    Posts
    113
    Matt,

    Don't know if this will help, but what I have done (aside from giving them the option to use the DTPicker by activating it on a dbl click in the txBox) is to use both CDate and Format!

    Here's an example...
    Code:
    tboCloseDate.text = Format(CDate(tboCloseDate.text), "mm/dd/yyyy")
    it appears to convert any thing the user puts into the tbox that CDate can interpret as a date, then it formats it into the form I want.

    Hope that helps ya.

    MDS

  13. #13
    Addicted Member WALDO's Avatar
    Join Date
    Aug 2002
    Location
    Swing of Prussia, PA
    Posts
    244

    Angry Check yourself, techyspecy

    Originally posted by techyspecy
    Obviously you do not know what you are talking about ....
    DTPicker requires no extra setup creation neither it creates any headaches. Its a standard windows component.
    I've seen too many instances where even Windows common controls have NOT been on users' PC's. Don't take it for granted that they'll be on every machine that you distribute your app to. Always include setup for EVERY component you use.

    I've been doing Windows installs for 7 years, now and I happen to know a thing or two about them.

    Open mouth,... insert foot.

  14. #14
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456

    Re: Check yourself, techyspecy

    Originally posted by WALDO
    I've seen too many instances where even Windows common controls have NOT been on users' PC's. Don't take it for granted that they'll be on every machine that you distribute your app to. Always include setup for EVERY component you use.

    I've been doing Windows installs for 7 years, now and I happen to know a thing or two about them.

    Open mouth,... insert foot.
    Ya, as if i care how long have you been doing installations for ?
    I been programming for 13 years, do you care ? I guess no.

    Any windows operating system above 95 will have this control unless someone intentionally deleted this control from there system.

  15. #15
    Addicted Member WALDO's Avatar
    Join Date
    Aug 2002
    Location
    Swing of Prussia, PA
    Posts
    244

    Untrue

    Originally posted by techyspecy
    Any windows operating system above 95 will have this control unless someone intentionally deleted this control from there system.
    Over the years I've seen multiple Windows operating systems packaged on PC's without minimum components. I'VE SEEN IT HAPPEN. I've seen instances where components have been removed from OS'es. Users are stupid. I've seen them remove core DLL's because they thought it would "take up too much space".

    Why don't you listen to someone who might know something you don't. I guess arrogance is hereditary. I realy hate the people who think that their replies and only their replies are the Gospel. They usually end up starting 17 post arguments with someone who happens to disagree with them, no matter how right or wrong either party is. It's one of the first signs of megalomania.

    Anyway, the point I was trying to make was that when you make setups, it would probably be in your best interesr to prepare for ANY and ALL stupid stuff, which means including extra components when you use them. When using extra components, adding them to setups creates larger setups, i.e. extra headaches/hassels.

    A reason to favor textboxes with code over the DTPicker control is to perhaps avoid such headaches.
    Last edited by WALDO; Dec 12th, 2002 at 06:24 PM.

  16. #16
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Opinions count for anything?

    On the DTPicker control :

    You users type so fast that you must provide validation of their entries and notify them if their entries are incorrect. With the DTPicker control, the format is correct (YOU KNOW IT'S A DATE).

    Either way, there is time involved. Either

    1) User has to learn to manipulate the DTPICKER (and yes, it can be type into) or,

    2) Validation, which cause more time to flag user, and them to have to change the entry.

    Just my thoughts...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  17. #17
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456

    Re: Well

    Originally posted by James Stanich
    Opinions count for anything?

    On the DTPicker control :

    You users type so fast that you must provide validation of their entries and notify them if their entries are incorrect. With the DTPicker control, the format is correct (YOU KNOW IT'S A DATE).

    Either way, there is time involved. Either

    1) User has to learn to manipulate the DTPICKER (and yes, it can be type into) or,

    2) Validation, which cause more time to flag user, and them to have to change the entry.

    Just my thoughts...
    Waldo, Learn something from this guy if you can't learn something from me.

    I will spare you with your pshychic thoughts. You say you been involved in programming or something for 7 years. But it looks to me as if you are working for some Kindergarton school.

    If you will think about these things (less component/headache but more stupidity/pain in the butt) you will never be able to develope any professional application (which looks to me you never were involved in).

    Have you ever used datagrid control (?????), thats a separate control, what are you going to do if you do not want to use it, and you have to display thousands of data in a organized manner. I betcha, you are going to use 1000's of textboxes.
    (Oops - , what will happen if someone removed data grid control from the system and i do not want to distribute it)

    BTW - Thank you very much for your comments on my arrogancy but i do not need any evaluation from people like you.
    Last edited by techyspecy; Dec 12th, 2002 at 07:53 PM.

  18. #18
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    BTW - Matt, if you do not want to use DTPicker (for some remote reason that i cannot imagine in my wildest of dreams ), why do not you give a try to Microsoft Masked Edit control 6.0 which can also serve your purpose (how efficiently - I do not know, never used it).

    Needless to mention my Bro waldo is going to be pissed with my arrogance.

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