Results 1 to 17 of 17

Thread: Text Box with Date Format

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Worldwide in the Sun
    Posts
    566

    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

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Why does 03022001 become 05/12/2001. ?

    What's the logic?
    Mark
    -------------------

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Worldwide in the Sun
    Posts
    566
    Woops, Sorry, That's a typing error

    The date should be the same of course.

    thanx Ray

  4. #4
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    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
    Mark
    -------------------

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Worldwide in the Sun
    Posts
    566
    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

  6. #6
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    I always use MaskEdBoxes for formatted text boxes. They're a doddle
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  7. #7
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    they're easy, but they do lack some features

    stupid microsoft

  8. #8
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    also darre1

    *** is up with ur signature?


    if 0 = 1 then
    0 = 0 + 1
    end

    ?


    which implies that

    1 = 1 + 1

    which is wrong ?


  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Worldwide in the Sun
    Posts
    566
    I agree completely with the sentence

    stupid microsoft

    but where is that alternative?


    cheers
    Ray

  10. #10
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Question

    You ever considered using the calendar control? The user can't type a date, and it is already formated for you.
    ~Peter


  11. #11
    DaoK
    Guest
    I agree completely with the sentence

    stupid microsoft

    but where is that alternative?
    Linux or Mac

  12. #12
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    but then we can't use visual basic and the like, so we would not be able to grace this forum with our presence

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Worldwide in the Sun
    Posts
    566
    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

  14. #14
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    i'm going to play around with linux soon

    see if i can gain some more skills

  15. #15
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Smile

    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


  16. #16
    Addicted Member Rikk's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta
    Posts
    131
    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!

  17. #17
    Hyperactive Member
    Join Date
    Sep 2001
    Location
    Orlando
    Posts
    392

    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
  •  



Click Here to Expand Forum to Full Width