how to get the contents of a text file into a variable in vb 6.0?
any help?
Printable View
how to get the contents of a text file into a variable in vb 6.0?
any help?
You ned to Open the file for reading and store its contents into the variable :
Something like ;
Code:Dim FileName1 As String 'holds first file path
Dim FileH1 As Integer 'file handle 1
Dim strInOut As String 'holds input
FileName1 = "E:\Test.txt" 'path to 1st file
Open FileName1 For Binary Access Read As #FileH1 'open file
'read the info line by line
strInOut = Space$(LOF(1))
Get #FileH1, , strInOut
Close #FileH1 'close the handles
You could also open it for input and use the Input # method to read the entire file into a variable.
thank you for your response...well i used this...it works...
Code:Set ftxt = fs.CreateTextFile("D:\xxx\yy.txt", True)
textperl = "initialized text"
Open "D:\xxx\yy.txt" For Input As #1
While Not EOF(1)
Input #1, MyData
value = MyData
somevariable = somevariable & vbNewLine & value
Wend
Debug.Print textperl
Close #1
Set ftxt = Nothing