我创建了一个.txt
包含 4 行的文件,其中包含以下几行:
4
1
3
2
然后我使用“Shell”对文件进行排序。结果排序:
1
2
3
4
最后我正在阅读排序文件并将每一行写入第二个文件,但它们以原始顺序出现!
请帮忙。
这是代码:
Option Explicit
Sub my_mac2()
Dim my_path, my_tmp_file, my_out_file, my_data_from_tmp, my_command As String
Dim my_tmp_file_num, my_out_file_num As Integer
my_path = "E:\MASAV\VBA\"
my_tmp_file = my_path & "_tmp.txt"
my_out_file = my_path & "_out.txt"
my_tmp_file_num = FreeFile()
Open my_tmp_file For Output As #my_tmp_file_num
Print #my_tmp_file_num, "4"
Print #my_tmp_file_num, "1"
Print #my_tmp_file_num, "3"
Print #my_tmp_file_num, "2"
Close #my_tmp_file_num
my_command = "sort " & my_path & "_tmp.txt /O " & my_path & "_tmp.txt"
Shell my_command, vbHide
my_tmp_file_num = FreeFile()
Open my_tmp_file For Input As #my_tmp_file_num
my_out_file_num = FreeFile()
Open my_out_file For Output As #my_out_file_num
While Not EOF(my_tmp_file_num)
Line Input #my_tmp_file_num, my_data_from_tmp
Print #my_out_file_num, my_data_from_tmp
Wend
Close #my_tmp_file_num
Close #my_out_file_num
End Sub