为实现上述功能,小王编写如下VB程序,首先在Text1中输入两个满足条件的序列,数字之间用“,”隔开且以“,”结尾,单击按钮“Cod1”,在Text2中输出最小值所在序列中的位置,程序运行界面如下图所示。
Private Sub Cod1_Click( )
Dim s As String, ch As String
Dim i As Integer, j As Integer, n As Integer, c As Integer
Dim a(100) As Integer
s = Text1.Text: c = 0: n = 0
For i = 1 To Len(s)
ch = Mid(s, i, 1)
If ch >= "0" And ch <= "9" Then
Else
n = n + 1
c = 0
End If
Next i
i = 1: j = n
Do While
m = (i + j) \ 2
If a(m) > a(i) Then
i = m
Else
j = m
End If
Loop
End Sub