ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Adding text file to a user form? (https://www.excelbanter.com/excel-programming/322054-adding-text-file-user-form.html)

Chip[_3_]

Adding text file to a user form?
 
I have made many user forms in the past. And I know you can have an
image show up in a user form. I am wondering if there is any way in
which I can show to the user the contents of a text file (.txt) while
they are making a choice in the user form (basically the text files
could be one of two types and I want the user to be able to see it and
then tell my macro which one it is). The text file will change each
time, because in the previous dialog box I have them find the text file
on their computer. Thanks in advance.


Tom Ogilvy

Adding text file to a user form?
 
You could read in the text file and put the text in a textbox.

--
Regards,
Tom Ogilvy

"Chip" wrote in message
ps.com...
I have made many user forms in the past. And I know you can have an
image show up in a user form. I am wondering if there is any way in
which I can show to the user the contents of a text file (.txt) while
they are making a choice in the user form (basically the text files
could be one of two types and I want the user to be able to see it and
then tell my macro which one it is). The text file will change each
time, because in the previous dialog box I have them find the text file
on their computer. Thanks in advance.




Chip[_3_]

Adding text file to a user form?
 
I'm not sure what you mean? How would I go about doing that? Any code
to get me started would be great.


Chip[_3_]

Adding text file to a user form?
 
By the way, Tom you are the man


Tom Ogilvy

Adding text file to a user form?
 
Use Low Level fileio

Private Sub CommandButton1_Click()
strFile = "C:\xltext\myfile.txt"
hFile = FreeFile

Open strFile For Input As hFile

Do While Not EOF(hFile)
Line Input #hFile, strLine
sStr = sStr & strLine & Chr(10)
Loop
Close #hFile
UserForm1.TextBox1.Text = sStr
End Sub


RBSmissert posted this like which has some added information on low level
file io

http://www.applecore99.com/gen/gen029.asp


Of course, if your text file is large, you may only want to read in a couple
of lines


Private Sub CommandButton1_Click()
Dim strFile as String, hFile as long
Dim strLine as String, icnt as long
strFile = "C:\xltext\myfile.txt"
hFile = FreeFile

Open strFile For Input As hFile
icnt = 0
Do While icnt < 5
Line Input #hFile, strLine
sStr = sStr & strLine & Chr(10)
icnt = icnt + 1
Loop
Close #hFile
UserForm1.TextBox1.Text = sStr
End Sub

--
Regards,
Tom Ogilvy


"Chip" wrote in message
oups.com...
I'm not sure what you mean? How would I go about doing that? Any code
to get me started would be great.




Tom Ogilvy

Adding text file to a user form?
 
Make sure the textbox property for multiline is set to true.

--
Regards,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
Use Low Level fileio

Private Sub CommandButton1_Click()
strFile = "C:\xltext\myfile.txt"
hFile = FreeFile

Open strFile For Input As hFile

Do While Not EOF(hFile)
Line Input #hFile, strLine
sStr = sStr & strLine & Chr(10)
Loop
Close #hFile
UserForm1.TextBox1.Text = sStr
End Sub


RBSmissert posted this like which has some added information on low level
file io

http://www.applecore99.com/gen/gen029.asp


Of course, if your text file is large, you may only want to read in a

couple
of lines


Private Sub CommandButton1_Click()
Dim strFile as String, hFile as long
Dim strLine as String, icnt as long
strFile = "C:\xltext\myfile.txt"
hFile = FreeFile

Open strFile For Input As hFile
icnt = 0
Do While icnt < 5
Line Input #hFile, strLine
sStr = sStr & strLine & Chr(10)
icnt = icnt + 1
Loop
Close #hFile
UserForm1.TextBox1.Text = sStr
End Sub

--
Regards,
Tom Ogilvy


"Chip" wrote in message
oups.com...
I'm not sure what you mean? How would I go about doing that? Any code
to get me started would be great.






Chip[_3_]

Adding text file to a user form?
 
Got it. Thanks...That's pretty cool.


JaiJai

Adding text file to a user form?
 

All these 2 methods are reading the text file line by line. But I have
very large text file (over 1000KB) needed to be put on the text box. I
a bit waste time and maybe error .

Is there any methods that I can put this large text file on the tex
box, other than the reading text method?

--
JaiJa
-----------------------------------------------------------------------
JaiJai's Profile: http://www.excelforum.com/member.php...fo&userid=1948
View this thread: http://www.excelforum.com/showthread.php?threadid=34071


Tom Ogilvy

Adding text file to a user form?
 
Have you tried them?

That type of code reads in a file pretty fast.

there are ways to modify that to read in a file to a variable in one go.

--
Regards,
Tom Ogilvy

"JaiJai" wrote in
message ...

All these 2 methods are reading the text file line by line. But I have a
very large text file (over 1000KB) needed to be put on the text box. It
a bit waste time and maybe error .

Is there any methods that I can put this large text file on the text
box, other than the reading text method??


--
JaiJai
------------------------------------------------------------------------
JaiJai's Profile:

http://www.excelforum.com/member.php...o&userid=19484
View this thread: http://www.excelforum.com/showthread...hreadid=340711




JaiJai[_2_]

Adding text file to a user form?
 

Yes, I have tried the all and it really time consuming to read and write
line by line.
The attached file is the text file (large file size) that I want to put
on the textbox.

Are there any other good methods ?


+-------------------------------------------------------------------+
|Filename: CSV-htaa.zip |
|Download: http://www.excelforum.com/attachment.php?postid=3653 |
+-------------------------------------------------------------------+

--
JaiJai
------------------------------------------------------------------------
JaiJai's Profile: http://www.excelforum.com/member.php...o&userid=19484
View this thread: http://www.excelforum.com/showthread...hreadid=340711


Tom Ogilvy

Adding text file to a user form?
 
Private Sub CommandButton1_Click()
Dim sStr As String
strFile = "C:\Data6\CSV-htaa.txt"
Hfile = FreeFile

Open strFile For Input As Hfile
i = LOF(Hfile)
sStr = Input(i, #Hfile)
Close #Hfile
UserForm1.TextBox1.Text = sStr
UserForm1.Show
End Sub

give it a try.

--
Regards,
Tom Ogilvy

"JaiJai" wrote in
message ...

Yes, I have tried the all and it really time consuming to read and write
line by line.
The attached file is the text file (large file size) that I want to put
on the textbox.

Are there any other good methods ?


+-------------------------------------------------------------------+
|Filename: CSV-htaa.zip |
|Download: http://www.excelforum.com/attachment.php?postid=3653 |
+-------------------------------------------------------------------+

--
JaiJai
------------------------------------------------------------------------
JaiJai's Profile:

http://www.excelforum.com/member.php...o&userid=19484
View this thread: http://www.excelforum.com/showthread...hreadid=340711




Tom Ogilvy

Adding text file to a user form?
 
Make sure Multiline is set to true for the textbox. Also, probably want to
display the vertical scrollbar.

Private Sub CommandButton1_Click()
Dim sStr As String
strFile = "C:\Data6\CSV-htaa.txt"
Hfile = FreeFile

Open strFile For Input As Hfile
i = LOF(Hfile)
sStr = Input(i, #Hfile)
'Debug.Print Len(sStr)
Close #Hfile
With UserForm1.TextBox1
.MultiLine = True
.ScrollBars = fmScrollBarsVertical
.Text = sStr
End With
UserForm1.Show
End Sub

--
Regards,
Tom Ogilvy

"JaiJai" wrote in
message ...

Yes, I have tried the all and it really time consuming to read and write
line by line.
The attached file is the text file (large file size) that I want to put
on the textbox.

Are there any other good methods ?


+-------------------------------------------------------------------+
|Filename: CSV-htaa.zip |
|Download: http://www.excelforum.com/attachment.php?postid=3653 |
+-------------------------------------------------------------------+

--
JaiJai
------------------------------------------------------------------------
JaiJai's Profile:

http://www.excelforum.com/member.php...o&userid=19484
View this thread: http://www.excelforum.com/showthread...hreadid=340711




NickHK

Adding text file to a user form?
 
JaiJai,
Just put the whole file into a RichTextBox ?

NickHK

"JaiJai" wrote in
message ...

All these 2 methods are reading the text file line by line. But I have a
very large text file (over 1000KB) needed to be put on the text box. It
a bit waste time and maybe error .

Is there any methods that I can put this large text file on the text
box, other than the reading text method??


--
JaiJai
------------------------------------------------------------------------
JaiJai's Profile:

http://www.excelforum.com/member.php...o&userid=19484
View this thread: http://www.excelforum.com/showthread...hreadid=340711





All times are GMT +1. The time now is 01:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com