For i= 1 to 3
List1. AddItem b(a(i))
Next i
数组元素a(1)到a(6)的值依次为“4,2,3,6,1,5”,数组元素b(1)到b(6)的值依次为“Ella”“Sally”“Lily”“Tom”“Anna”“Jack”,则执行上述程序段,List1中显示的内容是( )
Dim a(1 To 10) As Integer
Dim s As String, n, i As Integer
s = "54851845236": n = Len(s)
For i = 1 To n - 1
a(i) = Val(Mid(s, i, 2))
Next i
For i = 1 To n - 2
k = i
For j = i + 1 To n - 1
If a(k) < a(j) Then k = j
Next j
If k <> i Then
t = a(k): a(k) = a(i): a(i) = t
End If
Next i
Text1.Text = Str(a(1))
该程序段运行后,文本框 Text1 中显示的内容是:( )
i = 1:j = 8:s = ""
key = Text1. Text
Do While i <= j
m = (i +j)\2
If key = a(m) Then
s = s+ "M"
Exit Do
ElseIf key <a(m) Then
j = m -1:s = s+ "L"
Else
i = m+1:s = s + "R"
End If
Loop
Text1. Text = s
数组元素a(1)到a(8)的值依次为“4,22,27,32,35,44,56,59”,该程序段执行后,文本框Text1中显示的内容不可能是( )
Dim a(1 To 10) As Integer
Dim s As String, n, key As Integer
a(1) = 23: a(2) = 33: a(3) = 44: a(4) = 55: a(5) = 66: a(6) = 77
i = 1: j = 6: c = 0: key = 35
Do While i <= j
c = c + 1
m = (i + j) \ 2
If (j - i + 1) Mod 2 = 0 Then m = m + 1
If a(m) = key Then Exit Do
If key < a(m) Then j = m - 1 Else i = m + 1
Loop
该程序段运行后,下列各变量的值不正确的是:( )
Private Sub Command1_Click
Dim s As String, ch As String, sum As Integer
Dim fh As Integer
s = Text1.Text: fh = 1: p = 0: sum=0
For i = 1 To Len(s)
ch = Mid(s, i, 1)
If ch >= "0" And ch <= "9" Then
p =
Else
sum =
p = 0
If ch = "-" Then
fh = -1
ElseIf ch = "+" Then
fh = 1
End If
End If
Next i
Label1.Caption = Str(sum)
End Sub
现要求计算从原点到整点(x,y)螺旋折线段的长度。小王根据上述描述设计如下VB程序,请回答下列问题:
Dim x As Integer, y As Integer 'x用于存储横坐标的值,y用于存储纵坐标的值
Private Sub Command1_Click()
Dim sum As Integer, m As Integer
Dim dx As Integer, dy As Integer
Dim i As Integer, t As Integer
x=Val(Text1. Text)
y =Val(Text2. Text)
dx = 0:dy=0
sum=0
m=1:t=-1
Do While not check(dx,dy)
For i=1 To m
If check(dx,dy)Then exit do 'Exit do表示退出Do循环
dx = dx+t
sum = sum+1
Next i
For i=1 To m
If check(dx,dy) Then Exit Do
sum = sum + 1
Next i
m=m+1
Loop
Label1. Caption= Str(sum)
End sub
Function check(xl As Integer,y1 As Integer)As Boolean
check = False
If x1=x And y1=y Then
End If
End function