Private Sub Command1_Click()
Dim a As intger, i As intger, s As String
n = Val(Text1.Text)
s = ""
For i = 1 To 2 * n - 1
If i > n Then ① Else ②
Next i
text2.Text = s
End Sub
为实现以上功能,①②处分别填写( )
n = 12
f = Val(Text1.Text)
left = 1
right = n
Do While left < right
middle = (left + right) \ 2
If f <= a(middle) Then
right = middle
Else
left = middle + 1
End If
Loop
A数组元素A(1) 到A(12) 中的数分别是1 4 6 10 11 16 17 18 19 20 21 55,在文本框text1 中输入值7 赋给变量f,经过该程序段“加工”后,right 的值为( )
map =“ 01234567890123456789012345”
tel = Text1.Text
For i = 1 To Len(tel)
c = Mid(tel, i, 1)
If c >=“ 0” And c <=“ 9” Then
s = s + c
ElseIf c >“ A” And c <=“ Z” Then
s = s + Mid(map, Asc(c) - Asc(“A”) + 1, 1)
End If
Next i
在text1 文本框中输入“hi,NICETOSEEYOU-2016”,程序执行完后s 的结果是( )
Private Sub Command1_Click()
Dim p As Integer
Dim sum As Long
p = Val(Text1.Text)
sum = fx(p)
Text2.Text = CStr(sum)
End Sub
Function fx(x As Integer) As Long
If x = 1 Then
fx = 1
Else
fx =
End If
End Function
要该程序实现此功能,横线处的代码为( )
Private Sub Command1_Click()
Dim sum, k, j, n As Integer
n = Val(Text1.Text)
sum = 0: k = 1
Do While k <= n
j = 1
Do While j <= k
sum = sum + 1: j = j + 1
Loop
k = k * 3
Loop
Text2.Text = CStr(sum)
End Sub
Function arr(x As Integer) As Boolean
Dim s As Integer, i As Integer
s = 1
For i = 2 To x \ 2
If x Mod i = 0 Then s = s * i
Next i
If s = x Then
arr = True
Else
arr = False
End If
End Function
Private Sub Command1_Click()
Dim i As Integer
For i = 2 To 10
If arr(i) Then List1.AddItem str(i)
Next i
End Sub
单击Command1按钮后,List1中显示的结果是( )
Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As String, n As Integer, s As String
s = "abcdefghijklmn"
n = 4
List1.Clear
For i = 1 To n
k = Mid(s, i + 1, i)
For j = 1 To Len(k)
k = k + Mid(s, j, 1)
Next j
List1.AddItem k
Next i
End Sub
该程序运行后,在列表框List1中显示的是( )
Private Sub Command1_Click()
Const n = 20
Dim i As Integer, j As Integer
Dim a(1 To n) As Integer
For j = 1 To n
a(j) = 0
Next j
For i = 1 To n
For j = 1 To n
Ifthen
End If
Next j
Next i
For j = 1 To n
If a(j) = 0 Then list1.AddItem Str(j)
Next j
End Sub
为了实现程序该功能,在画线处填写正确代码。
原1-7号男生身高 |
171 172 180 174 176 179 178 |
筛选排序后序列 |
171 172 174 176 178 179 180 |
“造型设计”后序列 |
180 178 174 171 172 176 179 |
王林同学用VB编写模拟“节目造型”程序,功能如下:从数据库中导出所有学生编号、性别和身高数据;单击“筛选排序”按钮Command1,选出“男生”且按身高升序排列显示在文本框Text1中;单击“设计造型”按钮Command2,根据身高仿“V”字的造型进行有序排列,并将结果显示在文本框Text2 中。程序运行界面如图所示。举例说明如下:
Const n = 7
Dim h2(1 To n) As Integer
Dim height1(1 To n) As Integer, height 2 (1 To n) As Integer
Dim i As Integer, j As Integer, temp As Integer
Dim sex(1 To n) As Boolean ' 男生sex=true
Private Sub Form_Load()
'n名学生的身高和性别由数据库导出,分别存储在数组height1和sex中,代码略!
End Sub
Private Sub Command1_Click()
For i = 1 To n - 1
For j = n To i + 1 Step -1
IfThen
temp = height1(j): height1(j) = height1(j - 1): height1(j - 1) = temp
End If
Next j
Next i
For i = 1 To n
Text1.Text = Text1.Text + " " + Str(height1(i))
Next i
End Sub
Private Sub Command2_Click()
Dim left, right As Integer, i As Integer, mid As Integer
mid = Int((1 + n) / 2)
left = 0: right = 0
For i = 2 To n Step 2
right = right + 1
height2(mid + right) = height1(i)
left = left + 1
Next i
For i = 1 To n
Text2.Text = Text2.Text +“ “ + Str(height2(i))
Next i
End Sub
为实现以上功能,请在画线处填写正确代码。
Private Sub Command1_Click()
Dim s As String, f As Boolean, L As Integer
s = Text1.Text
j = Len(s)
i = 1
Do while
i = i+1
j = j-1
Loop
If Then Print "是回文串" Else Print " 不是回文串"
End Sub
在画线处填入合适代码,使程序能正常运行。
小丫编写了一个求中位数的VB程序,功能如下:单击“求中位数”按钮Command1,程序根据输入的n和m,随机产生n个在[0,m]范围内的数。程序运行界面如下所示:
实现上述功能的VB 程序如下:
Dim x(1 To 1000) As Long
Private Sub Command1_Click()
Dim n As Integer, i As Integer, rbound As Integer, mid As Integer
Dim m As Integer, count As Integer
n = Val(Text1.Text)
m = Val(Text2.Text)
List1.Clear
Randomize
For i = 1 To n
x(i) =Int(Rnd * (m + 1)) ' 产生[0,m] 的随机数
List1.AddItem x(i)
Next i
lb = 0
rb = m
Do While lb <rb
mid = (lb + rb) \ 2
①
For i = 1 To n
If ② Then
count = count + 1
End If
Next i
If count > n \ 2 Then
lb = mid + 1
Else
③
End If
Loop
Text3. text = str(rb)
End Sub
程序要实现该功能,画线处应填入的代码为:
①②③
代码如下:
Dim a(1 To 100) As String, a1(1 To 100) As String, b(1 To 100) As Integer, b1(1 To 100) As Integer
Private Sub Form_Load()
'读取数据库中学生相关信息,姓名存数组a,身高存数组b
End Sub
Private Sub Command1_Click()
Dim temp As Integer, temp2 As String, k As Integer, s As String, s1 As String
For i = 1 To 44
For j = i + 1 To 45
If b(i) > b(j) Then
temp = b(i): b(i) = b(j): b(j) = temp
temp2 = a(i): a(i) = a(j): a(j) = temp2
End If
Next j
Next i
For x = 1 To 3
k = 0
For y = 15 * x ToStep -1
If x Mod 2 = 1 Then
If y Mod 2 = 1 Then
b1(15 * (x - 1) + 8 - k) = b(y)
a1(15 * (x - 1) + 8 - k) = a(y)
Else
k = k + 1
b1(15 * (x - 1) + 8 + k) = b(y)
a1(15 * (x - 1) + 8 + k) = a(y)
End If
Else
If y Mod 2 = 1 Then
k = k + 1
b1(15 * (x - 1) + 8 - k) = b(y)
a1(15 * (x - 1) + 8 - k) = a(y)
Else
b1(15 * (x - 1) + 8 + k) = b(y)
a1(15 * (x - 1) + 8 + k) = a(y)
End If
End If
Next y
Next x
For i = 1 To 45
s = s + " " + a1(i)
s1 = s1 + " " + Str(b1(i)) + " "
IfThen
Label1.Caption = Label1.Caption + " 第" + Str(i \ 15) + " 排" + s + vbCrLf + s1 + vbCrLf
' fvbCrLf 表示回车换行
s = ""
s1 = ""
End If
Next i
End Sub
要使程序实现此功能,在画线处填入适当的语句或表达式,将程序补充完整。
现要求根据输入的字符串(长度在1000 以内),全部由数字和字母组成,得到大小写不敏感压缩后的结果(即所有小写字母均视为相应的大写字母)。如:原字符串为aAABBbBCCCaaaaa,压缩后的结果(A,3)(B,4)(C,3)(A,5)。
实现这一功能的程序代码如下:
Private Sub Command1_Click()
Dim s As String, s1 As String
Dim tmp As String, ans As String
Dim i As Integer, j As Integer
s = Text1.Text
s1 = ""
For i = 1 To Len(s)
s1 = s1 & ToUpcase()
Next i
i = 1
Do While i <= Len(s1)
tmp = Mid(s1, i, 1)
ans = ans & "(" & tmp & ","
j = i + 1
Do While j <= Len(s1) And Mid(s1, j, 1) = tmp
j = j + 1
Loop
ans = ans && ")"
Loop
Text2.Text = ans
End Sub
Function ToUpcase(c As String) As String
If c >= "a" And c <= "z" Then
ToUpcase = Chr(Asc(c) - 32)
Else
ToUpcase = c
End If
End Function
在画线处填入适当的语句或表达式,将程序补充完整。
程序代码如下:
Dim x As String
Dim y As String
Dim c(1 To 100) As String
Private Sub Command1_Click()
Dim z As String
x = Text1.Text
y = Text3.Text
z = f(x,y)
Text2.Text = z
End Sub
Function f(x As String, y As String) As String
Dim i, w, achar As Integer
Dim mm As String
w = Asc(y)
For i = 1 To Len(x)
achar = Asc(Mid(x, i, 1))
c(i) = Chr(x Xor y) ‘
Next i
For t = 1 To Len(x)
mm = mm+achar ‘
Next t
f = mm
End Function
程序代码有2处错误,请在画线处写上正确代码。
代码如下:
Private Sub Command1_Click()
Dim a(13), i, j, n As Integer '定义变量
Form1.Cls
i = 1 '将变量i的值为1
Do While i <= 13 '当i的值小于等于13时循环
Do While True
j = j + 1
If j > 13 Then '当j的值大于13时,将其重置为1
If a(j) = 0 Then n = n + 1 '如果该位置元素为0,则n加1
If n = i Then
'将i的值放入数组指定的位置中
n = 0 ' 计数器重新为0
Exit Do
End If
Loop
i = '计数器i加1
Loop
Label1.Caption = "原来牌的顺序是:"
For k = 1 To 13
Label2.Caption = Label2.Caption + '输出扑克牌的原有顺序
Next k
End Sub
在画线处填入适当的语句或表达式,将程序补充完整。