|
-
Oct 26th, 2006, 03:50 PM
#1
Thread Starter
Addicted Member
[RESOLVED] simple change... help me plz
Hello every one
i have a button to load two .txt files
if user select a file to load for example (test.txt)
automatically another file with the same name followed by the word first should be loaded which well be (testfirst.txt)in this case
THIS FILE SHOULD BE IN THE SAME DIRECTORY
this is my code:
VB Code:
With CommonDialog1
.CancelError = True
.Filter = "Text files (*.txt)|*.txt"
.DialogTitle = "Save the file..."
.ShowSave
If .filename <> "" Then
Form1.RichTextBox1.LoadFile .filename, rtfText
RichTextBox2.LoadFile Left(.filename, Len(.filename) - 4) & "first.txt", rtfText
txtFileText.Text = RichTextBox2.Text
End If
End With
what i need is that if user selected a file that don't have a partner an error message should appaer
how can do this?
i mean if user select file test.txt and the file testfirst.txt is not there then display error message
-
Oct 26th, 2006, 04:20 PM
#2
Re: simple change... help me plz
I want to ask a question, why are you Loading textfiles using ShowSave method??
Anyways, just try out this:
VB Code:
Dim fso As Object
Private Sub Command1_Click()
On Error GoTo errhand
With CommonDialog1
.CancelError = True
.Filter = "Text files (*.txt)|*.txt"
.DialogTitle = "Save the file..."
.ShowSave
If .FileName <> "" Then
If fso.fileexists(Left(.FileName, Len(.FileName) - 4) & "first.txt") Then
Form1.RichTextBox1.LoadFile .FileName, rtfText
RichTextBox2.LoadFile Left(.FileName, Len(.FileName) - 4) & "first.txt", rtfText
'txtFileText.Text = RichTextBox2.Text
Else
MsgBox "Partner File not present"
Exit Sub
End If
End If
End With
errhand:
If Err.Number = 32755 Then _
MsgBox "Cancel was selected"
End Sub
Private Sub Form_Load()
Set fso = CreateObject("Scripting.FileSystemObject")
End Sub
-
Oct 26th, 2006, 04:45 PM
#3
Addicted Member
Re: simple change... help me plz
Why you use a RichTextBox then sending it the textbox , you can load data to it directly
-
Oct 27th, 2006, 02:33 AM
#4
Thread Starter
Addicted Member
Re: simple change... help me plz
thanks Harsh Gupta
that is what i was looking for
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
|