溫度換算器程式碼


 



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 



        T1.ForeColor = Color.Blue            End Sub

 



    Private Sub c2f_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles f2c.Click

 



        Dim f As String

 



        Dim c As Double

 



        'f = InputBox("給我一個攝氏度數", "輸入", "20")

 



        f = T1.Text

 



        c = 9 * f / 5 + 32

 



        'T1.Text = f

 



        T2.Text = c

 



    End Sub

 



    Private Sub B2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles B2.Click

 



        Dim ret

 



        ret = MsgBox("不要離開啦~!!", MsgBoxStyle.OKCancel + MsgBoxStyle.Exclamation + MsgBoxStyle.DefaultButton1, "結束")

 



        If ret = MsgBoxResult.OK Then End

 



        End

 



    End Sub

 



    Private Sub c2f_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles c2f.Click

 



        Dim c As String

 



        Dim f As Double

 



        'c = InputBox("給我一個華氏度數", "輸入", "68")

 



        c = T2.Text

 



        f = 5 * (c - 32) / 9

 



        T1.Text = f

 



        'T1.Text = c

 



    End Sub

 



Private Sub T1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles T1.KeyPress

 



        If e.KeyChar = Chr(13) Then

 



            Dim f As String

 



            Dim c As Double

 



            f = T1.Text

 



            c = 9 * f / 5 + 32

 



            T2.Text = c

 



        End If

 



    End Sub

 



Private Sub T2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles T2.KeyPress

 



        If e.KeyChar = Chr(13) Then

 



            Dim c As String

 



            Dim f As Double

 



            c = T2.Text

 



            f = 5 * (c - 32) / 9

 



            T1.Text = f

 



        End If

 



    End Sub

 



End Class

arrow
arrow
    全站熱搜

    allnewtim 發表在 痞客邦 留言(0) 人氣()