问几道简单的VB题目

来源:百度知道 编辑:UC知道 时间:2024/06/05 09:38:18
按照条件,写出相应的条件语句
1 当C字符变量中第三个字符是"C"时,利用MsgBox显示"yes",否则显示"no"
2 利用If语句和IIf函数两种方法求三个数x、y、z中的最大值,并将其放入Max变量中

1.代码如下:
Private Sub Command1_Click()
Dim c$
c = "abcdefg"
If Mid(c, 3, 1) = "C" Then
MsgBox "yes"
Else
MsgBox "no"
End If
End Sub

2.代码:
Private Sub Command2_Click() 'IF方式
Dim x%, y%, z%, max%
x = 5: y = 10: z = 7
If x > y Then
max = x
Else
max = y
End If
If max < z Then max = z
Print max
End Sub

Private Sub Command3_Click() 'IIF方式
Dim x%, y%, z%, max%
x = 5: y = 10: z = 7
max = IIf(x > y, x, y)
max = IIf(max > z, max, z)
Print max
End Sub

1楼的已经说得很清楚了,我就不多说了