We help IT Professionals succeed at work.

start at 0

I have a count that starts at 1 and I need it to start at 0.

Dim cnt As Integer = 0

inside a reader (( Do While ))
cnt = cnt + 1
tb.ID = quantity" + cnt.ToString()

how can I get it to start at 0
Comment
Watch Question

Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009

Commented:
put the cnt = cnt +1 at the end of the tool, or do:

Dim cnt As Integer = -1
You are intializing the  cnt variable at 0 ... do u want cnt to be 0 in the first loop of the while to show the quantity ? well.. showing before adding 1 is an option...

tb.ID = quantity" + cnt.ToString()
cnt = cnt + 1

Open in new window



another option is to use a Do While and not a While statement.

Do
       tb.ID = quantity" + cnt.ToString()
       ' more code here...
Loop While <condition>

Open in new window


and another option is to ask if this is the first time in the loop

Dim firstTime As Boolean

firstTime = True

Do While <condition>

if firstTime Then
    cnt = 0;
Else
     cnt = cnt + 1
EndIf

tb.ID = quantity" + cnt.ToString()

Open in new window


I don't know if the syntaxis is good since i don't really use Visual Basic.. but you can get the idea.

in the firstTime if... set firstTime = False;  
Seven priceFull Stack

Author

Commented:
this worked

tb.ID = quantity" + cnt.ToString()
cnt = cnt + 1