P1. 輸入數值A、B,輸出A-B之「絕對值」? If
Dim A, B As Single
Dim ans = ""
A = InputBox("輸入A=", "求A-B的絕對值", 0)
B = InputBox("輸入B=", "求A-B的絕對值", 0)
If A - B > 0 Then
ans = A - B
Else
ans = -(A - B)
End If
Me.TextBox1.Text = ans
P2. 輸入數值A、B,輸出A-B之「絕對值」? Select
Dim A, B As Single
Dim ans = ""
A = InputBox("輸入A=", "求A-B的絕對值", 0)
B = InputBox("輸入B=", "求A-B的絕對值", 0)
Select Case A - B
Case Is > 0
ans = A - B
Case Else
ans = -(A - B)
End Select
Me.TextBox2.Text = ans
P3.印出九九乘法表。 For
Dim ans = ""
For j = 1 To 9
For i = 1 To 9
ans &= j & "x" & i & "=" & RSet(i * j, 2) & " "
Next
ans &= vbNewLine
Next
Me.TextBox3.Text = ans
P5.輸入西元年 y,判斷 y 是「閏年」還是「平年」?
Dim y As Integer
Dim ans As String = ""
y = InputBox("西元年 = ", "輸入西元年 y,判斷 y 是「閏年」還是「平年」", 0)
If (y Mod 400 = 0) Or (y Mod 4 = 0 And y Mod 100 <> 0) Then
ans = y & "是閏年"
Else
ans = y & "是平年"
End If
Me.TextBox4.Text = ans
P6.不換行印出 -20 -24 -28 ... -44 -48 If
Dim ans As String = " "
For i = -20 To -48 Step -4
ans &= i & " , "
Next
Me.TextBox5.Text = ans
沒有留言:
張貼留言