Page 97 -
P. 97
範例一:英文單字練習系統。 第五章 陣列與排序
(一)表單物件說明
物件樣式
物件名稱 屬性
Form1 Text=”單字練習系統”
Label1 Text=”中文:”
Label2 Font=14pt
Text=”請輸入英文:”
Label3
Font=14pt
TextBox1 Text=””;Font=14pt
TextBox2 AutoSize=False
Button1 TextAlign=MiddleCenter
Button2 Text=””;Font=14pt
BackColor=Coral
Text=””;Font=14pt
Text=”請出題”;Font=14pt
Text=”批改”;Font=14pt
(二)程式碼
Public Class Form1
Dim voc(,) As String = {{"車", "car"}, {"貓", "cat"}, {"書桌", "desk"}, {"_
巴士", "bus"}, {"頭", "head"}}
Dim n As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Randomize()
n = Int(Rnd() * 5)
TextBox1.Text = voc(n, 0)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
If TextBox2.Text = voc(n, 1) Then
Label3.BackColor = Color.LightBlue
Label3.Text = "答對了,你好棒!"
Else
Label3.BackColor = Color.LightCoral
Label3.Text = "答錯了,再加油!"
End If
End Sub
End Class
93