2

カウンターが 10 になると、「あなたのチケットは無料です」と表示されます。さらに10回クリックすると「チケットは無料です」と表示されるようにカウンターをリセットする方法がわかりません

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
4

3 に答える 3

1

intCounter = 0テキストを出力した後、if ステートメント内に追加するだけでよいはずです。そう:

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
于 2013-10-08T19:46:33.183 に答える
1

今日の .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
于 2013-10-08T19:46:49.293 に答える
0

これは、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
于 2013-10-08T19:45:16.497 に答える