2017年11月21日 星期二

[ VB2010 ] - 008 條件判斷流程 003

[ VB2010 ] - 008 條件判斷流程 003

●條列式結構:

●三元判斷函數:




Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim R As Integer
        R = 60268
        TextBox1.Text = "R=" & R & "km, is " & WhoIs(R)

    End Sub

    Function WhoIs(ByVal Radius As Integer) As String
        Dim Mercury As Integer = 2440
        Dim Venus As Integer = 6052
        Dim Earth As Integer = 6378
        Dim Mars As Integer = 3397
        Dim Jupiter As Integer = 71942
        Dim Saturn As Integer = 60268
        Dim Uranus As Integer = 25559
        Dim Neptune As Integer = 24764

        If Radius = Mercury Then
            WhoIs = "Mercury"

        ElseIf Radius = Venus Then
            WhoIs = "Venus"

        ElseIf Radius = Earth Then
            WhoIs = "Earth"

        ElseIf Radius = Mars Then
            WhoIs = "Mars"

        ElseIf Radius = Jupiter Then
            WhoIs = "Jupiter"

        ElseIf Radius = Saturn Then
            WhoIs = "Saturn"

        ElseIf Radius = Uranus Then
            WhoIs = "Uranus"

        ElseIf Radius = Neptune Then
            WhoIs = "Neptune"

        Else
            WhoIs = "Unknow"

        End If

    End Function

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim Moon As Int32, Earth As Int32, Jupiter As Int32
        Moon = 1738
        Earth = 6378
        Jupiter = 71492

        TextBox1.Text = "地球比月球" & IIf(Earth > Moon, "大", "小")
        TextBox1.Text = "地球比木星" & IIf(Earth > Jupiter, "大", "小")

    End Sub
End Class

沒有留言:

張貼留言

113 學年度第 1 學期 RFID應用課程 Arduino程式

113 學年度第 1 學期 RFID應用課程 Arduino程式 https://www.mediafire.com/file/zr0h0p3iosq12jw/MFRC522+(2).7z/file 內含修改過後的 MFRC522 程式庫 (原程式有錯誤) //定義MFRC522...