Computer Science Canada Saving to Binary |
Author: | GlobeTrotter [ Fri Mar 11, 2005 12:58 pm ] |
Post subject: | Saving to Binary |
Rather than saving to a text file, I'd like to save to a binary file. Can anyone tell me how this is done? Please? |
Author: | Brightguy [ Fri Mar 11, 2005 8:33 pm ] | ||
Post subject: | Re: Saving to Binary | ||
No problem...
"byteNumber" is where in the file you want to write the data in "variable". |
Author: | GlobeTrotter [ Sat Mar 12, 2005 1:05 pm ] |
Post subject: | |
Does it have to be a .bin file? |
Author: | Brightguy [ Sat Mar 12, 2005 7:26 pm ] |
Post subject: | Re: Saving to Binary |
Nope, you can choose any filename that you want. If the file doesn't exist it will be created. |
Author: | GlobeTrotter [ Sun Mar 20, 2005 8:45 pm ] |
Post subject: | |
Another question, similar to this... how would I get a popup thing/file browser so that the user can choose where they want the file saved? |
Author: | Brightguy [ Mon Mar 21, 2005 12:14 am ] |
Post subject: | Re: Saving to Binary |
You can use the CommonDialog control for that. Press Ctrl+T to bring up the components dialog box, and select "Microsoft Common Dialog Control" to add the control into your project. To show a "Save As" dialog box, use the ShowSave method. The user's selection is returned in the FileName property. |
Author: | GlobeTrotter [ Tue Mar 22, 2005 7:33 pm ] | ||||
Post subject: | |||||
Thanks, I kind of got it working with this code:
But how do I make it so that they can only save it as a certain file type? Same thing with opening files. I'd also like to know if this code is right...
When I save a file with the first code, and try opening it with the second, Var does not get the value "testing". Is Get the right command? Thanks for all the help so far, btw |
Author: | Brightguy [ Thu Mar 24, 2005 10:52 pm ] | ||||
Post subject: | Re: Saving to Binary | ||||
What you have is correct. However, since Var is a variable-length string, using Get will read the number of characters in Var (which in that case was 0). A solution would be to define Var as a fixed-length string:
Another solution would be to open the file in Random mode, where all data is stored in numbered "records", and it will automatically store the length of variable-length strings. (When using Get in random access mode, rather than the byte number you use the record number you want to read.) As for opening/saving a specific file type, set the Filter property, like so:
|
Author: | GlobeTrotter [ Thu Mar 24, 2005 11:24 pm ] |
Post subject: | |
Thanks. Say I wanted to save a file that included a bunch of variables, such as Name, Address, etc. The file would only hold one person's stuff, not a bunch. therefore, I guess the records wouldn't be the right use, correct? What should I do? |
Author: | Brightguy [ Sat Mar 26, 2005 12:24 pm ] |
Post subject: | Re: Saving to Binary |
You could just have each variable stored in a separate record. By default all records are stored with 127 bytes I believe (so you'll get an error if a string goes over that). But you can change it by adding Len = recordlength at the end of your open statement. Or you could declare your own "Person" type that includes all the variables you want to store, and then store all the variables in a single record. |