If the data are really a UDT, there is no need to parse it after loading it as a string.
See TYPE SET in your help file and the easy way will be pretty obvious to you.
For that matter, if you open RANDOM or BINARY, you can GET directly into a UDT.
Announcement
Collapse
No announcement yet.
Open File for Random or Binary
Collapse
X
-
Thanx Kev and Michael,
You both verified what I thought, and found the information on the "OPEN statement" page. I was looking at the "Binary Files" page.
I also discovered another mistake on my part (should've caught if I had looked closer at the help files) that in reality what I was doing with my real code was.- Check if File exists? (I had "Usb Database\FileName" in this case)
- Open the File as Binary (I goofed and had just "FileName") here
- Read in the data and parse it.
And what was happening (and I did not think about it correctly till now was)- Check if File exists? (Yep it exists)
- Open the File as Binary (I goofed and had just "FileName" so in turn a new file was created with the same name but a different folder)
- Read in the data and parse it. (Nothing to read in new file, so nothing to parse.)
Thanks again for the help. I knew it had to be something simple, and I was just missing what it was
Leave a comment:
-
>thats if I understand it correctly, but found nothing in the help files to verify this).
Look Harder. I found this under OPEN (PB/Win 8.03 help)
If you try to open a nonexistent file for OUTPUT, APPEND, RANDOM, or BINARY operations, a new file is automatically created.
Leave a comment:
-
Look up OPEN [..] ACCESS READ in the help file under the OPEN statement. An error should be generated if the file does not exist. Alternatively, you could check for it's existance using DIR$ or FindFirstFile before opening the file.
Leave a comment:
-
Open File for Random or Binary
I am having a small problem with files opened for Binary or for Random, that I believe the code below is showing me that if the file does not exist, then it creates the file (like Append would), and because I do not write anything to the file, I now have a file in my directory with 0 Kb.
(thats if I understand it correctly, but found nothing in the help files to verify this).
My problem is, that I open a file from a subdirectory, and read the information, and then close the file. But now I have a new 0Kb file in my main directory.
Is there a way around this? or do I have to go back to Open FileName for Input? so that a "Blank Copy of the File" is not created?
I would like to use Binary, because if I use "For Input" the help file says
UDT variables may not be used
Code:#COMPILE EXE #DIM ALL FUNCTION PBMAIN () AS LONG LOCAL FileName AS STRING LOCAL Index AS LONG LOCAL FileNo AS LONG LOCAL sFileBuffer AS STRING FileNo = FREEFILE 'Open database FileName = "03f0 Hewlett Packard.db" ' OPEN FileName FOR BINARY AS FileNo 'Get database into string OPEN FileName FOR RANDOM AS FileNo 'Get database into string GET$ FileNo, LOF(FileNo), sFileBuffer 'Close database CLOSE FileNo END FUNCTION
Tags: None
Leave a comment: