Results 1 to 1 of 1

Hybrid View

  1. #1
    Expfighter's Avatar
    Join Date
    Nov 2014
    Gender
    male
    Location
    On planet earth
    Posts
    58
    Reputation
    10
    Thanks
    241
    My Mood
    Cheerful

    Lightbulb Reading files line by line

    This tutorial is for when you would like to make a cracker or something like that, and would like to read any file, putting content in a listbox or something

    Ill be using:
    VB.NET
    Visual Studio 2013 Express (Other versions should be fine too)
    A listbox for the contents
    A .txt file (can be any extension)

    Step 1
    Create a new project
    File > New Project Or Start menu > Create new project

    Step 2
    Make your layout / program
    Im putting down a listbox and a button for opening the file

     


    Step 3
    Code your button to open a file
    Drag a "OpenFileDialog" into your form, when you have a openfiledialog double click your button to open its code
    This should be the code for your button:

    Code:
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        OpenFileDialog1.ShowDialog()
    End Sub
    Double click OpenFileDialog1 (In Form1's Design Tab)
    Put this code in:
    Replace (dot) with a dot, because MPGH thinks im trying to post links

    Code:
    'Create a streamreader (To read the file)
    Dim streamreader As System(dot)IO.StreamReader = New System(dot)IO.StreamReader(OpenFileDialog1.FileName)
    'Create a variable that keeps track of which line we are at
    Dim line As Integer
    'Let our user know were ready to load his file (Pure for information)
    MessageBox.Show("Your file will be loaded!", "Info", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1)
    'Keep doing content till variable line is the same value as the amount of lines in the document
    Do Until line = System(dot)IO.File.ReadAllLines(OpenFileDialog1.FileName).Length
            'Add the current line to the listbox
            ListBox1.Items.Add(streamreader.ReadLine())
            'Add 1 up to line
            line = line + 1
    Loop
    To Moderators: If you can edit this thread, just replace the (dot)'s with a real dot and remove the alert

    Step 4
    Test it out!
    Hit that start button, and see what it does!

     

    Menu:


    Load screen:


    Loaded:

    Attached Thumbnails Attached Thumbnails
    Capture.JPG  

    Menu.JPG  

    Select.JPG  

    Loaded.JPG  


Similar Threads

  1. Replies: 3
    Last Post: 07-05-2012, 10:01 PM
  2. [Help] Read File per line (but no fstream!)
    By Code[VB] in forum C++/C Programming
    Replies: 3
    Last Post: 10-05-2011, 01:58 PM
  3. [Help] Read a textfile line-by-line.
    By ³²³ in forum Visual Basic Programming
    Replies: 6
    Last Post: 04-16-2011, 10:43 PM
  4. [Question]Reading in ftp by line
    By .Celtics in forum Visual Basic Programming
    Replies: 24
    Last Post: 11-02-2010, 05:22 AM
  5. [Tutorial] Reading from the CMD line
    By shercipher in forum C++/C Programming
    Replies: 7
    Last Post: 04-04-2006, 12:49 PM

Tags for this Thread