Link to home
Start Free TrialLog in
Avatar of metropia
metropiaFlag for United States of America

asked on

creating a counter with a for each loop

I need to pass a counter as an argument to a function within a for each loop in vb.net.

my loop:

For Each line In inFileContents.Split(arg, StringSplitOptions.None)
    Dim objFtpFileLine As New FtpFileLineClass()
    outStatusString = Upload_ToDatabase(FileId, LineNumer, line)
Next


The counter will be assigned to the variable LineNumber.

Any help would be nice.

Thank you.
SOLUTION
Avatar of Brendan M
Brendan M
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That's pretty close...more like:
        Dim lines() As String = inFileContents.Split(vbCrLf.ToCharArray, StringSplitOptions.RemoveEmptyEntries)
        For i As Integer = 0 To lines.Length - 1
            Dim objFtpFileLine As New FtpFileLineClass()
            outStatusString = objFtpFileLine.Upload_ToDatabase(FileId, i, lines(i))
        Next

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of metropia

ASKER

Thank you all for your help.

One small question.

I see that the first line to be read is zero element, how can that be altered, so that the first line read is 1?

Thank you
would it be to change:  For LineNumber As Integer = 0 To lines.Length - 1

To:  For LineNumber As Integer = 1 To lines.Length - 1
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial