Open TXT files in Visual Basic 
Author Message
 Open TXT files in Visual Basic

Hi. I want to open a TXT file with Visual Basic. This TXT
file was saved previously in MS-DOS Text format. How can I
open it?.


Tue, 06 Sep 2005 03:02:25 GMT  
 Open TXT files in Visual Basic


Quote:
>Hi. I want to open a TXT file with Visual Basic. This TXT
>file was saved previously in MS-DOS Text format. How can I
>open it?.

If by "open" you mean access the data contained within the file, you
can use VB's intrinsic I/O commands to open the file and get the data
into a string or byte array.  Have a look at the Open topic in your VB
help file for more info.  You might also want to look at the RTF
control as, I believe, it will bring the text in for you if you set
the correct properties.

HTH,
Bryan
____________________________________________________________
New Vision Software            "When the going gets weird,"
Bryan Stafford                   "the weird turn pro."

Microsoft MVP-Visual Basic     Fear and Loathing in LasVegas



Tue, 06 Sep 2005 03:29:27 GMT  
 Open TXT files in Visual Basic
Open "your_file.txt" For Input As #1
Do Until Eof(1)
Line Input #1, txt$
Text1 = Text1 & txt$ & vbCrLf
Loop
Close #1

You must set Text1.Multiline = True

Quote:

> Hi. I want to open a TXT file with Visual Basic. This TXT
> file was saved previously in MS-DOS Text format. How can I
> open it?.



Tue, 06 Sep 2005 04:48:33 GMT  
 Open TXT files in Visual Basic

Quote:
> Open "your_file.txt" For Input As #1
> Do Until Eof(1)
> Line Input #1, txt$
> Text1 = Text1 & txt$ & vbCrLf
> Loop
> Close #1

> You must set Text1.Multiline = True

Hi Joza...

This will give better performance....

Private Sub Command1_Click()
   Dim iFile As Integer
   iFile = FreeFile
   Open "your_file.txt" For Input As iFile
   Text1.Text = Input$(LOF(iFile), iFile)
   Close #iFile
End Sub

.... also, .... the line below creates an entirely new buffer and replaces the entire
contents of the textbox each time it runs... you can speed your loop up (assuming you
still want to loop) by changing the line below...

Quote:
> Text1 = Text1 & txt$ & vbCrLf

...well, it's easier to show the whole thing so...

Private Sub Command1_Click()
   Dim txt$
   Open "c:\temp\clsSysController.cls.bak" For Input As #1
   Text1.Text = ""
   Do Until EOF(1)
      Line Input #1, txt$
      Text1.SelText = txt$ & vbCrLf
   Loop
   Close #1
End Sub

--
Ken Halter - MS-MVP-VB - http://www.mvps.org/vbsight - Please keep it in the groups..



Tue, 06 Sep 2005 05:33:13 GMT  
 Open TXT files in Visual Basic
oops... posted the name of my test file.. that should be "your_file.txt" that we're trying
to open

--
Ken Halter - MS-MVP-VB - http://www.mvps.org/vbsight - Please keep it in the groups..



Tue, 06 Sep 2005 05:37:13 GMT  
 Open TXT files in Visual Basic
Hm... Very interest...
I agree with you, but example that I gave was for begginiers...


Wed, 07 Sep 2005 05:03:22 GMT  
 Open TXT files in Visual Basic


Quote:
> Hm... Very interest...
> I agree with you, but example that I gave was for begginiers...

That makes no sense.  You're saying that reading the file line by line in a
loop is "better for beginners" than reading the whole file at once?

Mike



Wed, 07 Sep 2005 10:21:43 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Opening .txt file in BASIC

2. Need some .txt files on learning Visual Basic

3. how to load a txt file in a string in visual basic

4. visual basic default Project Opening File Location

5. Open Secure PDF file in Visual Basic /w parameters

6. Opening pdf file at bookmark from visual basic

7. Visual Basic 5.0 and Opening Files

8. help opening dbf files in visual basic

9. Adding .TXT files to a VB program without the .TXT file

10. A request for help on Visual Basic Security - helpme.txt (1/1)

11. A request for help on security measures in Visual Basic - helpme.txt (1/1)

12. Question: Opening .txt file with vba

 

 
Powered by phpBB® Forum Software