按上述要求,编写一个VB程序,功能如下:程序运行时从数据库中读取志愿者的检测号、
DNA序列存入相应数组,在文本框Text1中输入抗体DNA序列,单击“检测结果”按钮Command11,在列表框List1中按检测号顺序显示每个志愿者的检测结果,并在标签Label1显示疫苗抗体的阳性率(以百分比表示,并保留2位小数),程序运行界面如图所示,请在划线处填入合适的代码。
Dim Pnum(1 To 100) As String 'Pnum数组存储志愿者的检测编号
Dim Pch(1 To 100) As String 'Pch数组存储志愿者的DNA序列
Dim Prs(1 To 100) As String 'Prs数组存储志愿者的检测结果
Dim n As Integer '存储志愿者的总人数
Private Sub Form_ Load( )
Dim i As Integer, j As Integer
Dim tmp As String, chtmp As String
Dim Conn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Conn.ConnectionString = "Provider=Mi crosoft. ACE.OLEDB.12. 0;Data Source=" + App.Path+"\DNADB.accdb"
Conn.Open
Set Rs.ActiveConnection = Conn
Rs.Open "SELECT * FROM Source" '从数据库的名为 “Source”数据表中读取数据
i =0
Do While Not Rs.EOF
i=i+1
Pnum(i) = Rs.Fields(0)
Pch(i) = Rs.Fields(1)
Rs.MoveNext
Loop
Rs.Close
Conn.Close
n=
For i=1 To n-1 '以检测号作为关键字对DNA序列数据进行升序排列
j=i+1
Do While j <= n
If Then
chtmp = Pch(i):Pch(i)= Pch(j):Pch(j)= chtmp
tmp = Pnum(i):Pnum(i)= Pnum(j):Pnum(j)= tmp
End If
j=j+1
Loop
Next i
End Sub
Private Sub Command1_ Click( )
Dim Ach As String, RVch As String, Vch As String
Dim i As Integer, j As Integer, k As Integer, m As Integer
Ach = Text1. Text: s = Len(Ach): RVch = Ach + Ach
k=0:m=0
For i=1 To n
If Len(Pch(i)) <= Len (Ach) Then
k =k+ 1: Prs(i) = “无效”
Else
For j=1 To s '按环状序列依次进行比较
Vch =
If Test(Vch,Pch(i)) Then
m=m+1
Prs(i) =“阳性”: Exit For
Else
Prs(i) =“阴性”
End If
Next j
End If
Next i
For i =1To n
List1. AddItem Pnum(i) +" " + Prs(i)
Next i
Label1. Caption = Str(Int(m/(n-k)*10000 +0.5)/100) + "%"
End Sub
Function Test(str1 As String,str2 As String) As Boolean '字符串比对函数
Dim i As Integer
Test = False
For i = 1 To Len(str2) - Len(str1) + 1
If Then
Test = True: Exit For
End If
Next i
End Function