Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 12-22-2002, 11:20 PM   #1
Member (9 bit)
 
muTe's Avatar
 
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.
muTe is offline   Reply With Quote
Old 12-23-2002, 08:22 AM   #2
Professional gadfly
 
doctorgonzo's Avatar
 
Join Date: Jan 2002
Location: Minneapolis, MN
Posts: 6,364
Send a message via MSN to doctorgonzo
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.
doctorgonzo is offline   Reply With Quote
Old 12-23-2002, 03:41 PM   #3
Member (9 bit)
 
muTe's Avatar
 
Join Date: Jan 2002
Location: Quebec, Canada
Posts: 426
Have you tried it with a big txt file (300k) ?
thanks
Dim3x
muTe is offline   Reply With Quote
Old 12-23-2002, 04:01 PM   #4
Professional gadfly
 
doctorgonzo's Avatar
 
Join Date: Jan 2002
Location: Minneapolis, MN
Posts: 6,364
Send a message via MSN to doctorgonzo
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.
doctorgonzo is offline   Reply With Quote
Old 12-23-2002, 05:54 PM   #5
Member (9 bit)
 
muTe's Avatar
 
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
muTe is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 12:27 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2