|
-
Dec 12th, 2002, 08:16 AM
#1
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???
-
Dec 12th, 2002, 09:58 AM
#2
Addicted Member
If it were me, I would use the format function on both, concatenate the two, then evaluate the string as a date.
-
Dec 12th, 2002, 10:04 AM
#3
Let me in ..
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?
-
Dec 12th, 2002, 10:13 AM
#4
Addicted Member
Because if you want to reduce the size of your setup/headaches, you might want to consider distributing LESS extra components.
-
Dec 12th, 2002, 10:15 AM
#5
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:
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...
-
Dec 12th, 2002, 10:21 AM
#6
Addicted Member
Maybe this?
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
-
Dec 12th, 2002, 10:36 AM
#7
Re: Maybe this?
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
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?
-
Dec 12th, 2002, 11:14 AM
#8
Addicted Member
Oh, I see
Keep doin' what you're doin' then.
Maybe break those if's into separate functions
VB 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
-
Dec 12th, 2002, 02:46 PM
#9
Let me in ..
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.
-
Dec 12th, 2002, 02:48 PM
#10
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...
-
Dec 12th, 2002, 03:01 PM
#11
Let me in ..
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.
-
Dec 12th, 2002, 03:05 PM
#12
Lively Member
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
-
Dec 12th, 2002, 03:44 PM
#13
Addicted Member
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.
-
Dec 12th, 2002, 04:52 PM
#14
Let me in ..
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.
-
Dec 12th, 2002, 05:54 PM
#15
Addicted Member
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.
-
Dec 12th, 2002, 06:01 PM
#16
PowerPoster
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....
-
Dec 12th, 2002, 07:06 PM
#17
Let me in ..
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.
-
Dec 12th, 2002, 07:50 PM
#18
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
|