Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

quickest way to load textfile into a textbox

Status
Not open for further replies.

ptmcs

Technical User
Joined
Oct 1, 2004
Messages
38
Location
GB
Whats the quickest way to load text into a
textbox in vb5?
DOn't want to use RichTextBox
Many thanks
 
I'm not sure, but does this work?

textmessage = "blablabla..."
txtBox.text = testmessage

--------------------------------------
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
 
Also be sure to put the txtbox.multiline value to True...

--------------------------------------
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
 
sorry - as in load in from a file into a textbox...

Have opened a file:
Open fullpathfilename For Input As #1

and have tried both the following bits of code:

Do While Not EOF(1)
Input #1, lineoftext
Form1.Text1.Text = Form1.Text1.Text + lineoftext
Loop

and

Form1.Text1.Text = Input(LOF(1), #1)

but both lose the carriage return lines feeds from the
file / tabs etc etc....

could do something in the above loop but surely there's
a simple one liner for this?

 
and if you add a vbcrlf in the loop like this?

Code:
Do While Not EOF(1)
  Input #1, lineoftext
  Form1.Text1.Text = Form1.Text1.Text + lineoftext + vbcrlf
Loop

--------------------------------------
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
 
Just a quick question: why "Don't want to use RichTextBox"?
 
You may also want to use the Line Input command instead of Input. Line Input reads from the file until it sees a CR LF. The Input command is slightly different.
 
>why "Don't want to use RichTextBox"?
Probably to avoid RTB ocx dependency.

Instead of reading the file line-by-line, you can also read the whole text file at once like this.
___
[tt]
Open "C:\scandisk.log" For Binary As #1
Text1 = Input(LOF(1), 1)
Close #1[/tt]
 
pxtanic has already tried and rejected Input(LOF(1), 1)
 
oops! I didn't see that. I think, its again a CR/LF issue.

pxtanic, try this code. Not just a one-liner code but I hope it would work.
___
[tt]
Dim S As String
Open Filename For Binary As #1
S = Input(LOF(1), 1)
Close #1
S = Replace$(S, vbCrLf, vbCr)
S = Replace$(S, vbLf, vbCr)
S = Replace$(S, vbCr, vbCrLf)
Text1.Text = S[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top