Public Class Form1
Dim sum As Integer
Private Sub a_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles a.Click
txtShow.Enabled = True
txtShow.Text = ""
txtSum.Text = ""
Dim i As Integer
Dim age(9) As Integer
sum = 0
For i = 0 To 9
age(i) = InputBox(" คุณกำลังป้อนอายุคนที่ " & i + 1, " ยินดีต้อนรับ ")
txtShow.Text = txtShow.Text & age(i) & vbCrLf
sum = sum + age(i)
Next i
End Sub
Private Sub b_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b.Click
txtSum.Text = sum
End Sub
Private Sub c_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles c.Click
Me.Close()
End Sub
End Class
Tag : .NET, VB.NET, VS 2005 (.NET 2.x), VS 2008 (.NET 3.x), VS 2010 (.NET 4.x)
แต่ผมลองเพิ่มโค้ดตามที่คุณ game บอกแล้ว แต่โปรแกรมมันก็ยังคำนวณเลขทั้ง คู่ & คี่ อยู่เลยคับ
Code (VB.NET)
Private Sub b_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b.Click
Dim i As Integer
Dim age(i) As Integer
txtSum.Text = sum
If age(i) Mod 2 = 0 Then
sum = sum + age(i)
End If
End Sub
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim a, sum As Integer
For i = 1 To 10
a = InputBox("กรุณากรอกอายุคนที่ " & i, "กรอกอายุ", "")
If a Mod 2 = 0 Then
sum = sum + a
End If
TextBox1.Text = sum
Next
End Sub