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. Looping through a string array

Looping through a string array

Scheduled Pinned Locked Moved Visual Basic
data-structurestutorialquestionannouncement
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.
  • J Offline
    J Offline
    j45mw
    wrote on last edited by
    #1

    Can someone tell me how to loop through a string array using a FOR..NEXT or DO UNTIL loop? Public Sub Update(ByVal Product_Category As String, ByVal Percentage As Decimal, ByVal ParamArray Location_Codes() As String) End sub The above is my subroutine and I want to loop through the ParamArray Location_Codes(). So that I can then run some additional code for each item in that array. Kinda like this: For each XXXX in Location_codes() Make some decisions Next Can this be done? Thanks

    D M 2 Replies Last reply
    0
    • J j45mw

      Can someone tell me how to loop through a string array using a FOR..NEXT or DO UNTIL loop? Public Sub Update(ByVal Product_Category As String, ByVal Percentage As Decimal, ByVal ParamArray Location_Codes() As String) End sub The above is my subroutine and I want to loop through the ParamArray Location_Codes(). So that I can then run some additional code for each item in that array. Kinda like this: For each XXXX in Location_codes() Make some decisions Next Can this be done? Thanks

      D Offline
      D Offline
      Dave Doknjas
      wrote on last edited by
      #2

      You can loop through using the Chars method: Dim thisstring As String = "abc" For i As Integer = 0 To thisstring.Length MsgBox(thisstring.Chars(i)) Next In VB 2005, you can omit the ".Chars": For i As Integer = 0 To thisstring.Length MsgBox(thisstring(i)) Next David Anton www.tangiblesoftwaresolutions.com Instant C#: VB.NET to C# Converter Instant VB: C# to VB.NET Converter Instant C++: C# to C++ Converter Instant J#: VB.NET to J# Converter Clear VB: Cleans up outdated VB.NET code

      D 1 Reply Last reply
      0
      • D Dave Doknjas

        You can loop through using the Chars method: Dim thisstring As String = "abc" For i As Integer = 0 To thisstring.Length MsgBox(thisstring.Chars(i)) Next In VB 2005, you can omit the ".Chars": For i As Integer = 0 To thisstring.Length MsgBox(thisstring(i)) Next David Anton www.tangiblesoftwaresolutions.com Instant C#: VB.NET to C# Converter Instant VB: C# to VB.NET Converter Instant C++: C# to C++ Converter Instant J#: VB.NET to J# Converter Clear VB: Cleans up outdated VB.NET code

        D Offline
        D Offline
        Dave Doknjas
        wrote on last edited by
        #3

        Ack - that should be "thisstring.Length - 1" of course. David Anton www.tangiblesoftwaresolutions.com Instant C#: VB.NET to C# Converter Instant VB: C# to VB.NET Converter Instant C++: C# to C++ Converter Instant J#: VB.NET to J# Converter Clear VB: Cleans up outdated VB.NET code

        1 Reply Last reply
        0
        • J j45mw

          Can someone tell me how to loop through a string array using a FOR..NEXT or DO UNTIL loop? Public Sub Update(ByVal Product_Category As String, ByVal Percentage As Decimal, ByVal ParamArray Location_Codes() As String) End sub The above is my subroutine and I want to loop through the ParamArray Location_Codes(). So that I can then run some additional code for each item in that array. Kinda like this: For each XXXX in Location_codes() Make some decisions Next Can this be done? Thanks

          M Offline
          M Offline
          Marc 0
          wrote on last edited by
          #4

          Public Sub Update(ByVal Product_Category As String, ByVal Percentage As Decimal, ByVal ParamArray Location_Codes() As String) For Each **_code_ As String** In Location_codes() 'Make some decisions Next End sub You may have to do some error checking first, to see if Location_Codes is not nothing or empty. Merry Christmas! :jig:


          "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick

          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