实现上述功能的VB程序如下,请在划线处填入合适的代码。
Dim shuju As String, a(1 To
100) As String
Dim t As Integer, i As Integer, j As Integer, c
As String, p As Integer, temp As String, q as String Dim f As Boolean, n As Integer, k As Integer
'读取所有城市数据保存在变量shuju中,并显示在列表框List1中,代码略
t = Len(shuju)
i = 1: p = 0: j = 1
Do While i <= t
c = Mid(shuju, i, 1)
If c = "/" Or c = ";"
Then
p = p + 1
a(p) = j = i + 1
End If
i = i + 1
Loop
q = Text1.Text : n = Val(Text2.Text)
: i = 1
Do While i <= p \ 4 - 1
k = i
IfThen f = True Else f = False
For j = i + 1 To p \ 4
If a(4 * j - 3) = q Then
If Val(a(4
* j)) / Val(a(4 * j - 1)) >
Val(a(4 * k)) / Val(a(4 * k - 1)) Or Not f Then k =
j
End If
End If
Next j
If k <> i Then
temp = a(4 * k - 3): a(4 * k - 3) = a(4 * i
- 3): a(4 * i - 3) = temp
temp = a(4 * k - 2): a(4 * k - 2) = a(4 * i
- 2): a(4 * i - 2) = temp
temp = a(4 * k - 1): a(4 * k - 1) = a(4 * i
- 1): a(4 * i - 1) = temp temp = a(4 * k): a(4 * k) = a(4 * i): a(4 * i) = temp
End If
If Then
List2.AddItem a(4*i-3) & "/" & a(4*i-2) & "/" & Format(Val(a(4*i)) / Val(a(4*i-1)), "0.00%") & ";"
i = i + 1
Else
Exit Do
End If
Loop
End Sub