Results 1 to 8 of 8

Thread: splitting the text

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    24

    splitting the text

    how to split the text in textbox i.e when we enter the data in text box like this 220304 we should get the output as 22/03/04

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,092
    I would use a maskedit box instead of a standard textbox.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    if you know they are going to enter 6 numbers, and only six numbers:
    VB Code:
    1. dim myStr as String
    2. dim myNewStr as String
    3. myStr = Text1.text
    4. myNewStr = Left(myStr,2) & "/" & Mid(myStr,2) & "/" & Right(myStr,2)
    5. 'msgbox myNewStr
    6. text1.text = myNewStr

    note: untested.
    Have I helped you? Please Rate my posts.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    24

    split

    thanks a lot acidic it helped me out thanx

  5. #5
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655
    Originally posted by Acidic
    if you know they are going to enter 6 numbers, and only six numbers:
    VB Code:
    1. dim myStr as String
    2. dim myNewStr as String
    3. myStr = Text1.text
    4. myNewStr = Left(myStr,2) & "/" & Mid(myStr,2) & "/" & Right(myStr,2)
    5. 'msgbox myNewStr
    6. text1.text = myNewStr

    note: untested.
    So maybe add before that code
    VB Code:
    1. If Len(Text1.Text) > 6 Then Msgbox "Number too long, try again" : Exit Sub
    2. If Len(Text1.Text) < 6 Then
    3. Do
    4. Text1.Text = "0" & Text1.Text
    5. Loop Until Len(Text1.Text) = 6
    6. 'And voila! :)

    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

  6. #6
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Originally posted by Ruku
    So maybe add before that code
    VB Code:
    1. If Len(Text1.Text) > 6 Then Msgbox "Number too long, try again" : Exit Sub
    2. If Len(Text1.Text) < 6 Then
    3. Do
    4. Text1.Text = "0" & Text1.Text
    5. Loop Until Len(Text1.Text) = 6
    6. 'And voila! :)
    But that'll just add 0s to the beggining... If I enter : 2404 I might mean 2/4/2004... So the addition of 0s doesn't help


    Has someone helped you? Then you can Rate their helpful post.

  7. #7
    Member
    Join Date
    Mar 2004
    Location
    Texas
    Posts
    53
    Let's say you enter in 1204 then 12104, instead of starting from the front, lets start from the back, assuming the last 2 digits will be the year, so now we have 12 and 121 for the '12' we know that it has to be 1/2/04, but waht about the second? it can be 1/21 or 12/1, to distinguish, you will have to require the user to use a 0 in fron of digits 1-9. thus making the size 6, u can simplify everything by just reading in 3 sets of 2 digits. so now we have
    010204 -> read in 2 at a tine 01/02/04, then 012104-> read in 2 at a time 01/21/04. THis is a approach I'd reccomend. Good luck!

    PS add in the codition simiolar to manavo11:
    VB Code:
    1. If Len(Text1.Text) <> 6 Then Msgbox "Date in wrong format"
    Good programming site:
    *http://www.planet-source-code.com

    Our CS Clan Page:
    *http://h2p.inter-gamer.com/index.html

  8. #8
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    You might want to try the date picker control

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