2009年1月22日 星期四

彰商程式設計隊的99題練習題(4.輸入四個數字,找出最大與最小值。)

 

image

image

image

 

程式碼

Public Class Form1
    Dim a, b, c, d
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        a = Val(TextBox1.Text)
        b = Val(TextBox2.Text)
        c = Val(TextBox3.Text)
        d = Val(TextBox4.Text)
        If a > b And a > c And a > d Then
            TextBox1.ForeColor = Color.Red
        ElseIf b > a And b > c And b > d Then
            TextBox2.ForeColor = Color.Red
        ElseIf c > a And c > b And c > d Then
            TextBox3.ForeColor = Color.Red
        Else
            TextBox4.ForeColor = Color.Red
        End If

        If a < b And a < c And a < d Then
            TextBox1.ForeColor = Color.Green
        ElseIf b < a And b < c And b < d Then
            TextBox2.ForeColor = Color.Green
        ElseIf c < a And c < b And c < d Then
            TextBox3.ForeColor = Color.Green
        Else
            TextBox4.ForeColor = Color.Green
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Clear()
        TextBox2.Clear()
        TextBox3.Clear()
        TextBox4.Clear()

        TextBox1.ForeColor = Color.Black
        TextBox2.ForeColor = Color.Black
        TextBox3.ForeColor = Color.Black
        TextBox4.ForeColor = Color.Black
    End Sub
End Class

1 則留言: