Public Class Form1 Private Sub clearBtn_Click(ByVal sender As System.Object, ByV
ID: 3927310 • Letter: P
Question
Public Class Form1
Private Sub clearBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearBtn.Click
'cleat the input and result
inputTxt.Text = ""
resultLabel.Text = ""
End Sub
'close the form
Private Sub exitBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitBtn.Click
'close the application
Me.Close()
End Sub
'Double click on the calculat button and write the following code
Private Sub cntBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cntBtn.Click
'Set the following variables to zero
Dim count As Integer = 0
Dim value As Integer = 0
Dim index As Integer = 0
If CInt(inputTxt.Text) > 1000 Then
textBox.Text = "Please Enter a 3 Digit Number"
'set focus to inputtext
inputTxt.Focus()
Else
'get input text and convert to integer
value = Convert.ToInt32(inputTxt.Text)
For index = 1 To value
If index Mod 2 = 0 Then
count = count + 1
End If
Next
resultLabel.Text = "This number contains " + CStr(count) + " even digits"
End If
End Sub
End Class
Explanation / Answer
Public Class Form1
Private Sub clearBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearBtn.Click
'cleat the input and result
inputTxt.Text = ""
resultLabel.Text = ""
End Sub
'close the form
Private Sub exitBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitBtn.Click
'close the application
Me.Close()
End Sub
'Double click on the calculat button and write the following code
Private Sub cntBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cntBtn.Click
'Set the following variables to zero
Dim count As Integer = 0
Dim value As Integer = 0
Dim index As Integer = 0
If CInt(inputTxt.Text) > 1000 Then
textBox.Text = "Please Enter a 3 Digit Number"
'set focus to inputtext
inputTxt.Focus()
Else
'get input text and convert to integer
value = Convert.ToInt32(inputTxt.Text)
For index = 1 To value
If index Mod 2 = 0 Then
count = count + 1
End If
Next
resultLabel.Text = "This number contains " + CStr(count) + " even digits"
End If
End Sub
End Class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.