|
-
Oct 7th, 2006, 10:23 PM
#1
Thread Starter
New Member
[Resoved] Text Reader Help
hi!
i have a Text Editing software where i can load any .txt file.
this works perfectly just i want to get rid of the error message " file cannot be found" and replace it with a msg box saying some thing like "Windows cannot fild the file "abc" , please make sure you have typed the name correctly."
here is the code i have created
VB Code:
Private Sub cmdLoad_Click()
Dim strName As String
Dim strFile As String
Dim strTemp As String
strName = InputBox("Filename:") ' file name to load
Open "C:\" & strName & ".txt" For Input As #1 ' loaded file
strFile = ""
Do Until EOF(1)
Line Input #1, strTemp
strFile = strFile & strTemp & vbCrLf
Loop
txtout.Text = strFile 'print file to textbox
Close #1
End Sub
Thx in advance!!
Last edited by Mick Grey; Oct 7th, 2006 at 11:52 PM.
-
Oct 7th, 2006, 10:32 PM
#2
Re: Text Reader Help
VB Code:
strName = InputBox("Filename:")
if dir(strname) = "" then 'file not found
msgbox "File " & strname & " Not found"
exit sub
end if
' rest of your code
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Oct 7th, 2006, 11:21 PM
#3
Thread Starter
New Member
Re: Text Reader Help
Sorry but that didnt work
instead of the msg box poping up when it cant find a file it popups eveytime even the file is located in c:\ and nothing comes up in the text box this is how i placed ur code.
Sorry for the Trouble im still a noob with VB!!
VB Code:
Private Sub cmdLoad_Click()
Dim strName As String
Dim strFile As String
Dim strTemp As String
strName = InputBox("Filename:")
if dir(strname) = "" then 'file not found
msgbox "File " & strname & " Not found"
exit sub
end if
Open "C:\" & strName & ".txt" For Input As #1 ' loaded file
strFile = ""
Do Until EOF(1)
Line Input #1, strTemp
strFile = strFile & strTemp & vbCrLf
Loop
txtout.Text = strFile 'print file to textbox
Close #1
End Sub
ive also tryed other ways like this:
VB Code:
strName = InputBox("Filename:") ' file name to load
Open "C:\" & strName & ".txt" For Input As #1 ' loaded file
strFile = ""
If Dir(strName) = "" Then 'file not found
MsgBox "File " & strName & " Not found"
Exit Sub
End If
'rest of the code
Last edited by Mick Grey; Oct 7th, 2006 at 11:25 PM.
-
Oct 7th, 2006, 11:42 PM
#4
Re: Text Reader Help
VB Code:
strName = InputBox("Filename:")
[B]strName = "C:\" & strName & ".txt"[/B]
If Dir(strName) = "" Then 'file not found
MsgBox "File " & strName & " Not found"
Exit Sub
End If
[B]Open strName For [/B]Input As #1 ' loaded file
strFile = ""
Do Until EOF(1)
a small change, you need to have the full name for the file in the string
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Oct 7th, 2006, 11:51 PM
#5
Thread Starter
New Member
Re: Text Reader Help
thx , fix it
thx forthe fast reply too
-
Oct 8th, 2006, 06:01 AM
#6
Re: [Resoved] Text Reader Help
Just use a CommonDialog its easier.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|