I try to reset a counter once the counter hits 10 and I can not do it well.

advertisements

Once the counter hits 10, it displays "your tickets are free". I can't figure out how to reset the counter so that another 10 clicks will display "your tickets are free"

Public Class Form1
Dim intCounter As Integer

Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
    Dim intTicketPrice As Integer = Val(Me.txtTicketNum.Text) * 8
    intCounter = intCounter + 1

    If intCounter = 10 Then
        Me.lblFeed.Text = "Your tickets are free!!!"

    ElseIf intTicketPrice Then
        Me.lblFeed.Text = "Your tickets cost: " & intTicketPrice & " Dollars"
    End If
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    intCounter = 0
End Sub

End Class


You should be able to just add intCounter = 0 inside of your if statement, after you output your text. So:

If intCounter = 10 Then
    Me.lblFeed.Text = "Your tickets are free!!!"
    intCounter = 0
ElseIf intTicketPrice Then
    Me.lblFeed.Text = "Your tickets cost: " & intTicketPrice & " Dollars"
End If

Alternately, you can get by without ever resetting the counter and instead perform a modulus operation on the counter -

If (intCounter % 10) = 0 Then
    Me.lblFeed.Text = "Your tickets are free!!!"
ElseIf intTicketPrice Then
    Me.lblFeed.Text = "Your tickets cost: " & intTicketPrice & " Dollars"
End If