vb编程顺序文件中存放了若干个数,读入后从小到大排列,再重新写入文件
3个回答
展开全部
Private Sub Command1_Click()
Dim a() As Single, t As Single
Dim i As Integer, j As Integer, l As Integer, m As Integer
'读取文件的数据
Open "c:\test.txt" For Input As #1
ReDim a(LOF(1)) As Single
n = 0
Do Until EOF(1)
n = n + 1
Input #1, a(n)
Loop
Close #1
'进行数据排序
For i = 1 To n - 1
For j = i + 1 To n
If a(i) > a(j) Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next j
Next i
'把数据写入文件
Open "c:\test.txt" For Output As #1
For l = 1 To n
Print #1, a(l);
Next l
Close #1
End Sub
Dim a() As Single, t As Single
Dim i As Integer, j As Integer, l As Integer, m As Integer
'读取文件的数据
Open "c:\test.txt" For Input As #1
ReDim a(LOF(1)) As Single
n = 0
Do Until EOF(1)
n = n + 1
Input #1, a(n)
Loop
Close #1
'进行数据排序
For i = 1 To n - 1
For j = i + 1 To n
If a(i) > a(j) Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next j
Next i
'把数据写入文件
Open "c:\test.txt" For Output As #1
For l = 1 To n
Print #1, a(l);
Next l
Close #1
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询