源自 http://www.svbr8.url.tw/Prg_Coding/VB/index_basic_guide.php
●用If判斷式執行對的時候的程式碼與錯的時候的程式碼:
●夾心餅中的夾心餅:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim moon, earth, jupiter As Integer
Dim a, b As Boolean
moon = 1738 : earth = 6378 : jupiter = 71492
a = earth > moon
b = earth > jupiter
If a = True Then
TextBox1.Text = "地球比月球大"
Else
TextBox1.Text = "地球比月球小"
End If
If b = True Then
TextBox1.Text = TextBox1.Text & Chr(13) + Chr(10) & "地球比木星大"
Else
TextBox1.Text = TextBox1.Text & Chr(13) + Chr(10) & "地球比木星小"
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim moon, earth, jupiter As Integer
moon = 1738 : earth = 6378 : jupiter = 71492
If jupiter > earth Then
If earth > moon Then
TextBox1.Text = "木星大於地球 且 地球大於月球"
Else
TextBox1.Text = "木星大於地球 但 地球不大於月球"
End If
Else
If earth > moon Then
TextBox1.Text = TextBox1.Text & Chr(13) + Chr(10) & "木星不大於地球 但 地球大於月球"
Else
TextBox1.Text = TextBox1.Text & Chr(13) + Chr(10) & "木星不大於地球 且 地球不大於月球"
End If
End If
End Sub
End Class
沒有留言:
張貼留言