Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Looping a Split Array

Posted on 2004-10-26
9
Medium Priority
?
1,117 Views
Last Modified: 2010-04-24
I need the proper code to loop a Split Array

        Dim BSplit
        BSplit = Microsoft.VisualBasic.Split(Testing the Split, " ")

I want to split the above then loop through the array 0 1 etc.
Could someone help me out with this.
0
Comment
Question by:DTRON04
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 

Expert Comment

by:1209
ID: 12412074
       Dim BSplit() as string
        BSplit = Microsoft.VisualBasic.Split(Testing the Split, " ")
0
 

Expert Comment

by:1209
ID: 12412093
discard the previous one....
        Dim BSplit
        BSplit = Microsoft.VisualBasic.Split(Testing the Split, " ")
for j as inetegr= 0 to upperbond(bsplit)
next
0
 

Author Comment

by:DTRON04
ID: 12412168
Dim BSplit      
 BSplit = Microsoft.VisualBasic.Split(BName, " ")
        For j = 0 To Upperbound(BSplit)
            BClean = BClean + "+" + BSplit(j)
        Next

This code tells me upperbound has to be declared

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Assisted Solution

by:1209
1209 earned 400 total points
ID: 12412231
use this..I guess this would solve the problem

dim BSplit() as string
 BSplit = Microsoft.VisualBasic.Split(BName, " ")
        For j = 0 To Microsoft.VisualBasic.Upperbound(BSplit)
            BClean = BClean + "+" + BSplit(j)
        Next
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1200 total points
ID: 12412320
There are two basic ways to iterate though an array...either by Index or with a For Each loop:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer
        Dim value As String
        Dim values() As String

        values = Split("Testing the Split", " ")

        ' First method
        For i = 0 To values.GetUpperBound(0)
            Debug.WriteLine(values(i))
        Next

        ' Second method
        For Each value In values
            Debug.WriteLine(value)
        Next
    End Sub

~IM
0
 
LVL 6

Expert Comment

by:KGreg
ID: 12413010
I agree with idle mind, however I just wanted to add a quick note about performance and the For Each loop..  When you use a For Each loop, an Enumerator object is created behind the scenes.  For this reason, you should avoid For Each, and use the For loop indexing method (ie.  For i = 0 to n  etc.) when complexity/performance is a concern

KGREG
0
 

Expert Comment

by:1209
ID: 12413235
i was mentioning it wrong...its UBound and not upperbound....
0
 
LVL 2

Assisted Solution

by:AmanBrar
AmanBrar earned 400 total points
ID: 12418659
Hi,
try using this:

 Dim BSplit
 BSplit = Microsoft.VisualBasic.Split(Testing the Split, " ")

 For n=0 To (BSplit.length() -1)
    Debug.WriteLine( BSplit(n) )
 Next

hope this helps.
0
 

Author Comment

by:DTRON04
ID: 12427222
thanks guys
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question