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