Teachers:
請問我如果在程式初需先輸入密碼然後才再做溫度轉換,如果我不用 inputbox 的方法,用輸入在文書盒判斷的方法,
我該如何做?以下是我的程式碼好像不行(在load呼叫副程式),請給我一點指教!
'--------------------------------------
'程式開始時,需先輸入密碼
'華氏溫度轉換為攝氏溫度
'攝氏溫度轉換為華氏溫度
'--------------------------------------
'-------------------------------------
' 物件名稱:cmdceltofah 事件名稱:click
'將攝氏溫度轉換為華氏溫度
'------------------------------------
Private Sub cmdceltofah_Click()
fah = (Val(txtcel.Text) * (9 / 5)) + 32
txtfah.Text = Str(fah)
End Sub
'-------------------------------------
' 物件名稱:cmdfahtocel 事件名稱:click
'將華氏溫度轉換為攝氏溫度
'------------------------------------
Private Sub cmdfahtocel_Click()
cel = (Val(txtfah.Text) - 32) * (5 / 9)
txtcel.Text = Str(cel)
End Sub
'-------------------------------------
' 物件名稱:form 事件名稱:load
'呼叫副程式txtpwd
'------------------------------------
Private Sub Form_Load()
Call txtpwd_KeyPress
End Sub
'-------------------------------------
' 物件名稱:txtcel 事件名稱:keypress
'攝氏溫度輸入限制在 0 ~9 or "."
'------------------------------------
Private Sub txtcel_KeyPress(KeyAscii As Integer)
If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
If KeyAscii <> Asc(".") Then
KeyAscii = 0
Beep
End If
End If
End Sub
'-------------------------------------
' 物件名稱:txtfah 事件名稱:keypress
'攝氏溫度輸入限制在 0 ~9 or "."
'------------------------------------
Private Sub txtfah_KeyPress(KeyAscii As Integer)
If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
If KeyAscii <> Asc(".") Then
KeyAscii = 0
Beep
End If
End If
End Sub
'-------------------------------------
' 物件名稱:txtpwd 事件名稱:keypress
'判斷密碼輸入
'------------------------------------
Private Sub txtpwd_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Label3.Visible = False
txtpwd.Text = False
If txtpwd.Text <> "0000" Then
Print "password error"
End
End If
MsgBox "welcome use this programe!", 48, "welcome"
End If
End Sub
請問我如果在程式初需先輸入密碼然後才再做溫度轉換,如果我不用 inputbox 的方法,用輸入在文書盒判斷的方法,
我該如何做?以下是我的程式碼好像不行(在load呼叫副程式),請給我一點指教!
'--------------------------------------
'程式開始時,需先輸入密碼
'華氏溫度轉換為攝氏溫度
'攝氏溫度轉換為華氏溫度
'--------------------------------------
'-------------------------------------
' 物件名稱:cmdceltofah 事件名稱:click
'將攝氏溫度轉換為華氏溫度
'------------------------------------
Private Sub cmdceltofah_Click()
fah = (Val(txtcel.Text) * (9 / 5)) + 32
txtfah.Text = Str(fah)
End Sub
'-------------------------------------
' 物件名稱:cmdfahtocel 事件名稱:click
'將華氏溫度轉換為攝氏溫度
'------------------------------------
Private Sub cmdfahtocel_Click()
cel = (Val(txtfah.Text) - 32) * (5 / 9)
txtcel.Text = Str(cel)
End Sub
'-------------------------------------
' 物件名稱:form 事件名稱:load
'呼叫副程式txtpwd
'------------------------------------
Private Sub Form_Load()
Call txtpwd_KeyPress
End Sub
'-------------------------------------
' 物件名稱:txtcel 事件名稱:keypress
'攝氏溫度輸入限制在 0 ~9 or "."
'------------------------------------
Private Sub txtcel_KeyPress(KeyAscii As Integer)
If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
If KeyAscii <> Asc(".") Then
KeyAscii = 0
Beep
End If
End If
End Sub
'-------------------------------------
' 物件名稱:txtfah 事件名稱:keypress
'攝氏溫度輸入限制在 0 ~9 or "."
'------------------------------------
Private Sub txtfah_KeyPress(KeyAscii As Integer)
If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
If KeyAscii <> Asc(".") Then
KeyAscii = 0
Beep
End If
End If
End Sub
'-------------------------------------
' 物件名稱:txtpwd 事件名稱:keypress
'判斷密碼輸入
'------------------------------------
Private Sub txtpwd_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Label3.Visible = False
txtpwd.Text = False
If txtpwd.Text <> "0000" Then
Print "password error"
End
End If
MsgBox "welcome use this programe!", 48, "welcome"
End If
End Sub
全站熱搜
留言列表