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. get string array length

get string array length

Scheduled Pinned Locked Moved Visual Basic
databasealgorithmsdata-structureshelp
4 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.
  • S Offline
    S Offline
    Stephan Wright
    wrote on last edited by
    #1

    does anyone of you know how to get the length of a string array? My code looks like this mystring = ActiveDocument.Paragraphs(index) mydata = Split(mystring, " ") So in the beginning I do not know the size of the array. But I do need to know if the word I am searching for, is in this array. Therefor I have to parse the array to search it. But if I do not know the upper limit, this causes a "out of bounds" error. So I do need the upper limit to avoid the error to be thrown. Could anyone please tell me how to get the length so I could do the following (in VBA!) ? For i = 0 to upperlimit if mydata(i) = mysearchstring then do something end if Next Thanks! Stephan.

    F S 2 Replies Last reply
    0
    • S Stephan Wright

      does anyone of you know how to get the length of a string array? My code looks like this mystring = ActiveDocument.Paragraphs(index) mydata = Split(mystring, " ") So in the beginning I do not know the size of the array. But I do need to know if the word I am searching for, is in this array. Therefor I have to parse the array to search it. But if I do not know the upper limit, this causes a "out of bounds" error. So I do need the upper limit to avoid the error to be thrown. Could anyone please tell me how to get the length so I could do the following (in VBA!) ? For i = 0 to upperlimit if mydata(i) = mysearchstring then do something end if Next Thanks! Stephan.

      F Offline
      F Offline
      Fawxes
      wrote on last edited by
      #2

      Try UBound(mydata,1) An optimist's glass is half full. A pesimist's glass is half empty. An engineer goes and gets the right size glass.

      S 1 Reply Last reply
      0
      • F Fawxes

        Try UBound(mydata,1) An optimist's glass is half full. A pesimist's glass is half empty. An engineer goes and gets the right size glass.

        S Offline
        S Offline
        Stephan Wright
        wrote on last edited by
        #3

        thanks, it works! Stephan.

        1 Reply Last reply
        0
        • S Stephan Wright

          does anyone of you know how to get the length of a string array? My code looks like this mystring = ActiveDocument.Paragraphs(index) mydata = Split(mystring, " ") So in the beginning I do not know the size of the array. But I do need to know if the word I am searching for, is in this array. Therefor I have to parse the array to search it. But if I do not know the upper limit, this causes a "out of bounds" error. So I do need the upper limit to avoid the error to be thrown. Could anyone please tell me how to get the length so I could do the following (in VBA!) ? For i = 0 to upperlimit if mydata(i) = mysearchstring then do something end if Next Thanks! Stephan.

          S Offline
          S Offline
          Scott Serl
          wrote on last edited by
          #4

          There are at least 3 ways to do what you want: 1. As already mentioned, use ubound. ubound is a vb only feature and is convenient because it returns the upper bound of the array which is usefull for loops. 2. mydata.Length basically returns the count of array items. This available in any language of .net. It is less convenient for loops because you must subtract 1 from it. 3. For Each loop:

          For Each str As String In MyData
          'Do Something
          Next

          You don't have to know the array bounds to loop through the items.

          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