-
creating a file if it does not exist, but not wipe it if it does?
Hey Guys,
I'm making a programme at the minute that requires a password to be stored in a text file. When the form to enter the password loads, it runs a length check on the file to see if there's actually a password in it. My problem is that I retrieve the data with the input statement, but if the file doesnt actually exist then this brings up the error (i know why thats not a problem).
To get around this error i have the code as follows:
Code:
Dim filenumber as integer
Filenumber = FreeFile()
Open app.path & "\file.ext" for append as #filenumber
close #Filenumber
open app.path & "\file.ext" for input as #filenumber
***Code to extract data goes here***
Now I have to add the append line so that if the file does not exist, it is created, but if it does exist, the file is not altered. Now to me, despite the fact it does what it's supposed to, it looks stupid. Is there an easier method to create a file that doesnt exist, but if it does exist, not wipe it?
Many Thanks in advance,
el__sid
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
-
You could just use an 'if' statement.
There is some code on this site in the freevbcode section that has a function 'pathexists', which will tell you if the file you are trying to open already exits. Then you and if or select case.
I think you could probably do the same with an FileLen() statement, and see if it returns an error??
-
See Dir - returns zero length string if file does not exist
-
will look into this, thanks
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
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
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|