
请根据算法将下列程序补充完整。
Private Sub Command1_Click()
Label3.Caption = ""
For i = 1 To 50
a(i) =
If i Mod 10 = 0 Then
Label3.Caption = Label3.Caption + CStr(a(i)) + vbCrLf '换行
Else
Label3.Caption = Label3.Caption + CStr(a(i)) + " "
End If
Next i
End Sub
Private Sub Command2_Click()
Label4.Caption = ""
n = 0
For i = 1 To 50
For k = 2 To a(i) - 1
If Then Exit For
Next k
If k = a(i) Then
n = n + 1
If n = 1 Then b(n) = a(i)
For j = 1 To n - 1
If b(j) = a(i) Then: Exit For
If j = n - 1 Then b(n) = a(i)
Next j
End If
Next i
For j = 1 To n
Label4.Caption = Label4.Caption + + " "
Next j

|
图a |
请回答下列问题:
| 图b |
s = Text1.Text
If Mid(s, 1, 1) = "(" Then flag = True Else flag = False
cnt = 0: sum = 0
For i = 2 To Len(s)
c = Mid(s, i, 1)
If flag = True Then
If c >= "a" And c <= "z" Then
sum = sum + 1
Else
If sum <> 0 Then cnt = cnt + 1: sum = 0
End If
End If
If c = "(" Then flag = True
If c = ")" Then flag = False
Next i
文本框Text1的内容为一串只包含小写字母、左右括号和空格的字符串“(we can) do (better) we (should (be )better)”,执行程序段后,变量cnt的值为( )
"查找ASCII最大的字符"/ C .Form1.AddItem "查找ASCII最大的字符")
Const n = 40
Private Sub Command1_Click()
Dim s As String, ch As String
Dim i As Integer, max As Integer
s = Text1.Text
max = 0
For i = 1 To Len(s)
ch =
If Asc(ch) > max Then max = Asc(ch)
Next i
Label1.Caption = "最大ASCII码:" + + " 该字符为:" + Chr(max)
End Sub
Private Sub Form_Load() ’随机生成可见字符并显示在文本框Text1中
Randomize
For i = 1 To n
Text1.Text = Text1.Text +
Next i
End Sub
1)操作1(单词的删除):在Text2中输入一个单词s1,在字符串s中找到左边第一个出现的相同单词(区分大小写),将其删除,并在Label1中显示删除单词的位置pos;若s中不存在单词s1,则字符串s不变。
例如:s=“Go with your your passion.”s1=“your” 点击“删除”按钮后,s=“Go with your passion.”pos=“9”若s1=“Your”,则s不变。
2)操作2(单词的插入):在Text3中输入一个单词s2,并在Text4中输入插入位置w,将s2插入到经过删除操作的s中以w开始的位置。
例如:s=“Go with your passion.”s2=“absolutely” w=21
点击“插入”按钮后,s=“Go with your passion absolutely.”
程序运行界面如下图所示。
实现上述功能的VB程序如下。请回答下列问题:
Dim s As String
Private Sub Command1_Click( ) '实现删除单词命令
Dim s1 As String, t As String, i As Integer, pos As String, result As String Dim begin As Integer, word As String
s = Text1.Text s1 = Text2.Text begin = 1
For i = 1 To Len(s)
t =
If Not (t >= "a" And t <= "z" Or t >= "A" And t <= "Z") Then
If i > begin Then
word =
If word = s1 Then ‘找到与s1相等的单词,则将该单词删除
s = Mid(s, 1, begin - 1) + Mid(s, i+1, Len(s) - i)
pos =
Exit For
End If
End If
begin = i + 1
End If
Next i
Text5|.Text = s
Label1.Caption = pos End Sub
Private Sub Command2_Click() '实现插入单词命令
Dim w As Integer, result As String, s2 As String s2 = Text3.Text
result = + " " + s2 + " " + Mid(s, w, Len(s) - w + 1) Text5.Text = result
End Sub