下列说法中正确的是( )
i= 1 : j =9 : n =0
key=Val( Textl.Text)
Do While i <= j
m=(i + j) \ 2
If key = d(m) Then
Exit Do
j= m - 1
Else
i=m+1
End If
Loop
方框中的正确代码应为( )
Private Sub Command1_Click()
Dim n As Integer, i As Integer, s As String
n = Val(Text1.Text)
s = ""
For i = 1 To 2 * n - 1
If i <= n Then ① Else ②
Next i
Label1.Caption = s
End Sub
为实现以上功能,划线①②处应分别填写( )
Const MAXNUM = 100
Dim i As Integer, n As Integer
Dim a(1 To MAXNUM ^ 2) As Integer
Private Sub Command1_Click()
Dim line As String
n = Val(Text1.Text)
line = ""
List1.Clear
Randomize
For i = 1 To n ^ 2
a(i) = ①
If i > 1 And i Mod n = 1 Then
List1.AddItem line
line = Str(a(i))
Else
line = ②
End If
Next i
List1.AddItem line
End Sub
Private Sub Command2_Click()
Label1.Caption = ""
For i = 1 to ③
Label1.Caption = Label1.Caption & Str(a(i + (i - 1) * n))
Next i
End Sub
① ② ③
场景:main | 类别序号:2 | 进入方式:由“load”场景单击“播放”按钮进入 |
呈现方式: ⒈“文字1”和“文字2”均由小变大,出现在舞台中间偏上位置。 ⒉其他动画略。 | 呈现顺序说明: ⒉一开始出现背景图片、“太阳”、“云”、“文字1”、“枫叶1”和“枫叶2”的动画,再出现“文字2”和“蜻蜓”的动画。 ⒉该场景播放结束后,跳转到第1帧继续播放。 |
A | B | C | D |
Private Sub Command1_Click()
Dim i As Integer, j As Integer, sum As Integer
Dim n As Integer
n = Val(Text1.Text)
sum = 0
List1.Clear
For i = 1 To n ' ①
j = i - 1
Do While sum <= n ' ②
j = j + 1
sum = sum + j
Loop
If sum = n Then
List1.AddItem Str(i) & " + ... +" & Str(j) & "=" & Str(n)
End If
sum = 0
Next i
End Sub
① ②
小张编写了一个VB程序来解这个游戏,功能如下:点击“初始化”按钮Command1初始化游戏,程序随机地将1~8这8个整数填入到数阵的外层圆圈中,同时将该状态下的数阵显示在列表框List1中。点击“开始”按钮Command2,程序开始移数字,并将移动过程中的每一步输出在列表框List2中,最后统计总移动步数到标签Label1中。为了清楚地描述输出数字在数阵中的每一步移动步骤,小张给数阵中的每一个圆圈都进行了编号,具体编号方法如图c所示,因此1号圈中的数字移动到2号圈可以表示为“1#-->2#”。程序运行界面如图d所示。
实现上述功能的VB代码如下。
Dim a(1 To 8) As String
Private Sub Command1_Click()
Dim temp As Integer, i As Integer, j As Integer
Dim flag(1 To 8) As Boolean
For i = 1 To 8
①
Next i
Randomize
For i = 1 To 8
temp = Int(Rnd() * 8 + 1) '生成1~8之间的随机整数
Do While flag(temp)
temp = Int(Rnd() * 8 + 1) '生成1~8之间的随机整数
Loop
a(i) = temp
flag(temp) = True
Next i
List1.Clear
List1.AddItem "初始状态:"
PrintCircle
End Sub
Private Sub Command2_Click()
Dim i As Integer, j As Integer, temp As String, n As Integer, moveStep As String
moveStep = ""
List2.Clear
n = 0
For i = 1 To 7 '使用冒泡排序对圆圈中的数字进行移动
For j = 1 To ②
If a(j) >= a(j + 1) Then
temp = a(j): a(j) = a(j + 1): a(j + 1) = temp
moveStep = Str(j) & "#--> 0#"
moveStep = moveStep & " " & Str(j + 1) & "#-->" & Str(j) & "#"
moveStep = moveStep & " " & "0#-->" & Str(j + 1) & "#"
List2.AddItem moveStep
n = n + 1
End If
Next j
Next i
List1.AddItem "移动数字后:"
PrintCircle
Label1.Caption = "总移动步数:" & ③
End Sub
'在列表框List1中输出当前的数阵状态
Function PrintCircle()
List1.AddItem "-------------------------"
List1.AddItem "[" & a(1) & "]-[" & a(2) & "]-[" & a(3) & "]"
List1.AddItem " | \ | / |"
List1.AddItem "[" & a(8) & "]-[" & " " & "]-[" & a(4) & "]"
List1.AddItem " | / | \ |"
List1.AddItem "[" & a(7) & "]-[" & a(6) & "]-[" & a(5) & "]"
List1.AddItem "-------------------------"
End Function
① ② ③