小s推荐的舞蹈:VB题“判断三个数中最大的数”其中的问题

来源:百度文库 编辑:高考问答 时间:2024/05/11 18:46:40
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single
Dim strtemp As String
a = InputBox("请输入第一个数:")
b = InputBox("请输入第二个数:")
c = InputBox("请输入第三个数:")

strtemp = a & "," & b & "," & c
strtemp = strtemp & "三个数中最大的数:"

If a > b And a > c Then
strtemp = strtemp & a
End If
If b > a And b > c Then
strtemp = strtemp & b
End If
If c > a And c > b Then
strtemp = strtemp & c
End If
Label1.Caption = strtemp
end sub

其中有“&”符号是什么意思,可以有什么简单的方法代替吗???

Dim a As Single, b As Single, c As Single
Dim strtemp As String
'以上定义变量类型

a = InputBox("请输入第一个数:")
b = InputBox("请输入第二个数:")
c = InputBox("请输入第三个数:")
'提示3个输入框,并分别将3个输入的数字分配给 a b c
'假如输入的是 1 2 3

strtemp = a & "," & b & "," & c
'这时,strtemp的内容就是 “1,2,3"

strtemp = strtemp & "三个数中最大的数:"
'这时,strtemp的内容就是 “1,2,3三个数中最大的数:”

If a > b And a > c Then
strtemp = strtemp & a
End If
'如果条件 a大于b 并且 a大于c那么 strtemp的内容是
' 1,2,3三个数中最大的数:1

If b > a And b > c Then
strtemp = strtemp & b
End If

'如果条件 b大于a 并且 b大于c那么 strtemp的内容是
' 1,2,3三个数中最大的数:2

If c > a And c > b Then
strtemp = strtemp & c
End If

'如果条件 c大于a 并且 c大于b那么 strtemp的内容是
' 1,2,3三个数中最大的数:3

Label1.Caption = strtemp
'将 strtemp 的内容赋值给label1.Caption

& 是连接字符用的,跟“+ ”差不多,但不能运算,就是纯粹的连接起来。

Private Sub Command1_Click()
dim a(3) as integer
for j=0 to 2
a(j)=inputbox("请输入第" & j+1 & "个数:")
next
for i=0 to 2
if a(i)>a(i+1) then
a(3)=a(i)
a(i)=a(i+1)
a(i+1)=a(3)
end if
next
print a(2)& "是三个数中最大的数!"
end sub

因为是手写的,可能有错,错的话自己改一下。

& 是连接字符用的,跟“+ ”差不多,但不能运算,就是纯粹的连接起来

&是连接字符串的运算符,可以用+代替