load txt file into a textbox
does anyone know a quick way to load a txt file into a textbox? the .txt file has a pretty long string in it, so that's why i would like to just load it into a textbox to make it easier on me. I cant find the code to load a txt file into a textbox for some reason, even though i thought it would be easy.
Re: load txt file into a textbox
VB Code:
Public Sub DocToTxt(Path As String, TxtBox As TextBox)
Dim ff As Integer
Dim StrLine As String
Open Path For Input As ff
Do Until EOF(ff)
Line Input #ff, StrLine
TxtBox.Text = TxtBox.Text & StrLine & vbNewLine
Loop
Close ff
End Sub
Try that.
Re: load txt file into a textbox
That should work, except that it is about the slowest possible way to do it.
Quote:
Originally Posted by Whatupdoc
does anyone know a quick way to load a txt file into a textbox?
VB Code:
Public Sub DocToTxt(ByRef pszFilename As String, ByRef pTextbox As Textbox)
Dim hFile As Long
hFile = FreeFile()
Open pszFilename For Binary Access Read Lock Write As #hFile
pTextbox.Text = Input(hFile, LOF(hFile))
Close #hFile
End Sub
Re: load txt file into a textbox
Quote:
Originally Posted by penagate
That should work, except that it is about the slowest possible way to do it.
VB Code:
Public Sub DocToTxt(ByRef pszFilename As String, ByRef pTextbox As Textbox)
Dim hFile As Long
hFile = FreeFile()
Open pszFilename For Binary Access Read Lock Write As #hFile
pTextbox.Text = Input(hFile, LOF(hFile))
Close #hFile
End Sub
Sorry, it's the only way I knew how to do it :p Yes that would be faster, although I would of never thought of that.
Re: load txt file into a textbox
Re: load txt file into a textbox
it doesnt seem to work. i have that function in a module then i called it from form_load using this code: Call DocToTxt(App.Path & "\data.txt", Text3)
there is a file called data.txt in the same directory as the program and there's also a textbox called text3.text. I get an error "Bad file name or number" then it points to pTextbox.Text = Input(hFile, LOF(hFile))
Re: load txt file into a textbox
Sorry I had the parameters round the wrong way
It should be
VB Code:
pTextbox.Text = Input$(LOF(hFile), hFile)