
Private Sub Command1_Click()
Dim s As Integer, x As Integer
s = 0
x = 20
For x = 20 To 1 Step -3
s = s + x
Next x
Print x
End Sub
Private Sub Command1_Click ( )
Dim t As Long, s As string
s = Text1. Text
For i = 1 To Len (s)
s = Mid(Text1. Text, i, 1)
If s > = “0” s < = “9” Then
t = t * 10 + Va1 (s)
ElseIF s > = “a” And s< = “z” Then
t = 10
End If
Next i
Text2. Text = Str(t)
End Sub
运行该程序,在文本框Text1中输入“2018 Iphone7”,单击命令按钮Command1后,文本框Text2中显示的内容是( )

Private Sub Command 1_Click()
Dim n As Integer,i As Integer
Dim a(1 To 50)As Integer
Randomize
For i=l To 50
①
List1.AddItem Str(a(i))
Next i
If a(1)<a(2)Then
firstmin=a(1)
secondmin =a(2)
Else
firstmin=a(2)
secondmin=a(1)
End If
For i=3 To 50
If a(i)<secondmin Then
If ② Then
secondmin=firstmin
firstmin=a(i)
Else
③
End If
End If
Next i
Labell.Caption="第二小的数是"&Str(secondmin)
End Sub
①②③
li = map(int, input(). split())
cnt=0
for i in li:
if :
cnt+=1
print("奇数有{}个。". format(cnt))
现用VB程序实现上述功能:在文本框Text1中输入参赛队伍数n,单击“编排”按钮Command1,在列表
|
图a 图b |
框List1中输出每轮比赛秩序。程序运行效果如图b所示。
实现上述功能的VB代码如下,但加框处代码有错,请改正。
Private Sub Command1_Click( )
Dim team(1 To 20) As String '存储各队伍编号
Dim n As Integer,c As Integer,result As String
Dim i As Integer,j As Integer,temp As String
n=Val(Text1.Text)
For i=1 To n
team(i)=Str(i)
Next i
c=n+n Mod 2 '变量c存储比赛编排的队伍总数
If c<>n Then team(c)=Str(0)
For i=1 To c-1
result=″ ″
For j=1 To c\2
result=result & team(j) & ″-″&
& ″;″ '
Next j
List1.AddItem ″第″ & Str(i) & ″ 轮″ & result
'固定编号1,其余队伍逆时针移动一个位置
temp=team(c)
For j=c To 2 Step -1
'
Next j
team(2)=temp
Next i
End Sub
Key=Val(Text1.Text)
i=1:j=10
Text2.Text=""
Do While i<=j
m=Int((i+j)/2+0.5)
If Key=a(m)Then Exit Do 'Exit Do表示退出循环
If Key<a(m)Then j=m-1 Else i=m+1
Text2.Text=Text2.Text +Str(a(m))
Loop
数组元素a(1)到a(10)的值依次为“8,17,24,30,36,40,55,58,61,66”,文本框Text1中输入的值是30,执行该程序段后,文本框Text2中显示的是( )
For i = 1 To 6
a(i) = Int(Rnd * 10) + 1
Next i
For i = 2 To 6
If i Mod 2 = 0 And a(i)>a(i-1) Then
t=a(i):a(i)=a(i-1):a(i-1)=t
Else
a(i)=a(i)-1
End If
Next i
执行程序后,数组元素a(1)到a(6)的值可能是( )