|
-
Dec 10th, 2001, 11:09 AM
#1
Thread Starter
Fanatic Member
Text Box with Date Format
On my form I have a Textbox with Date properties specified as
dd/mm/yyyy.
When the user enters : 03022001, I want following
result in the text box : 05/12/2001.
But the format seems not to do the job.
How can I fix that problem.
The best solution would be that automatically, on the right
position in the text box, the slash would be inserted.
Any tips and samples are welcome.
Thanx
Ray
-
Dec 10th, 2001, 11:12 AM
#2
Frenzied Member
Why does 03022001 become 05/12/2001. ?
What's the logic?
-
Dec 10th, 2001, 11:16 AM
#3
Thread Starter
Fanatic Member
Woops, Sorry, That's a typing error
The date should be the same of course.
thanx Ray
-
Dec 10th, 2001, 11:30 AM
#4
Frenzied Member
I think you'll have to do it using Mid()
Code:
Option Explicit
Private Sub Command1_Click()
Debug.Print formatdate(Text1.Text)
End Sub
Private Function formatdate(d As String) As String
Dim strout As String
If Len(d) = 8 Then
Select Case Format("01/02", "d")
Case 1
strout = Mid(d, 1, 2) & "/" & Mid(d, 3, 2) & "/" & Mid(d, 5)
Case 2
strout = Mid(d, 3, 2) & "/" & Mid(d, 1, 2) & "/" & Mid(d, 5)
End Select
Else
strout = "Incorrect Date supplied"
End If
formatdate = strout
End Function
-
Dec 10th, 2001, 11:50 AM
#5
Thread Starter
Fanatic Member
Mark, your code works fine.
I hoped there was a shorter way by using a
format(text1,"dd/mm/yyy") and in the same time the
user only needed to type a date, the slash was automatic
inserted because of the date format.
But that doesn't work.
Maybe a bug in VB 
I remember something similar in the good old dBase IV
and was looking for a similar code.
Thanx
Ray
-
Dec 14th, 2001, 07:31 AM
#6
Bouncy Member
I always use MaskEdBoxes for formatted text boxes. They're a doddle
-
Dec 14th, 2001, 07:33 AM
#7
Conquistador
they're easy, but they do lack some features 
stupid microsoft
-
Dec 14th, 2001, 07:36 AM
#8
Conquistador
also darre1
*** is up with ur signature?
if 0 = 1 then
0 = 0 + 1
end
?
which implies that
1 = 1 + 1
which is wrong ?
-
Dec 14th, 2001, 11:00 AM
#9
Thread Starter
Fanatic Member
-
Dec 14th, 2001, 11:20 AM
#10
Frenzied Member
You ever considered using the calendar control? The user can't type a date, and it is already formated for you.
~Peter

-
Dec 14th, 2001, 12:41 PM
#11
I agree completely with the sentence
stupid microsoft
but where is that alternative?
Linux or Mac
-
Dec 14th, 2001, 07:50 PM
#12
Conquistador
but then we can't use visual basic and the like, so we would not be able to grace this forum with our presence
-
Dec 15th, 2001, 02:34 AM
#13
Thread Starter
Fanatic Member
Well, maybe linux is better but I don't like it. 
And when I should use linux I loose this forum, NO WAY. 
I have to check it out, never used the calendar control.
Thanx
Ray
-
Dec 15th, 2001, 04:24 AM
#14
Conquistador
i'm going to play around with linux soon 
see if i can gain some more skills
-
Dec 16th, 2001, 06:40 PM
#15
Frenzied Member
Hopefully the calendar control will put a smile on your face.
And i don't know about you folks, but i'm happy with Microsoft. I'd hate to suffer with those other OS's. I shudder to think about it. My machine boots and runs sweet. I have no complaints.
~Peter

-
Dec 16th, 2001, 09:18 PM
#16
Addicted Member
Originally posted by da_silvy
also darre1
*** is up with ur signature?
if 0 = 1 then
0 = 0 + 1
end
?
which implies that
1 = 1 + 1
which is wrong ?
I think it's right!! If 0 = 1 then 1 = 0 that means 0 + 0 = 1 if looked at like 0 (really a 1) + 0 (really a 0) = 1 (really a 1) OR
0 = 0 + 1 (really a 0)
Rikk =\=
Starcraft, Protoss Scout Driver!
-
Dec 16th, 2001, 10:32 PM
#17
Hyperactive Member
Just for the Record
There is a DatePicker Control in VB which is for Date Input. You could specify the input format etc. And it also displays the calender control if the user wants it.
This should satisfy all your Date Input need.
If you don't like the readymade solution, create your own. If you don't know how to do that, learn it.
Or switch to something else. No body begged you to use Microsoft.
More often, it is our lack of knowledge, where we don't even care to know if any solution already exist.
Abu Haider
____________________________
100% Data Validation for the MS DataGrid Control. Plus Support for Custom and Foreign Lists, DatePicker and much more...
The DataGridEnhancer
I often point to a place where the problem has been discussed, instead of giving you the code that solves it. This is for good, may be you will understand some day...
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
|