First occurence in For Each statement

I've got a For Each statement written in visual studio using vb.  It takes a comma separated statement and runs something on each item separated by the commas.  I need to do something special with the first item.  How could I do this?
Who is Participating?
learning_t0_pr0gramConnect With a Mentor Commented:
you could use a boolean statement.

Dim SkipSpecial As Boolean

For Each .. ..
    If SkipSpecial = False Then
        'it is the first time here, run your special code
        SkipSpecial = True
        ' .. every other time, this code will run
    End If
Steve KrileCommented:
Another way to do this would be to use a String Array.  Something like this:

dim commastring as String = "thingone, thingtwo, thingthre, blaj"
dim StrArr() as String
StrArr = Split(commstring,",")    <---this creates a String Array using the comma in your original string to as a separator

Now, you can do whatever you'd like to the first thing by refering to it directly - outside of the context of a loop.

StrArr(0) (which in the example I've shown here would be equal to "thingone"

And to loop through your string array you could do:

dim i as Integer = 0
for i = 0 to ubound(StrArr)

schwientekdAuthor Commented:
Worked perfect.  Thanks for the quick response.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.