Get a filename

bunze

Well-known member
Joined
Aug 4, 2005
Messages
52
Location
Adirolf
Programming Experience
1-3
I know this is .net forums but I'm already registered here..

in vb.net i need to put 1 word inside of a text file C:\name.txt i need to put a word like "john" in it.

Now in a vb6 program i need to read the text file. C:\name.txt and store its contents in a variable.

thanks in advance
 
Last edited:
This would be for write word John with VB.NET

VB.NET:
[COLOR=seagreen]'-------------Write to Text-----------------[/COLOR]
 
[SIZE=2][COLOR=#0000ff]
Dim[/COLOR][/SIZE][SIZE=2] oFile [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.IO.File
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] oWrite [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.IO.StreamWriter
oWrite = oFile.CreateText("C:\sample.txt")
oWrite.WriteLine("John")
oWrite.Close()
[/SIZE]


While in VB6 you could use Input$ function:
VB.NET:
[COLOR=seagreen]'-------------Read from Text--------------
[/COLOR]
Function ReadTextFile (filename$) As String
    Dim handle As Integer
    handle = FreeFile
    Open filename$ For Input As #handle
    FileText = Input$(LOF(handle), handle)
    Close #handle
End Function

Usage of this reusable procedure

VB.NET:
[COLOR=seagreen]'notice that this method is much faster than reading each single line of the file using a Line Input statements[/COLOR]
Text1.Text = ReadTextFile("c:\sample.txt")

HTH
Regards ;)
 
Back
Top