实现摄氏温度与华氏温度之间的转换

Option Explicit

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

你可能感兴趣的:(实现摄氏温度与华氏温度之间的转换)