Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. seperate string

seperate string

Scheduled Pinned Locked Moved Visual Basic
data-structuresquestion
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    macmac38
    wrote on last edited by
    #1

    Hello, i like to seperate an incoming string to an array. The values are delimited by commas. input string format like "122.23, 232.0, 12.34" I think of using the split function: Dim inputstr as variant list = split(inputstr,",") After this i like to put the several values in double format variables. This require some typecasting, right? Does anybody has the syntax for the loop and the typecyasting? I am new to vb.. happy coding, -mark

    J N 2 Replies Last reply
    0
    • M macmac38

      Hello, i like to seperate an incoming string to an array. The values are delimited by commas. input string format like "122.23, 232.0, 12.34" I think of using the split function: Dim inputstr as variant list = split(inputstr,",") After this i like to put the several values in double format variables. This require some typecasting, right? Does anybody has the syntax for the loop and the typecyasting? I am new to vb.. happy coding, -mark

      J Offline
      J Offline
      Jim Matthews
      wrote on last edited by
      #2

      Hi Mark, not sure which version of VB you're using (VBA, VBCLassic, or VB.Net) for splitting the string in VB.Net...

      Dim input as Object = "122.23, 232.0, 12.34"
      Dim arrList() as String = CStr(inputString).Split(","c)

      for casting the remaining items from the stringarray to a double format recursively in VB.Net...

      Dim arrCosts(arrList.GetUpperBound(0)) as Double
      for i as Int32 = 0 to arrList.Length - 1
      arrCosts(i) = Double.Parse(arrList(i).Trim)
      next

      arrCosts is an array of your Numbers in Double format. hope this helps.


      -jim

      M 2 Replies Last reply
      0
      • J Jim Matthews

        Hi Mark, not sure which version of VB you're using (VBA, VBCLassic, or VB.Net) for splitting the string in VB.Net...

        Dim input as Object = "122.23, 232.0, 12.34"
        Dim arrList() as String = CStr(inputString).Split(","c)

        for casting the remaining items from the stringarray to a double format recursively in VB.Net...

        Dim arrCosts(arrList.GetUpperBound(0)) as Double
        for i as Int32 = 0 to arrList.Length - 1
        arrCosts(i) = Double.Parse(arrList(i).Trim)
        next

        arrCosts is an array of your Numbers in Double format. hope this helps.


        -jim

        M Offline
        M Offline
        macmac38
        wrote on last edited by
        #3

        Thanks, i am using vba on excel 2003 happy coding, -mark

        1 Reply Last reply
        0
        • J Jim Matthews

          Hi Mark, not sure which version of VB you're using (VBA, VBCLassic, or VB.Net) for splitting the string in VB.Net...

          Dim input as Object = "122.23, 232.0, 12.34"
          Dim arrList() as String = CStr(inputString).Split(","c)

          for casting the remaining items from the stringarray to a double format recursively in VB.Net...

          Dim arrCosts(arrList.GetUpperBound(0)) as Double
          for i as Int32 = 0 to arrList.Length - 1
          arrCosts(i) = Double.Parse(arrList(i).Trim)
          next

          arrCosts is an array of your Numbers in Double format. hope this helps.


          -jim

          M Offline
          M Offline
          macmac38
          wrote on last edited by
          #4

          mmh, by the way do you have an VBA implementation? happy coding, -mark
          os win2000 vba office 2003, vc++ 6.0

          J 1 Reply Last reply
          0
          • M macmac38

            mmh, by the way do you have an VBA implementation? happy coding, -mark
            os win2000 vba office 2003, vc++ 6.0

            J Offline
            J Offline
            Jim Matthews
            wrote on last edited by
            #5

            sorry mark, i have absolutely 0 experience with vba and i don't want to give you bad information. this small bit shouldn't be that difficult to translate though. actually, thinking about it, in vba are there any other data types other than variant? or am i thinking of vb script...


            -jim

            1 Reply Last reply
            0
            • M macmac38

              Hello, i like to seperate an incoming string to an array. The values are delimited by commas. input string format like "122.23, 232.0, 12.34" I think of using the split function: Dim inputstr as variant list = split(inputstr,",") After this i like to put the several values in double format variables. This require some typecasting, right? Does anybody has the syntax for the loop and the typecyasting? I am new to vb.. happy coding, -mark

              N Offline
              N Offline
              Nick Seng
              wrote on last edited by
              #6

              dim str as string

              For Each str in list
              Value = CDbl(str)
              Next

              This should probably work


              "if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.

              M 1 Reply Last reply
              0
              • N Nick Seng

                dim str as string

                For Each str in list
                Value = CDbl(str)
                Next

                This should probably work


                "if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.

                M Offline
                M Offline
                macmac38
                wrote on last edited by
                #7

                Hi, confusing.. So how must be the code to read out the input string into the the double type text fields as shown below? Dim input As Variant Dim value(1 to 3) AS double input = "122.23, 232.0, 12.04" . . . labelx.caption = value(1) //double 122.23 labely.caption = value(2) //double 232.0 labelz.caption = value(3) //double 12.04 happy coding, -mark
                os win2000 vba office 2003, vc++ 6.0

                N 1 Reply Last reply
                0
                • M macmac38

                  Hi, confusing.. So how must be the code to read out the input string into the the double type text fields as shown below? Dim input As Variant Dim value(1 to 3) AS double input = "122.23, 232.0, 12.04" . . . labelx.caption = value(1) //double 122.23 labely.caption = value(2) //double 232.0 labelz.caption = value(3) //double 12.04 happy coding, -mark
                  os win2000 vba office 2003, vc++ 6.0

                  N Offline
                  N Offline
                  Nick Seng
                  wrote on last edited by
                  #8

                  Dim i as integer
                  dim str as string = Split(input,",")

                  For i = 1 to 3
                  value(i) = CDbl(str(i-1))
                  Next


                  "if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.

                  M 1 Reply Last reply
                  0
                  • N Nick Seng

                    Dim i as integer
                    dim str as string = Split(input,",")

                    For i = 1 to 3
                    value(i) = CDbl(str(i-1))
                    Next


                    "if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.

                    M Offline
                    M Offline
                    macmac38
                    wrote on last edited by
                    #9

                    input = "122.23, 232.0, 12.04" Dim i As Integer Dim str() As String str = Split(input, ",") For i = 1 To 3 value(i) = CDbl(str(i - 1)) Next Labelx.Caption = value(1) // 12223 Labely.Caption = value(2) // 2320 Labelz.Caption = value(3) // 1204 Yeah, this works. But why are the output values no float variables? happy coding, -mark
                    os win2000 vba office 2003, vc++ 6.0

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups