close
迴圈程式碼
Private Sub B1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles B1.Click
Dim a, b, c, d, all
a = CInt(T1.Text) '初始值
b = CInt(T2.Text) '終止值
c = CInt(T3.Text) '遞增值
For all = a To b Step c
d = d + all
T5.Text = T5.Text & all & "+"
Next
T4.Text = d
End Sub
Private Sub B2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles B2.Click
Dim a, b, c, d, all
a = CInt(T1.Text) '初始值
b = CInt(T2.Text) '終止值
c = CInt(T3.Text) '遞增值
all = a
T5.Text = ""
If c > 0 Then
Do While all <= b
d = d + all
T5.Text = T5.Text & all
If all + c > b Then
T5.Text = T5.Text & "="
Else
T5.Text = T5.Text & "+"
End If
all = all + c
Loop
T4.Text = d
Else
Do While all >= b
d = d + all
T5.Text = T5.Text & all
If all + c < b Then
T5.Text = T5.Text & "="
Else
T5.Text = T5.Text & "+"
End If
all = all + c
Loop
T4.Text = d
End If
End Sub
Private Sub B3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles B3.Click
Dim a, b, c, d, all
a = CInt(T1.Text) '初始值
b = CInt(T2.Text) '終止值
c = CInt(T3.Text) '遞增值
all = a
T5.Text = ""
If c > 0 Then
Do Until all > b
d = d + all
T5.Text = T5.Text & all
If all + c > b Then
T5.Text = T5.Text & "="
Else
T5.Text = T5.Text & "+"
End If
all = all + c
Loop
T4.Text = d
Else
Do Until all < b
d = d + all
T5.Text = T5.Text & all
If all + c < b Then
T5.Text = T5.Text & "="
Else
T5.Text = T5.Text & "+"
End If
all = all + c
Loop
T4.Text = d
End If
End Sub
Private Sub B4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles B4.Click
Dim a, b, c, d, all
a = CInt(T1.Text) '初始值
b = CInt(T2.Text) '終止值
c = CInt(T3.Text) '遞增值
all = a
T5.Text = ""
If c > 0 Then
Do
d = d + all
T5.Text = T5.Text & all
If all + c > b Then
T5.Text = T5.Text & "="
Else
T5.Text = T5.Text & "+"
End If
all = all + c
Loop While all <= b
T4.Text = d
Else
Do
d = d + all
T5.Text = T5.Text & all
If all + c < b Then
T5.Text = T5.Text & "="
Else
T5.Text = T5.Text & "+"
End If
all = all + c
Loop While all >= b
T4.Text = d
End If
End Sub
Private Sub B5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles B5.Click
Dim a, b, c, d, all
a = CInt(T1.Text) '初始值
b = CInt(T2.Text) '終止值
c = CInt(T3.Text) '遞增值
all = a
T5.Text = ""
If c > 0 Then
Do
d = d + all
T5.Text = T5.Text & all
If all + c > b Then
T5.Text = T5.Text & "="
Else
T5.Text = T5.Text & "+"
End If
all = all + c
Loop Until all > b
T4.Text = d
Else
Do
d = d + all
T5.Text = T5.Text & all
If all + c < b Then
T5.Text = T5.Text & "="
Else
T5.Text = T5.Text & "+"
End If
all = all + c
Loop Until all < b
T4.Text = d
End If
End Sub
End Class
全站熱搜