Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Dates w/ Masked Edit or VB6 TextBox

Posted on 1999-06-30
13
Medium Priority
?
1,454 Views
Last Modified: 2012-05-04
I need a simple way for the user to enter a date like "123199" and have the date convert to "12/31/99" or "12/31/1999".

My problem - I am trying to use the VB6 masked edit box and using the Date data format property as mm/dd/yy.
When running the app, I am required to enter the Julian date (i.e., 35,900) and then I will get the appropriate mm/dd/yy date.

Also - when I use the VB6 TextBox, which also has the DataFormat property, I set the property for mm/dd/yy, but when running the app, nothing appears to occur as a result.

For example, when I enter in the "123199" and tab out of the TextBox, the text remains "123199" when I expect the "12/31/99" format that I set up in the DataFormat property.
0
Comment
Question by:wileecoy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +3
13 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 1521208
DataFormat only work with bound controls.

Have you tried the Date Time Picker?
0
 
LVL 4

Author Comment

by:wileecoy
ID: 1521209
I hoped that they didn't have to be bound.

What is the Date Time Picker?
0
 
LVL 4

Author Comment

by:wileecoy
ID: 1521210
I hoped that they didn't have to be bound.

What is the Date Time Picker?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 4

Author Comment

by:wileecoy
ID: 1521211
I found it - Testing...
0
 
LVL 4

Author Comment

by:wileecoy
ID: 1521212
Claim your prize - That works good.

Thanks.
0
 
LVL 6

Expert Comment

by:sharmon
ID: 1521213
You could also do something like this, but would have to put a little more checking in it.

Function MMDDYY_To_Date(ByVal strDate As String) As String
    MMDDYY_To_Date = Mid$(strDate, 1, 2) & "/" & Mid$(strDate, 3, 2) & "/" & Mid$(strDate, 5, 2)

End Function

Private Sub Form_Load()

End Sub

Private Sub txtDate_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then txtDate = MMDDYY_To_Date(txtDate)

End Sub

Private Sub txtDate_LostFocus()
txtDate = MMDDYY_To_Date(txtDate)
End Sub
0
 
LVL 3

Expert Comment

by:gajendra
ID: 1521214
Masket Edit supports to properties, namely FORMAT and MASK that are useful in such times.

set mask to ##/##/##    -> This decides how data will be entered

and format to mm/dd/yyyy -> This decides how it will be shown at other times.

Notice the 2# for mask and 4y for the format. These variations may be handled to your advantage for entering and showing values.

HTH

Gajendra

0
 

Expert Comment

by:davepcam1
ID: 1521215
Umm, you could however set the Masked edit Box to ##/##/##

for the textbox when u tab out of it do something like this

private sub text1_Lostfocus()
text1.text = cdate(text1.text)
end sub

0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1521216
The problem is that it doesn't know how to interpret the string 123199 as a date.

The best thing to do is the following. When the user tabs out of the box, take its contents and

- extract the last two digits. If <=39, prefix with 20, if >40, prefix with 19 to make a date between 1940 and 2039; you can choose other watershed values if you wish.

- extract the middle and first two digits. Now you can reformat the string as

"yyyy/mm/dd"

And this you can always convert to a Date field

Dim datX As Date

datX = CDate("1986/03/30") '30 March 1986

Once you've converted it to a proper date field, you can convert it to any date format you like


0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 1521217
Isn't it me that was supposed to claim the prize!
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1521218
Patience.... Just wait until wileecoy rejects gajendra's answer.

gajendra - once someone invites someone else to claim the prize or get their points it is considerted "courteous" in EE not to lock the question anymore and to leave that for the invited person. Of course you're always welcome to add comments.
0
 
LVL 4

Author Comment

by:wileecoy
ID: 1521219
Thanks caraf_g, for repeating the protocol.

I was looking for a quick, clean answer - emoreau responded with both.

Again, claim your prize emoreau.  I've already got it in and working in my app.

0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 80 total points
ID: 1521220
Thanks wileecoy!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question