VB 6.0 講義 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
程式練習6: 計算匯率
步驟1. 依畫面擺上物件 (2個 文字框, 2 個標籤, 1個命令鈕, 1個框架, 2個選項鈕)
步驟2. 修改相關屬性
類別 | 預設物件名稱 | 屬性欄 | 屬性說明 | 屬性值 |
form(表單) | form1 | name | 表單名稱 | frmcalculator |
caption | 表單標題 | 計算匯率 | ||
label(標籤) | label1 | name | 標籤名稱 | lbl1 |
caption | 標籤外觀 | 美金 匯率 台幣 | ||
label(標籤) | label2 | name | 標籤名稱 | lblresult |
caption | 標籤外觀 | 清為空白 | ||
borderstyle | 標籤外框 | 1 | ||
textbox(文字框) | text1 | name | 文字框名稱 | txtno1 |
text | 文字框內容 | 清為空白 | ||
textbox(文字框) | text2 | name | 文字框名稱 | txtno2 |
text | 文字框內容 | 清為空白 | ||
CommandButton(命令鈕) | command1 | name | 命令鈕名稱 | cmdequal |
caption | 命令鈕內容 | = | ||
Frame(框架) | frame1 | name | 框架名稱 | frame1 |
OptionButton(選項鈕) | option1 | name | 選項鈕名稱 | opUsNt |
value | 選項鈕的值 | true | ||
caption | 選項鈕外觀 | 美金 -> 台幣 | ||
OptionButton(選項鈕) | option2 | name | 選項鈕名稱 | opNtUs |
caption | 選項鈕外觀 | 台幣 -> 美金 |
修改完後看一下畫面, 是否有所改變
步驟3. 撰寫程式碼
在 命令鈕 cmdequal 上雙按 , 寫入以下藍色的程式碼
Private Sub cmdequal_Click()
If opusnt.Value = True Then
lblresult.Caption = Val(txtno1.Text) * Val(txtno2.Text)
End If
If opntus.Value = True Then
lblresult.Caption = Val(txtno1.Text) / Val(txtno2.Text)
End If
End Sub
思考1: 能否改成2組? ( 一組:台幣 -> 美金 , 美金 -> 台幣) ( 另一組: 台幣 -> 人民幣 , 人民幣 -> 台幣)
思考2: 不用框架能否使用?