Click here to Skip to main content
15,919,613 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to read a text file with only 2 Lines and show them in text boxes here is my code (from MSDN) but cannot figure out how to continue:
VB
Dim fileReader As System.IO.StreamReader
fileReader = My.Computer.FileSystem.OpenTextFileReader("C:\Program Files\login.conf")
        Dim str1, str2 As String

and have the first Line of the txt file in variable str1 and second in str2 like this :
VB
textbox1.text = str1
textbox2.text = str2
Posted
Updated 28-Oct-15 5:22am
v2

 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 28-Oct-15 11:31am    
5ed.
—SA
Member 3892343 28-Oct-15 11:37am    
ty
ZurdoDev 28-Oct-15 11:54am    
You're welcome.
Maciej Los 28-Oct-15 15:43pm    
5ed!
Use File.ReadAllLines Method

VB
Public Shared Function ReadAllLines (
    path As String
) As String()



Example:

Imports System
Imports System.IO

Public Class Test
    Public Shared Sub Main()
        Dim path As String = "c:\temp\MyTest.txt"
        Dim sw As StreamWriter

        ' This text is added only once to the file.
        If File.Exists(path) = False Then

            ' Create a file to write to.
            Dim createText() As String = {"Hello", "And", "Welcome"}
            File.WriteAllLines(path, createText)
        End If

        ' This text is always added, making the file longer over time
        ' if it is not deleted.
        Dim appendText As String = "This is extra text" + Environment.NewLine
        File.AppendAllText(path, appendText)

        ' Open the file to read from.
        Dim readText() As String = File.ReadAllLines(path)
        Dim s As String
        For Each s In readText
            Console.WriteLine(s)
        Next
    End Sub
End Class


hope it would resolve your issue
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900