图1
图2
程序代码如下:
Private Sub Command1_Click()
Dim i As Integer
List1.Clear '清除列表框内容
For i = 3 To 97 ___①___ If f(i) And f(i+2)=true Then List1.AddItem Str(i) + " 和 " + Str(i + 2) End If Next i |
End Sub
Private Function f(x As Integer) As Boolean '判断是否为素数,若是返回true,若不是则返回false
………
End Function
程序中①划线处应填入
数组a用于存储产生的10个随机整数,函数f(x)用于判断随机整数x与已生成的整数是否有重复,若有重复则返回True,否则返回False。
Dim a(1 To 10) As Integer
Function f(x As Integer) As Boolean
′代码略
End Function
Private Sub Commandl_Click()
Dim n As Integer ′n用于统计已经产生的随机整数个数
Dim i As Integer.j As Integer
Dim x As Integer.k As Integer
Randomize ′初始化Rnd函数
n=0
List1.Clear ′清除列表框中内容
List2.Clear
Do While n<10
x=① ′产生[1,999]范围内的随机整数
If Not f(x) Then
n=n+1
a(n)=x
List1.AddItem Str(a(n))
End If
Loop
For i=1 To 9
For j=10 To i+1 step -1
If ② Then
k=a(j):a(j)=a(j-1):a(j-1)=k
End If
Next j
Next i
For i=1 To 10
List2.AddItem Str(a(i))
Next i
End Sub
假设共有500个市民,市民的相关信息都存储在“information.accdb”的data表中,”xm, ye,kh” 字段放市民的姓名,余额,卡号。查询程序界面如第16题图所示。工作人员在文本框Text1中输入卡号,单击“查询”按钮,如果找到,就在Label1中显示卡内市民姓名和卡内余额;否则显示“查无此人”。程序如下,请按要求将程序补充完整。
Private Sub command1_click()
Dim conn As New ADODB.Connection, rs As New ADODB.Recordset
Dim strSQL As String
Dim a,b,c as string
Dim n as integer
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + App.Path + "\ ① "
conn.Open
strSQL ="select * from data"
Set rs.ActiveConnection = conn
rs.Open strSQL
Label1.Caption = ""
c=val(text1.text)
n=0
rs.movefirst
Do while not rs.EOF
n=n+1
a=rs.Fields("xm")
②
If c= rs.Fields("kh") then
Label1.caption=a+ "的卡内余额为"+b+"元"
Exit if
else
rs.movenext
end if
loop
if n=500 then Label1.caption=”查无此人”
rs.close
conn.close
set rs=nothing
set conn=nothing
End Sub