Option Explicit
Private Sub Command1_Click()
IfTrim(Text1.Text) = "" Then Text1.Text = "0"
Label3.Caption = transth(Val(Text1.Text), True)
Label4.Caption = "摄氏度"
Label5.Caption = "华氏度"
End Sub
Private Sub Command2_Click()
IfTrim(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
Ifblnctof 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 AsInteger)
IfNot IsNumeric(Chr(keyascii)) And keyascii <> 8 Then
keyascii = 0
End If
End Sub
这个程序是练习册上的习题,在写这个程序的时候,有好多的地方都不能写出来,好多语言都不会,还是有些生涩。