Variables 我试图重置计数器,一旦计数器达到10,我似乎不能得到它的权利。
一旦计数器达到10,它将显示“您的票是免费的”。我不知道如何重置计数器,以便再点击10次显示“您的票是免费的”Variables 我试图重置计数器,一旦计数器达到10,我似乎不能得到它的权利。,variables,counter,Variables,Counter,一旦计数器达到10,它将显示“您的票是免费的”。我不知道如何重置计数器,以便再点击10次显示“您的票是免费的” 这看起来像一个Vb窗体应用程序。我认为您只需要在您的条件下重置intCounter,如下所示: Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click Dim intTicketPrice As Integer = Val(Me.txtTicketNu
这看起来像一个Vb窗体应用程序。我认为您只需要在您的条件下重置intCounter,如下所示:
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!!!"
intCounter = 0
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
输出文本后,您应该能够在if语句中添加
intCounter=0
。因此:
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
或者,您可以在不重置计数器的情况下通过,而是在计数器上执行模数运算-
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
可能您今天对.Net的期望过高:)您没有在代码中将计数器设置为0
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!!!"
intCounter = 0
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
这与我之前的回答有什么不同?@geedubb这是一个明显的问题,我认为我们两人同时回答了这个问题。
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!!!"
intCounter = 0
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