|
-
Nov 13th, 2000, 11:50 AM
#1
Hi.
Can someone give me the code to create a directory so that this code works,
Code:
a = App.Path & "\Basedados\" & (j + 1) & ".txt"
Open a For Input As #(j + 1)
this gives me an eror bacause i don´t have in the directory c:\MyProgram\, the "basedados" subdir, i have to create it manualy, but i whant that the program create the subdir automatecly how can i do that ?
numibesi
-
Nov 13th, 2000, 11:58 AM
#2
Frenzied Member
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Nov 13th, 2000, 12:24 PM
#3
I was using that, dâ
I was using that but here it is
Code:
Private Sub Save_Click()
Open.Checked = False
Save.Checked = True
MkDir (App.Path & "\BaseDados\")
For j = 0 To 3
a = App.Path & "\BaseDados\" & (j + 1) & ".txt"
Open a For Output As #(j + 1)
For i = 1 To Grid1.Rows - 2
Grid1.Row = i
Grid1.Col = j
Print #(j + 1), Grid1.Text
Next i
Close #(j + 1)
Next j
End Sub
everyting thing is fine until you save it more than once, ex: The first time you save enveriting is ok, the you change the data etc.. you click to save again and it gives you an "path\...." error so i tried this error andler,
Code:
Private Sub Save_Click()
On Err GoTo er:
Open.Checked = False
Save.Checked = True
MkDir (App.Path & "\BaseDados\")
For j = 0 To 3
a = App.Path & "\BaseDados\" & (j + 1) & ".txt"
Open a For Output As #(j + 1)
For i = 1 To Grid1.Rows - 2
Grid1.Row = i
Grid1.Col = j
Print #(j + 1), Grid1.Text
Next i
Close #(j + 1)
Next j
er:
Kill (App.Path & "\BaseDados\")
Save_Click
End Sub
but sometimes it fails too any idea, plase.
numibesi
-
Nov 13th, 2000, 12:56 PM
#4
Lively Member
How about this?
OK, if every time you try to run the program it uses MkDir to create a directory, after the first running of the app, that directory will exist. Every subsequent time the app is run the MkDir will try to make a directory that's already there. This causes an error. To get rid of the error you first need to check if the file is already in that directory like so:
Code:
If Dir(App.Path & "\BaseDados\") = "" Then 'the directory doesn't exist so create it
MkDir App.Path & "\BaseDados\"
End If
is that any help?
-
Nov 13th, 2000, 12:59 PM
#5
Lively Member
PS...
Plus, in your error handler, I don't think you can use Kill on a directory that has files in it. I'm not positive about that, but it could be a possible explanation for why the error handler doesn't always work. In stead of anticipating errors and adding an error handler, it's far better practice to not put in the error in the first place Error handlers are for when things go wrong in my view...
Sam
-
Nov 13th, 2000, 01:54 PM
#6
To Samdv
That was why i puted an error handler to handle error's, "Whent the thing went wrong", but thank´s i have solved the problem with your code and some of mine.
numibesi
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
|