Results 1 to 9 of 9

Thread: [RESOLVED] Simple code

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Resolved [RESOLVED] Simple code

    I have text for example:

    11.12.2009 or 7.8.2004 and how to get three variables, a, b, c
    a = 7
    b = 8
    c = 2004

    Thanks!

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Simple code

    Well, those sure look like dates, which offers up a couple methods. Since they are strings now, one thing you can do is to get the pieces directly with SubString, but that would get awkward since the dots can move around depending on whether the day and month are single or double digit. The better way to do this would be to convert to date using CDate (if you can be certain that they will always be dates, and Date.TryParse otherwise). You can then use the Month, Day, and Year properties to get those pieces from the date.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Re: Simple code

    I don't understand. That's not a date (just look like date), this can be some other string (98.72.2941), code?

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Simple code

    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Re: Simple code

    Does somebody have code for this I ask. I know when I have two elements

    split

    string(0)
    string(1)

    and now with point???

  6. #6
    Member
    Join Date
    Feb 2009
    Posts
    60

    Re: Simple code

    Dim a As Integer = ""
    Dim b As Integer = ""
    Dim c As Integer = ""

    Would this work? :S
    VB 2008 Beginner
    I'll Try And Help As Much As I Can

  7. #7
    Fanatic Member Megalith's Avatar
    Join Date
    Oct 2006
    Location
    Secret location in the UK
    Posts
    879

    Re: Simple code

    Code:
    Dim test as string = "78.95.9646"
    Dim splitString() as String
    splitString()= test.split(".")
    ' At this point we have 3 strings in an array
    Dim a, b, c as integer
    a = CInt(splitstring(0))
    b = CInt(splitstring(1))
    c = CInt(splitstring(2))
    If debugging is the process of removing bugs, then programming must be the process of putting them in.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Re: Simple code

    Thank you Megalith!

  9. #9
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Simple code

    Quote Originally Posted by Megalith View Post
    Code:
    Dim test as string = "78.95.9646"
    Dim splitString() as String
    splitString()= test.split(".")
    ' At this point we have 3 strings in an array
    Dim a, b, c as integer
    a = CInt(splitstring(0))
    b = CInt(splitstring(1))
    c = CInt(splitstring(2))
    This only works so long as the string contains only numbers separated by periods.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

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