In programming we often need to Count. To count we must
To count how many times we click a button
Dim intCount As Integer
Private Sub btnCount_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnCount.Click intCount = intCount + 1
End Sub
Private Sub btnReportCount_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnReportCount.Click MsgBox("Button clicked " & intCount & " times")
End Sub
The pattern for the statement used to count is
A = A + 1 (where A is an integer variable)
We also often have to Accumulate. That is - we have to add up a series of values. To accumulate we must
To add up values entered in a TextBox
Dim decSumPrice As Decimal
Private Sub btnAddEmUp_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnAddEmUp.Click
Dim decPrice As Decimal
If IsNumeric(txtPrice.Text) Then
decPrice = Convert.ToDecimal(txtPrice.Text) decSumPrice = decSumPrice + decPrice
End If End Sub
Private Sub btnReportSum_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnReportSum.Click
MsgBox("Sum of numbers entered " & decSumPrice) End Sub
The pattern for the statement used to add up a series of values is
A = A + B (where A is the accumulator variable and B
contains the value you want
to add up.)