|
-
Jan 24th, 2010, 11:37 AM
#1
Thread Starter
New Member
Creating a sorted file.
I wrote a membership program for our local senior center but I can't figure out how to create a alphabetized file so I can send it to a printer.
For instance:
File Names.dat contains
Mary
Jack
Sally
Andrew
I need to create a new alphabetized file.
I know a simple bubble sort routine will do this but I don't know how to do it. Can someone please help me?
-
Jan 24th, 2010, 11:52 AM
#2
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)
-
Jan 24th, 2010, 12:03 PM
#3
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);
-
Jan 24th, 2010, 01:21 PM
#4
Thread Starter
New Member
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.
-
Jan 24th, 2010, 02:43 PM
#5
Addicted Member
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.
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN
-
Jan 24th, 2010, 06:14 PM
#6
Thread Starter
New Member
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.
-
Jan 25th, 2010, 02:27 AM
#7
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
-
Jan 25th, 2010, 04:08 AM
#8
Re: Creating a sorted file.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 25th, 2010, 05:08 AM
#9
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
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|