Nested if statement help

clowns119

Member
Joined
Feb 17, 2005
Messages
8
Programming Experience
1-3
Hi all,
I am having a problom that i am unable to solve, hopefully someone can point me in the reight direction. I have a loop that is going from 1 to an unknown number stured in a variable called NumberOfLines. I need to use an if statement because if the output is anegitive number then it needs to be converted to a positive number. If I use a number value in the item.() area it works, but that number will not be known so I wanted it to run the if statement for as many times as the for loop says, i am trying to use the counter in the item.() ere but i get an error. anyone know why and or what to do to make it work. I just want the if loop to run for each LNCount.

here is the code
VB.NET:
 [size=2]
[/size][size=2][color=#0000ff]For[/color][/size][size=2] x = 1 [/size][size=2][color=#0000ff]To[/color][/size][size=2] 11

TabDataGrid(x, 0) = TS.MainCollections.Item(0).Groups(x).Value

[/size][size=2][color=#0000ff]For[/color][/size][size=2] LNCount = 1 [/size][size=2][color=#0000ff]To[/color][/size][size=2] NumberOfLines

[/size][size=2][color=#0000ff]If[/color][/size][size=2] (TabDataGrid(2, 0) - TS.MainCollections.Item(LNCount).Groups(2).Value) < 0 [/size][size=2][color=#0000ff]Then

[/color][/size][size=2]y = Abs(TabDataGrid(2, 0) - TS.MainCollections.Item(LNCount).Groups(2).Value)

[/size][size=2][color=#0000ff]Else[/color][/size][size=2] : y = (Abs((TabDataGrid(2, 0) - TS.MainCollections.Item(LNCount).Groups(2).Value) - 24))

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If

[/color][/size][size=2][/size][size=2][color=#0000ff]Next

[/color][/size][size=2]TabDataGrid(x, y) = TS.MainCollections.Item(LNCount).Groups(x).Value

[/size][size=2][color=#0000ff]Next

[/color][/size]
 
Be aware that arrays and collections are zero-based. This means that an array with N elements goes from index 0 to index (N - 1), and the same for collections. Given that your For loops both start at 1, I'm guessing that that is your problem.

Also, please don't post "I get an error" without posting what the error was and where it occurred.
 
Back
Top