Skip to main content

File Content Sorter in VB.NET

This tutorial will teach you how to create a program that sorts the content of file in

Now, let's start this tutorial!

1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.

2. Next, add one button named openBTN and an OpenFileDialog1 that we will use to open a particular file such as text file.

3. Now, we will do the coding.

We will first import the IO library.

  1. Imports System.IO

Then, we will declare the following variables below that we will use for a sub procedure.

  1. Dim Current As String
  2. Dim myWords As New List(Of String)
  3. Dim word() As String
  4. Dim I As Integer = 0
  5. Dim file As String()

We will then create a sub procedure named ProcessFile() to sort the content of the text file that we will going to choose.

  1. Private Sub ProcessFile()
  2. word = System.IO.File.ReadAllLines(Current)
  3. For Each Temp As String In word
  4. myWords.Add(word(I))
  5. I += 1
  6. Next
  7. myWords.Sort()
  9. FileOpen(1, Current, OpenMode.Output)
  10. For Each curWord As String In myWords
  11. PrintLine(1, curWord)
  12. Next
  13. FileClose()
  14. CloseApp()
  15. End Sub

And an OpenFile() sub procedure to trigger opening any text files.

  1. Private Sub OpenFile()
  2. With OpenFileDialog1
  3. .Filter = "Text Files (*.txt)|*.txt|Rich Text Files (*.rtf)|*.rtf"
  4. .FileName = ""
  5. OpenFileDialog1.ShowDialog()
  6. End With
  7. End Sub

Lastly, put this code in your Form_Load.

  1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2. file = Environment.GetCommandLineArgs()
  3. If file.Length > 1 Then
  4. Current = (file(1).ToString())
  5. ProcessFile()
  6. Else
  7. OpenFile()
  8. End If
  9. End Sub



For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.

Best Regards,

Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]

Visit and like my page on Facebook at:

Subscribe at my YouTube Channel at: Ser Bermz

Visit my website at:

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.


1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.