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???
Printable View
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???
If it were me, I would use the format function on both, concatenate the two, then evaluate the string as a date.
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? :confused:
Because if you want to reduce the size of your setup/headaches, you might want to consider distributing LESS extra components.
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 itQuote:
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? :confused:
VB Code:
If IsDate(txtDate.Text) = False Or (InStr(1, txtDate.Text, ":") <> 0 Or InStr(1, txtDate.Text, "/") = 0) Then MsgBox "Please enter valid date EX (" & Format(Date, "mm/dd/yyyy") & ")", vbInformation txtDate.SetFocus ElseIf IsDate(txtTime.Text) = False Or (InStr(1, txtTime.Text, ":") = 0 Or InStr(1, txtTime.Text, "/") <> 0) Then MsgBox "Please enter valid TIME ex(" & Format(Time, "hh:MM AMPM") & ")", vbInformation txtTime.SetFocus Else 'ALL GOOD End If
please let me know if you see a loophole...
VB Code:
Dim strTest As String strTest = _ Format$(txtDate.Text, "mm/dd/yyyy") & _ " " & Format$(txtTime.Text, "hh:nn:ss AM/PM") If IsDate(strTest) Then 'OK 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?Quote:
Originally posted by WALDO
VB Code:
Dim strTest As String strTest = _ Format$(txtDate.Text, "mm/dd/yyyy") & _ " " & Format$(txtTime.Text, "hh:nn:ss AM/PM") If IsDate(strTest) Then 'OK End If
Keep doin' what you're doin' then.
Maybe break those if's into separate functionsVB Code:
Function IsValidDate(Test) As Boolean IsValidDate = Not( _ IsDate(Test) = False Or _ (InStr(1, Test, ":") <> 0 Or _ InStr(1, Test, "/") = 0)) End Function IsValidTime(Test) As Boolean IsValidTime = Not( _ IsDate(Test) = False Or _ (InStr(1, Test, ":") = 0 Or _ InStr(1, Test, "/") <> 0)) End Function '... If Not IsValidDate(txtDate.Text) Then MsgBox "Please enter valid date EX (" & Format(Date, "mm/dd/yyyy") & ")", vbInformation txtDate.SetFocus ElseIf Not IsValidTime(txtTime.Text) Then MsgBox "Please enter valid TIME ex(" & Format(Time, "hh:MM AMPM") & ")", vbInformation txtTime.SetFocus Else 'ALL GOOD End If
Obviously you do not know what you are talking about ....Quote:
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.
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...Quote:
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.
yes it is, Does not matter if you install VB or not. You will get this component with windows.Quote:
Originally posted by kleinma
is it? i thought it was part of MSCOMCT2.OCX...
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.
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...
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.Code:tboCloseDate.text = Format(CDate(tboCloseDate.text), "mm/dd/yyyy")
Hope that helps ya.
MDS
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.Quote:
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 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 ?Quote:
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.
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. :D
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".Quote:
Originally posted by techyspecy
Any windows operating system above 95 will have this control unless someone intentionally deleted this control from there system.
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.
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. :DQuote:
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...
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. :D
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. :D
(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.
BTW - Matt, if you do not want to use DTPicker (for some remote reason that i cannot imagine in my wildest of dreams :D), 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. :p