Private Sub Command1_Click()
If Trim(Text1.Text) = "" Then Text1.Text = "0"
'调用自定义函数
Label3.Caption = transth(Val(Text1.Text).true)
Label4.Caption = "摄氏度"
Label5.Caption = "华氏度"
End Sub
Private Sub command2_click()
If Trim(Text1.Text) = "" Then Text1.Text = "0"
'调用自定义函数
Label3.Caption = transth(Val(Text1.Text).false)
Label4.Caption = "华氏度"
Label5.Caption = "摄氏度"
End Sub
Private Function transth(sngT As Single, blnCtoF As Boolean) As String
If blnCtoF Then
transth = Format(sngT * 9 / 5 + 32, "0.#")
Else
transth = Format((sngT - 32) * 5 / 9, "0.#")
End If
End Function
Private Sub text1_keypress(keyascii As Integer) '文本框键盘事件过程
'若按键非数字或回删键,取消按键
If Not IsNumeric(Chr(keyascii)) And keyascii <> 8 Then
keyascii = 0
End If
End Sub
End Sub