I am trying to write a program in VB.NET for file reading , by using File.ReadAllLines(file.txt), How i can show output the program is following,there is no code for showing output what i can use???

Program:

Imports System.IO 
Module Module1 
Sub Main() 
Dim array As String() = 
File.ReadAllLines("file.txt") 
Dim line As String 
For Each line In array 
    Dim length As Integer = line.Length 
Next 
End Sub 
End Module

You can output the linies by displaying them in a TextBox or RichTextBox control. As a matter of convenience, the RichTextBox control has methods to read/write files. or if this is for debugging purposes you can use Debug.WriteLine, or Console.WriteLine for console applications. In this case something like

Module Module1

    Sub Main()

        Dim lines() As String = System.IO.File.ReadAllLines(myfile)

        For Each line As String In lines
            Console.WriteLine(line)
        Next

    End Sub

End Module

Edited 4 Years Ago by Reverend Jim

Try this:

Imports System.IO 
Module Module1 
    Sub Main() 
        Dim array As String() = File.ReadAllLines("file.txt") 
        'Dim line As String this is unnecessary for-each dims the variable automatically
        For Each line In array 
            Dim length As Integer = line.Length
            'have a textbox on the form and set multiline to true
            'this line will output each line to the textbox.
            'if the lines are double spaced take off the vbnewline on the end.
            textbox1.text=textbox1.text & array & vbnewline
        Next 
    End Sub 
End Module

Edited 4 Years Ago by tinstaafl

This article has been dead for over six months. Start a new discussion instead.