請vb的高手們,看一下這個程式碼是否能在精簡
或是有另一種寫法...
因為我是個高中生對程式的蓋概念還不是很好請各位高手幫幫忙!!
(這個程式是電阻值測驗程式)
Dim a
Dim b
Dim c
Dim d
Dim aa
Dim bb
Dim cc
Dim dd, qq, ert
Dim er$, tt$, tt1$
Private Sub Command1_Click()
For i = 0 To 2
Text1(i).Text = ""
Next i
Randomize
123
a = Int(Rnd * 10)
b = Int(Rnd * 10)
c = Int(Rnd * 12)
d = Int(Rnd * 3)
aa = 0
bb = 0
cc = 0
dd = 0
'第一個色碼不能為黑色
If a = 0 Then
GoTo 123
End If
'執行隨機頻色副程式
aaa
bbb
ccc
ddd
'答案
If c = 0 Then
tt$ = aa & bb & cc
wer = tt$
Text3(0).Text = wer & er$
wer1 = wer / 10 ^ 3
Text3(1).Text = wer1 & er$
wer2 = wer / 10 ^ 6
Text3(2).Text = wer2 & er$
Else
tt1$ = aa & bb
tt$ = tt1$ * cc
wer = tt$
Text3(0).Text = wer & er$
wer1 = wer / 10 ^ 3
Text3(1).Text = wer1 & er$
wer2 = wer / 10 ^ 6
Text3(2).Text = wer2 & er$
End If
End Sub
Private Sub Command2_Click()
Beep
Unload Me
End Sub
Private Sub Command3_Click()
qq = qq + 1
If Text1(0) = "" And Text1(1) = "" And Text1(2) = "" Then
MsgBox ("抱歉您還沒輸入電阻數值!!")
Else
If qq = 10 Then
MsgBox ("色碼電阻測驗試題測驗結束!!")
Command1.Enabled = False
Label3.Caption = ert * 10 & " 分"
End If
If Text1(Index).Text = Text3(Index).Text Then
MsgBox ("恭喜您答對了!!")
Text1(Index) = ""
Text3(Index) = ""
ert = ert + 1
Label4.Caption = " " & ert
Else
If Text1(Index).Text <> Text3(Index).Text Then
MsgBox ("抱歉您答錯了!!")
Text1(Index) = ""
Text3(Index) = ""
End If
End If
End If
End Sub
Private Sub Form_Load()
a = 0
b = 0
c = 0
aa = 0
bb = 0
cc = 0
dd = 0
d = 0
er$ = 0
qq = 0
ert = 0
End Sub
Public Sub aaa()
Select Case a
Case 0
'黑
Picture1.BackColor = 0
Case 1
'棕
Picture1.BackColor = RGB(128, 64, 0)
aa = 1
Case 2
'紅
Picture1.BackColor = RGB(255, 0, 0)
aa = 2
Case 3
'橙
Picture1.BackColor = RGB(255, 128, 0)
aa = 3
Case 4
'黃
Picture1.BackColor = RGB(255, 255, 0)
aa = 4
Case 5
'綠
Picture1.BackColor = RGB(0, 255, 0)
aa = 5
Case 6
'藍
Picture1.BackColor = RGB(0, 0, 255)
aa = 6
Case 7
'紫
Picture1.BackColor = RGB(128, 0, 128)
aa = 7
Case 8
'灰
Picture1.BackColor = RGB(128, 128, 128)
aa = 8
Case 9
'白
Picture1.BackColor = RGB(255, 255, 255)
aa = 9
End Select
End Sub
Public Sub bbb()
Select Case b
Case 0
'黑
Picture2.BackColor = 0
bb = 0
Case 1
'棕
Picture2.BackColor = RGB(128, 64, 0)
bb = 1
Case 2
'紅
Picture2.BackColor = RGB(255, 0, 0)
bb = 2
Case 3
'橙
Picture2.BackColor = RGB(255, 128, 0)
bb = 3
Case 4
'黃
Picture2.BackColor = RGB(255, 255, 0)
bb = 4
Case 5
'綠
Picture2.BackColor = RGB(0, 255, 0)
bb = 5
Case 6
'藍
Picture2.BackColor = RGB(0, 0, 255)
bb = 6
Case 7
'紫
Picture2.BackColor = RGB(128, 0, 128)
bb = 7
Case 8
'灰
Picture2.BackColor = RGB(128, 128, 128)
bb = 8
Case 9
'白
Picture2.BackColor = RGB(255, 255, 255)
bb = 9
End Select
End Sub
Public Sub ccc()
Select Case c
Case 0
'黑
Picture3.BackColor = 0
cc = 0
Case 1
'棕
Picture3.BackColor = RGB(128, 64, 0)
cc = 10
Case 2
'紅
Picture3.BackColor = RGB(255, 0, 0)
cc = 10 ^ 2
Case 3
'橙
Picture3.BackColor = RGB(255, 128, 0)
cc = 10 ^ 3
Case 4
'黃
Picture3.BackColor = RGB(255, 255, 0)
cc = 10 ^ 4
Case 5
'綠
Picture3.BackColor = RGB(255, 0, 0)
cc = 10 ^ 5
Case 6
'藍
Picture3.BackColor = RGB(0, 255, 0)
cc = 10 ^ 6
Case 7
'紫
Picture3.BackColor = RGB(128, 0, 128)
cc = 10 ^ 7
Case 8
'灰
Picture3.BackColor = RGB(128, 128, 128)
cc = 10 ^ 8
Case 9
'白
Picture3.BackColor = RGB(255, 255, 255)
cc = 10 ^ 9
Case 10
'金
Picture3.BackColor = RGB(225, 225, 202)
cc = 10 ^ -1
Case 11
'銀
Picture3.BackColor = RGB(242, 242, 242)
cc = 10 ^ -2
End Select
End Sub
Public Sub ddd()
Select Case d
Case 0
'金
Picture4.BackColor = RGB(225, 225, 202)
er$ = "+-5%"
Case 1
'銀
Picture4.BackColor = RGB(242, 242, 242)
er$ = "+-10%"
Case 2
'無
Picture4.BackColor = RGB(255, 255, 255)
er$ = "+-20%"
End Select
End Sub