Open and save codes

almubarmeg
05-10-2003, 12:07 PM
Dear friends,

1-What is the problem with this "Open window code"

Private Sub lbopen_Click()

cmdlb.Enabled = True

With dlgCommonDialog
.DialogTitle = "Open"
.CancelError = False
.Filter = " (*.txt)|*.txt"
.ShowOpen
If Len(.FileName) = 0 Then
Exit Sub
End If

ofile = .FileName

On Error GoTo Errorhandle

Open ofile For Input As #1
Print "File path ", ofile
ok:
Exit Sub

Errorhandle:
MsgBox " The file is already open "

Resume ok

End With

The problem is the code can't check if the file has been opened or not..why ?

2- how can i write a code for save window


any help ?

piggybank1974
05-10-2003, 12:18 PM
I may or may not have a solution :huh:

use the freefile command e.g.


Dim Number as Long

Number = freeFile

Open ofile For Input As #Number
'your code
close #Number


Now you could do this with API, But You may or may not beble to check it this way

if Number = 1 then
'the code
end if


the first file that you open is using as an index number of one, so with that if you check for that it must be open, again just a subjection.

the pig..

almubarmeg
05-10-2003, 12:53 PM
UNfortunately, i didn't work.

Iceplug
05-10-2003, 01:15 PM
If the file is already open, then you can't open it. :-\
Take out the error handler and see what error you get. (Hopefully you won't get a File already open error). :)

almubarmeg
05-10-2003, 01:25 PM
What i want is to not open the file again during run time

piggybank1974
05-10-2003, 05:49 PM
Well put it in the load section of your main form ot create a Module(Bas File) and in there create some thing like this:



sub Main
'Load the file data here

'Call your main form
FrmMain.show
end sub


Also you need to change the Project Properties / Setup Object to Sub Main.

the pig.

Banjo
05-11-2003, 12:35 PM
Also:
Open ofile For Input As #1
Print "File path ", ofile
You are opening for Input and then trying to Output to it.

And as for your question about Saving, use the ShowSave function of the CommonDialog control.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum