Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

incrementing values

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0

In my program I have a variable named Counter which has a value of 0 to 7, I need help in writing code which increments the value of counter by 1 each time the sub procedure is run and which resets Counter to 0 when Counter exceeds 7. Thanks for your help! Lee
 
This is pretty easy (you'll be surprised at how easy it is!)
[tt]
Counter = Counter + 1
If Counter > 7 Then
Counter = 0
End If
[/tt]
You'd want to put the call to your subroutine in the correct place, depending on whether you want to call the sub before or after Counter gets incremented.

Chip H.

 
Here you go . . .

Code:
public sub Mysub()

    '** counter is a module level variable
    Counter = Counter +1 
    if Counter > 7 then
        Counter = 0
    end if

end sub
- Jeff Marler B-)
 
OK Chip . . . so you can type faster than I can . . . ;-) - Jeff Marler B-)
 
Lee -
Glad we could be of help.

Jeff -
What can I say? I was stuck at home on a beautiful Saturday afternoon with a cold. So, I came here!

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top