第五章 P58挑戰題答案


Public Class Form1
'全域變數
Dim i, j As Integer
Dim output As String

'一字形
Private Sub Rdb_shape1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Rdb_shape1.CheckedChanged
output = ""
For i = 1 To 10
 output = output & "*"
Next
TextBox1.Text = output

End Sub
'四方形
Private Sub Rdb_shape2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Rdb_shape2.CheckedChanged
output = ""
For i = 1 To 10
 For j = 1 To 10
  output = output & "*"
 Next j
 output = output & vbNewLine
Next i
TextBox1.Text = output
End Sub
'三角形
Private Sub Rdb_shape3_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Rdb_shape3.CheckedChanged
output = ""
For i = 1 To 10
 For j = 1 To i
  output = output & "*"
 Next j
 output = output & vbNewLine
Next i
TextBox1.Text = output
End Sub

'倒三角形
Private Sub Rdb_shape4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Rdb_shape4.CheckedChanged
output = ""
For i = 10 To 1 Step -1
 For j = 1 To i
  output = output & "*"
 Next j
 output = output & vbNewLine
Next i
TextBox1.Text = output
End Sub

'正三角形
Private Sub Rdb_shape5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Rdb_shape5.CheckedChanged
Dim k, numofstars As Integer
output = ""
numofstars = 1
For i = 1 To 19 Step 2
 For j = 19 To i Step -2
  output = output & " "
 Next j

 For
k = 1 To numofstars
  output = output & "*"
 Next k
 numofstars = numofstars + 2
 output = output & vbNewLine
Next i
TextBox1.Text = output
End Sub

'結束
Private Sub Bt_end_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt_end.Click
 End
End Sub

End Class

留言