數據文本中共四組數據,前兩組為坐標(X,Y),後兩組為存儲數據
目標文本中也是四組數據,前兩組是已按Y的升序排列好的坐標(X,Y),後兩組的數據需從數據文件中調出存入目標文件
文本的情況如下
1 2 5 0
11 25 8 0
12 21 3 0
5 2 4 0
排列後的情況
1 2 5 0
5 2 4 0
12 21 3 0
11 25 8 0
請各位大俠不吝賜教,小蝦米在此拜過!!
不清楚你说的前两组和后两组是什么东西...
Option Explicit
Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer
Dim a(1 To 4, 1 To 4) As Integer
Dim b(1 To 4) As Integer
Dim s As Integer
Open App.Path & "\vbtest.txt" For Input As #1
For i = 1 To 4
For j = 1 To 4
Input #1, a(i, j)
Next
Next
Close #1
Do
s = s + 1
For i = 1 To 4
b(i) = a(i, s)
Next
For i = 1 To 3
For j = 1 To 4 - i
If b(j) > b(j + 1) Then
k = b(j)
b(j) = b(j + 1)
b(j + 1) = k
End If
Next
Next
For i = 1 To 4
a(i, s) = b(i)
Next
If s = 4 Then Exit Do
Loop
For i = 1 To 4
For j = 1 To 4
Print a(i, j);
Next
Print
Next
End Sub