代码如下:
Option Explicit
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 Command1_Click()
If Trim(Text1.Text) = "" Then Text1.Text = "0"
Label3.Caption = TransTh(Val(Text1.Text), True)
Label4.Caption = "摄氏度"
Label5.Caption = "华氏度"
If blnCtoF Then
TransTh = Format(sngT * 9 / 5 + 32, "0.#")
Else
TransTh = Format((sngT - 32) * 5 / 9, "0.#")
End If
End Function
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
If Trim(Text1.Text) = "" Then Text1.Text = "0"
Label3.Caption = TransTh(Val(Text1.Text), False)
Label4.Caption = "华氏度"
Label5.Caption = "摄氏度"
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 Then
KeyAscii = 0
End If
KeyAscii = 0
End If
End Sub