Hi
I plan to use text box to input dates. Is there any way I can accept in dd/mm/yyyy style providing user with a box having slashes at required space so that the user just needs to type in date, month and year without pressing slash button. I will be storing it as simple text cause there is no date calculations involved in my programm, but if at later stage i need them for some calculation, i hope that can be managed through coding.
I heard about masking but could not find any mask control option in vb6. If its available in vb6, how it can be used in program?
Regards
VB6 - Accepting date in Text Box
Page 1 of 19 Replies - 4525 Views - Last Post: 13 December 2012 - 08:22 PM
Replies To: VB6 - Accepting date in Text Box
#2
Re: VB6 - Accepting date in Text Box
Posted 23 November 2011 - 12:46 PM
Look at adding the the Masked Edit Control to your project (Project - Components or CTRL+T) and select the Microsoft Masked Edit Control.
Google on it's usage.
Google on it's usage.
#3
Re: VB6 - Accepting date in Text Box
Posted 23 November 2011 - 05:03 PM
maj3091, on 23 November 2011 - 11:46 AM, said:
Look at adding the the Masked Edit Control to your project (Project - Components or CTRL+T) and select the Microsoft Masked Edit Control.
Google on it's usage.
Google on it's usage.
Thats the easist way, there is another way which i use in generating licence keys... its a function that you set to go a specific distance, and at that point insert a slash char... its a simple mid statement...
i use a counter to keep the place holder...
then add the mid of counter and counter +2 and add a "/" char... then tell it to do it again... until its done correctly... but that takes a little bit more code, but i think it looks better, masked edit text boxes when a char is entered into the text box it creates the slashes right away... which to me looks bad.
play around with it, see what you come up with...
Jesse Fender
#4
Re: VB6 - Accepting date in Text Box
Posted 23 November 2011 - 08:16 PM
maj3091, on 24 November 2011 - 01:16 AM, said:
Look at adding the the Masked Edit Control to your project (Project - Components or CTRL+T) and select the Microsoft Masked Edit Control.
Google on it's usage.
Google on it's usage.
I already looked for that and did not found Masked Edit Control anywhere in Components. I am using VB 6.0 Professional.
Even if, this control is used to mask text boxes, will the slashes be display at run time automatically or they will appear when the text box get focus ?
Quote
Thats the easist way, there is another way which i use in generating licence keys... its a function that you set to go a specific distance, and at that point insert a slash char... its a simple mid statement...
i use a counter to keep the place holder...
then add the mid of counter and counter +2 and add a "/" char... then tell it to do it again... until its done correctly... but that takes a little bit more code, but i think it looks better
i use a counter to keep the place holder...
then add the mid of counter and counter +2 and add a "/" char... then tell it to do it again... until its done correctly... but that takes a little bit more code, but i think it looks better
chuckjessup, Can you please quote some example ?
The other way I think would be to present a 2 digit text box for the user to enter date (A check can be made if date is less then 1 or date is greater than 31) and a 2 digit text box displaying month in digit (might be combo box as web sites used to collect dates) and a 4 digit box displaying current year (disabled) would be a simple way out.
After getting inpute in boxes I will need to combine (add these strings) the input to a single string variable. (Adding strings is possible I guess).
Any suggestions ?
#6
Re: VB6 - Accepting date in Text Box
Posted 24 November 2011 - 03:52 AM
Maj 3091, Thanks for the input.
I am working the other way, coding it myself. Here is the code :
Everything here is working fine. Its reading dates, converting them and increasing. But the problem starts when i check for the invalid dates.
Like if I supply 29 as BDate, 02 as BMonth and 2011 as BYear it says "Run Time Error 13" Type Mismatch.
Need help.
Regards
I am working the other way, coding it myself. Here is the code :
Private Sub txtBMonth_LostFocus()
If Val(txtDDate) > 31 Then
MsgBox ("Please enter Valid Date...!")
txtDDate = Val(Day(Now)) + 2
txtDDate.SetFocus
End If
Dating = Trim$(txtBMonth) & "/" & Trim$(txtBDate) & "/" & Trim$(txtBYear)
OrdDate = CDate(Dating) 'Run Time Error 13" Type Mismatch
If IsDate(OrdDate) Then
DelDate = OrdDate + 2
If IsDate(DelDate) Then
txtDDate = Val(Day(DelDate))
txtDMonth = Month(DelDate)
txtDYear = Year(DelDate)
End If
Else
MsgBox ("Please enter valid date...")
txtDDate.SetFocus
End If
End Sub
Everything here is working fine. Its reading dates, converting them and increasing. But the problem starts when i check for the invalid dates.
Like if I supply 29 as BDate, 02 as BMonth and 2011 as BYear it says "Run Time Error 13" Type Mismatch.
Need help.
Regards
#7
Re: VB6 - Accepting date in Text Box
Posted 24 November 2011 - 04:57 AM
Ok !
I kept on struggling and found a way.
I changed my code slightly and checked for valid date just before assigning it to another variable and its working fine now.
I kept on struggling and found a way.
I changed my code slightly and checked for valid date just before assigning it to another variable and its working fine now.
Private Sub txtBMonth_LostFocus()
If Val(txtDDate) > 31 Then
MsgBox ("Please enter Valid Date...!")
txtDDate = Val(Day(Now)) + 2
txtDDate.SetFocus
End If
Dating = Trim$(txtBMonth) & "/" & Trim$(txtBDate) & "/" & Trim$(txtBYear)
Dating = Trim$(Dating)
If Not IsDate(Dating) Then 'Checking here if it is a valid date.
MsgBox ("Date is Invalid...")
txtBDate.SetFocus
Else
OrdDate = CDate(Dating) ' Assigning this value to OrdDate
DelDate = OrdDate + 2 ' Increasing Delivery Date by 2 days.
txtDDate = Val(Day(DelDate))
txtDMonth = Month(DelDate)
End If
End Sub
#8
Re: VB6 - Accepting date in Text Box
Posted 24 November 2011 - 05:12 AM
You check at the top of the function if the day is invalid ( >31), but you don't exit from the sub-routine at that point and you carry on trying to process the date.
I'm not saying what you have done is "wrong", but it's a little pointless to check it's invalid then carry on.
I'm not saying what you have done is "wrong", but it's a little pointless to check it's invalid then carry on.
#9
Re: VB6 - Accepting date in Text Box
Posted 24 November 2011 - 05:47 AM
Thats just a check if the user is typing day more than 31 i.e. restricting him to enter values below 31.
Your suggestion is also right since am checking the validity of date with IsDate() function and it will take care of the issue.
This is final code now. Changed variable name dating to Bdate (for Booking Date), DDate (for Delivery Date).
In fact earlier I was restricting entry to valid days manually.
Thanks for correcting.
Regards
Your suggestion is also right since am checking the validity of date with IsDate() function and it will take care of the issue.
This is final code now. Changed variable name dating to Bdate (for Booking Date), DDate (for Delivery Date).
Private Sub txtBMonth_LostFocus()
BDate = Trim$(txtBMonth) & "/" & Trim$(txtBDate) & "/" & Trim$(txtBYear)
If Not IsDate(BDate) Then
MsgBox ("Date is Invalid...")
txtBDate.SetFocus
Else
OrdDate = CDate(BDate)
DelDate = OrdDate + 2
txtDDate = Val(Day(DelDate))
txtDMonth = Month(DelDate)
txtDYear = Year(DelDate)
End If
End Sub
Private Sub txtDMonth_LostFocus()
Ddate = Trim$(txtDMonth) & "/" & Trim$(txtDDate) & "/" & Trim$(txtDYear)
If Not IsDate(Ddate) Then
MsgBox ("Date is Invalid...")
txtDDate.SetFocus
End If
End Sub
In fact earlier I was restricting entry to valid days manually.
Thanks for correcting.
Regards
#10
Re: VB6 - Accepting date in Text Box
Posted 13 December 2012 - 08:22 PM
chuckjessup, on 23 November 2011 - 05:03 PM, said:
maj3091, on 23 November 2011 - 11:46 AM, said:
Look at adding the the Masked Edit Control to your project (Project - Components or CTRL+T) and select the Microsoft Masked Edit Control.
Google on it's usage.
Google on it's usage.
Thats the easist way, there is another way which i use in generating licence keys... its a function that you set to go a specific distance, and at that point insert a slash char... its a simple mid statement...
i use a counter to keep the place holder...
then add the mid of counter and counter +2 and add a "/" char... then tell it to do it again... until its done correctly... but that takes a little bit more code, but i think it looks better, masked edit text boxes when a char is entered into the text box it creates the slashes right away... which to me looks bad.
play around with it, see what you come up with...
Jesse Fender
For me this is the fastest and easiest way in making date in textbox.
in text change event
if len(text1.text)=2 then text1.text = text1.text & "/"
if len(text1.text)=5 then text1.text = text1.text & "/"
if len(text1.text)=10 then text2.setfocus
Sendkeys "{End}"
That's it!
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|