• We just launched and are currently in beta. Join us as we build and grow the community.

File Content Sorter in VB.NET

Hidden-Content

Content Audit Wizard
H Rep
0
0
0
Rep
0
H Vouches
0
0
0
Vouches
0
Posts
40
Likes
42
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
This tutorial will teach you how to create a program that sorts the content of file in vb.net.

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

    (

    )

  8. FileOpen(

    1

    , Current, OpenMode.

    Output

    )
  9. For

    Each

    curWord As

    String

    In

    myWords
  10. PrintLine(

    1

    , curWord)
  11. Next
  12. FileClose(

    )
  13. CloseApp(

    )
  14. 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

Output:

sortoutput.png


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 Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]

Add and Follow me on Facebook: https://www.facebook.com/donzzsky

Visit and like my page on Facebook at: https://www.facebook.com/BermzISware


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,292

324,135

324,143

Top