|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (9 bit)
Join Date: Jan 2002
Location: Quebec, Canada
Posts: 426
|
open a txt document in visual basic
hey,
I've coded something to open a txt document but it takes so much time that it appears that the program isn'st responding but after a long time it will open the file. here is what I did. I don't know if it's possible to open the file in a second like in wordpad?? thanks Private Sub menuopen_Click() With CommonDialog1 .Filter = "Text (*.txt)|*.txt|All (*.*)|*.*" .FilterIndex = 1 .ShowOpen End With buffer = "" txteditor.Text = "" If CommonDialog1.filename <> "" Then Open CommonDialog1.filename For Input As #1 While Not EOF(1) Input #1, buffer txteditor.Text = txteditor.Text & buffer & vbCrLf Wend Close #1 filechange = False End If frmtxteditor.SetFocus End Sub I also tried this method, it works faster but it's not "that" fast Set fill = fso.getfile("c:\windows\general.txt") Set ts = fill.OpenAsTextStream(ForReading) While Not ts.atendofstream Text1.Text = Text1.Text & ts.readline & vbCrLf Wend Last edited by muTe; 12-22-2002 at 11:25 PM. |
|
|
|
|
|
#2 |
|
Professional gadfly
|
I tried that code and it work instantly. I would guess that the problem lies elsewhere.
There are a couple of things I would suggest, though. Always dim your variables, and use "Option Explicit" in the general declarations portion (top part) of your modules to force you to do that. Also, While...Wend loops are not used much anymore and should be replaced by Do...Loop. |
|
|
|
|
|
#3 |
|
Member (9 bit)
Join Date: Jan 2002
Location: Quebec, Canada
Posts: 426
|
Have you tried it with a big txt file (300k) ?
thanks Dim3x |
|
|
|
|
|
#4 |
|
Professional gadfly
|
It is slower with a larger file. First, I may be wrong here, but I think that programs like Word do not load everything instantly, especially for longer programs. I think that instead it loads the first few pages, and then keeps loading in the background after displaying what it already has.
Second, are you using just a normal text box, or a different kind of control? Editing large amounts of text is not a text box's strong suit. You may want to try a Rich Text Box or something like that instead. |
|
|
|
|
|
#5 |
|
Member (9 bit)
Join Date: Jan 2002
Location: Quebec, Canada
Posts: 426
|
I tried a textbox then a rich text box and it did the same thing. maybe you're right about text editors that only loads parts of the documents. if there's no other way to do it I'll let the codelike that. thanks
dim3x |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|