您的位置:首页 > 其它

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

2012-05-05 13:52 274 查看
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

   这个程序是练习册上的习题,在写这个程序的时候,有好多的地方都不能写出来,好多语言都不会,还是有些生涩。

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息