VB 6.0 講義 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
程式練習8: 配對程式
設計一個程式, 用來做交友配對
戴眼鏡, 長髮, 廋
( 回答 A,B,C,D,E,F,G,H 小姐 - 8 種變化)
步驟1. 依畫面擺上物件 (3 個標籤, 1個命令鈕, 3個核取方塊)
步驟2. 修改相關屬性
類別 | 預設物件名稱 | 屬性欄 | 屬性說明 | 屬性值 |
form(表單) | form1 | name | 表單名稱 | frmbestgirl |
caption | 表單標題 | 交友配對 | ||
label(標籤) | label1 | name | 標籤名稱 | lbl1 |
caption | 標籤外觀 | 清為空白 | ||
borderstyle | 標籤外框 | 1 | ||
CommandButton(命令鈕) | command1 | name | 命令鈕名稱 | cmdresult |
caption | 命令鈕內容 | 配對結果 | ||
Check box(核取方塊) | check1 | name | 核取方塊名稱 | ck1 |
value | 核取方塊的值 | 1 | ||
caption | 核取方塊外觀 | 戴眼鏡 | ||
Check box(核取方塊) | check2 | name | 核取方塊名稱 | ck2 |
caption | 核取方塊外觀 | 長髮 | ||
Check box(核取方塊) | check3 | name | 核取方塊名稱 | ck3 |
caption | 核取方塊外觀 | 廋 |
修改完後看一下畫面, 是否有所改變
步驟3. 撰寫程式碼
在 命令鈕 cmdequal 上雙按 , 寫入以下藍色的程式碼
Private Sub cmdequal_Click()
上課講解
End Sub
思考1: 能否改成3個 label 來形容 上一題的特色 ? (利用 label.visible )( oo , . . , \ \ , | |, < > , | |)
思考2: 能否不用命令鈕?
上課講解:
If ck1.Value = 1 and ck2.Value = 1 and
ck3.Value = 1 Then
lbl1.Caption = "適合A小姐"
End If
If ck1.Value = 0 and ck2.Value = 0 and ck3.Value = 0 Then
lbl1.Caption = "適合B小姐"
End If
If ck1.Value = 0 and ck2.Value = 1 and ck3.Value = 1 Then
lbl1.Caption = "適合C小姐"
End If
If ck1.Value = 1 and ck2.Value = 0 and ck3.Value = 1 Then
lbl1.Caption = "適合D小姐"
End If
If ck1.Value = 1 and ck2.Value = 1 and ck3.Value = 0 Then
lbl1.Caption = "適合E小姐"
End If
If ck1.Value = 1 and ck2.Value = 0 and ck3.Value = 0 Then
lbl1.Caption = "適合F小姐"
End If
If ck1.Value = 0 and ck2.Value = 1 and ck3.Value = 0 Then
lbl1.Caption = "適合G小姐"
End If
If ck1.Value = 0 and ck2.Value = 0 and ck3.Value = 1 Then
lbl1.Caption = "適合H小姐"
End If
If ck1.value = 0 then
If ck2.value = 0 then
If ck3.value = 0 then
lbl1.Caption = "適合A小姐"
else
lbl1.Caption = "適合B小姐"
end if
else
If ck3.value = 0 then
lbl1.Caption = "適合C小姐"
else
lbl1.Caption = "適合D小姐"
end if
end if
Else
If ck2.value = 0 then
If ck3.value = 0 then
lbl1.Caption = "適合E小姐"
else
lbl1.Caption = "適合F小姐"
end if
If ck2.value = 0 then
If ck3.value = 0 then
lbl1.Caption = "適合G小姐"
else
lbl1.Caption = "適合H小姐"
end if
end if
End if
a = ck1.Value + ck2.Value * 2 +ck3.Value * 4
Select Case a
Case 0
lbl1.Caption = "適合A小姐"
Case 1
lbl1.Caption = "適合B小姐"
Case 2
lbl1.Caption = "適合C小姐"
Case 3
lbl1.Caption = "適合D小姐"
Case 4
lbl1.Caption = "適合E小姐"
Case 5
lbl1.Caption = "適合F小姐"
Case 6
lbl1.Caption = "適合G小姐"
Case 7
lbl1.Caption = "適合H小姐"
End Select
思考1: 能否改成3個 label 來形容 上一題的特色 ? (利用 label.visible )( oo , . . , \ \ , | |, < > , | |)
If Ck1.Value = 1 Then
Label1.Caption = " OO"
Else
Label1.Caption = " 。。"
End If
If Ck2.Value = 1 Then
Label2.Caption = " |||"
Else
Label2.Caption = " +++"
End If
If Ck3.Value = 1 Then
Label3.Caption = " | |"
Else
Label3.Caption = " < >"
End If