|
-
Nov 11th, 2005, 02:31 AM
#1
Thread Starter
Hyperactive Member
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.
-
Nov 11th, 2005, 02:44 AM
#2
Frenzied Member
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.
Age - 15 ::: Level - Advanced
If you find my post useful please ::Rate It::

-
Nov 11th, 2005, 03:03 AM
#3
Re: load txt file into a textbox
That should work, except that it is about the slowest possible way to do it.
 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
-
Nov 11th, 2005, 03:09 AM
#4
Frenzied Member
Re: load txt file into a textbox
 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 Yes that would be faster, although I would of never thought of that.
Age - 15 ::: Level - Advanced
If you find my post useful please ::Rate It::

-
Nov 11th, 2005, 03:10 AM
#5
Re: load txt file into a textbox
Well now you know!
-
Nov 11th, 2005, 11:46 AM
#6
Thread Starter
Hyperactive Member
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))
-
Nov 11th, 2005, 11:49 AM
#7
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)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|