Re: Creating a sorted file.
Try this:
vb.net Code:
Dim myNames() As String = File.ReadAllLines("C:\File Names.dat")
Dim sortedNames = (From name As String In myNames Order By name).ToArray
File.WriteAllLines("C:\File Names.dat", sortedNames)
Re: Creating a sorted file.
Umm... C# code:
C# Code:
string[] myNames = File.ReadAllLines("C:\\File Names.dat");
string[] sortedNames = (from name in myNames orderby name select name).ToArray();
File.WriteAllLines("C:\\File Names.dat", sortedNames);
Re: Creating a sorted file.
Thanks Predeep. I'm using VB5.0 I'm just looking for a simple bubble sort routine to open an existing file and create a new sorted file.
Re: Creating a sorted file.
Here in the C# section might not be the best place to post a vb5 question, it could take a long time for someone to give you a usable responce.
Re: Creating a sorted file.
Thank you Scottlafoy
This is the first time I used the forum and didn't realize I was in the C# section.
I'll repost in the right section if I can figure out this forum.
Re: Creating a sorted file.
Try something like this:
(not tested code)
vb Code:
Private Sub SortArray(ByRef TheArray() As String)
Dim temp As String, i As Integer, j As Integer
For i = 0 To UBound(TheArray)
For j = i To UBound(TheArray)
If TheArray(i) > TheArray(j) Then
temp = TheArray(i)
TheArray(i) = TheArray(j)
TheArray(j) = temp
End If
Next
Next
End Sub
Re: Creating a sorted file.
Re: Creating a sorted file.
Based on Rhino's idea in this post: http://www.vbforums.com/showpost.php...34&postcount=2
Code:
Option Explicit
Private Sub Form_Load()
Dim strTemp As String
Dim FF As Integer
FF = FreeFile '~~> Get free file handle
Open "c:\abc.txt" For Input As #FF '~~~> open the file for reading data
While Not EOF(FF)
Line Input #FF, strTemp
List1.AddItem strTemp '~~~> Adding the names to the list
Wend
Close #FF
Open "c:\abc.txt" For Output As #FF '~~~>Saving back, the sorted names
Dim i As Integer
For i = 0 To List1.ListCount - 1
Print #FF, List1.List(i)
Next
Close #FF
MsgBox "finished"
End Sub
List1's Sorted property was set to True at design time :wave: