图2
图3
Private Sub Commandl_Click( )
Dim s, p As String
Dim a, n As Integer
Dim kms As Integer
s= ①
n = Len ( s ):a = 0 :kms = Val(Text2.Text)
If n Mod kms = 0 Then
For i= ②_______
p = Mid(s,i,1)
If p= "A" or p= "a" Then a = a+l
Next i
Text3.Text = Str(a)
Else
Text3.Text="学生等级信息不正确"
End If
End Sub
请回答下列问题:
① 处应填;② 处应填。
实现上述功能的VB程序代码如下,请在划线处填上合适的代码。
Dim a( 1 To 20) As Integer
Private Sub Command1_Click ( )
Dim key As Integer
key = ①
i = 1
Do While key > a ( i ) And ( i <= 1 5 )
i = i + 1
Loop
Label4.Caption = “该数插入的位置是:” + Str ( i )
If i = 16 Then
a ( i ) = key
Else
For j = 16 To i + 1 Step -1
②
Next j
a ( i ) = key
End If
List2. Clear
For i = 1 To 16
List2.AddItem a( i)
Next i
End Sub
Private Sub Form_Load( )
'随机生成15个200以内的正整数
Randomize
For i = 1 To 15
a ( i ) = Int(Rnd * 200) + 1
Next i
'将15个数从小到大排序
For i = 1 To 14
k = i
For j = i + 1 To 15
If a ( k ) > a ( j ) Then k = j
Next j
If i <>k Then
t = a(i); a( i) = a ( k ):a ( k )
End If
Next i
'将排好序的数输出在列表框Listl中
Listl.Clear
For i = 1 To 15
Listl.AddItem str ( a ( i ) )
Next i
End Sub
程序中①划线处应填入,程序中②划线处应填入
小明设计了一个VB程序,用于求解10000以内的所有完全数。点击按钮Command1,标签Label1显示完全数的个数,并在列表框中显示10000以内所有的完全数。
程序运行效果如图所示
实现上述功能的VB程序如下,请在划线处填入合适代码。
Private Sub Command1_Click( )
Dim i As Integer, j As Integer, c As Integer, s As Integer
c = 0 ‘用于存储完全数的个数
For i =1 To 10000
s=0 ‘用于存储各因数之和
For j = 1 To i - 1
If fac(i, j) Then
Next j
If i = s Then
Listl.AddIltem Str( i)
End If
Next i
Label.Caption =“10000 以内共有” +Str(c) + “个完全数!”
End Sub
Function fac(x As Integer, y As Integer) As Boolean
'如果y是x的因数返回True,否则返冋False
If Then
fac = True
Else
fac = False
End If
End Function