部分程序代码如下:
Public number As String '货物编号
Public na As String '货物名称
Public co As String '货物数量
Private Sub Command1Click()
Dim flag As Integer '查询结果标志
number = Text1.Text
na = Text2.Text
co = Text3.Text
If (number = "" And na = "" And co = "") Then MsgBox ("你还没有输入查询条件") ’第一种情况
If number <> ""Then ’第二种情况
flag = searchnum(1, n) 'n 表示总的货物种类数量
List1.AddItem id(flag) + n(flag) + c(flag)
If flag = -1 Then MsgBox ("查询无结果,检查是否输入有误")
End If
If na <> "" Then ‘第三种情况
flag = searchna(1, n) 'n 表示总的货物种类数量
List1.AddItem id(flag) + n(flag) + c(flag)
If flag = -1 Then MsgBox ("查询无结果,检查是否输入有误")
End If
If co <> "" Then ‘第四种情况
flag = searchco(1, n)
If flag = 0 Then MsgBox ("查询无结果,检查是否输入有误")
End If
End Sub
Function searchnum(i, j) As Integer '按编号查询函数
Dim m As Integer
Do While i <= j
m = Fix((i + j) / 2)
If id(m) = number Then
searchnum = m: Exit Function '查询到结果返回值并结束该函数
End If
If id(m) > number Then ① Else i = m + 1
Loop
searchnum = -1
End Function
Function searchna(i, j) As Integer '按名称查询函数
For i = 1 To j Step 1
If n(i) = na Then searchna = i: Exit Function
Next i
searchna = -1
End Function
Function searchco(i, j) As Integer '按货物数量函数
Dim f As Integer
f = 0
For i = 1 To j Step 1
If ② Then
List1.AddItem id(i) + n(i) + c(i)
f = 1
End If
Next i
searchco (f)
End Function
回答下列问题: