我有一个需要用户提供两个整数的 Visual Basic 程序。
我需要能够显示用户输入的两个整数之间的偶数之和。如果用户的输入是偶数,它应该包含在总和中。
我无法弄清楚算法。
这是我的代码:
Public Class frmMain
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub txtFirstNum_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtFirstNum.KeyPress
' allows the text box to accept only numbers, and the Backspace key
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso
e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub txtSecondNum_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtSecondNum.KeyPress
' allows numbers and Backspace only
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso
e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
' display the sum of even numbers
' declarations
Dim intFirstNum As Integer
Dim intSecondNum As Integer
' convert string to number with TryParse method
Integer.TryParse(txtFirstNum.Text, intFirstNum)
Integer.TryParse(txtSecondNum.Text, intSecondNum)
' find the even numbers
If intFirstNum Mod 2 = 0 Then
ElseIf intFirstNum Mod 2 = 1 Then
End If
' add the even numbers
' display the result
End Sub
End Class
我怎样才能解决这个问题?