Re: What Does This Code Do?
It extracts the resource and writes it to the file
Re: What Does This Code Do?
"Writes it to the file" means writes it to the GIF file Hello.gif? But Hello.gif already exists in the directory in which the app using the resource file resides; so what's the use of writing it to the file?
Re: What Does This Code Do?
Yes thats whats its doing, overwritting the hello.gif file if it already exists too.
Re: What Does This Code Do?
Quote:
Originally Posted by arpan_de
"Writes it to the file" means writes it to the GIF file Hello.gif? But Hello.gif already exists in the directory in which the app using the resource file resides; so what's the use of writing it to the file?
A check should be made to see if the file exists. If it does not, then extact the resource file and write it. Simple.
Re: What Does This Code Do?
OK....fine....I have been trying to write to a text file using LoadResString but it generates the following error:
Resource with identifier '101' not found.
There is a Custom Resource whose Id is set to 101 but still VB generates the above error. Where am I erring? This is the code:
Code:
Open App.Path & "\Try.txt" For Output As #1
LoadResString ("101")
Print #1, "VBForums"
Close #1
Re: What Does This Code Do?
LoadResString is to read the resource, not write to it.
Re: What Does This Code Do?
Assign LoadRestring to a variable. Don't put 101 in quotes, though that isn't the error.
Re: What Does This Code Do?
Actually the app has a ComboBox & a CommandButton. When a user selects an option from the ComboBox & clicks the CommandButton, I want to write the selected option in a text file. For e.g. if the ComboBox has the following 5 options
Austria
Bahamas
China
Denmark
Egypt
& the user selects, say, Denmark, then the text file should be populated with Denmark. Next time if the user changes the option to, say, China, then the text file should be over-written with China. How do I go about it?
The text file gets created when the app starts but I guess to use the text file as a Custom Resource, the text file cannot be empty, isn't it? The empty text file got created but when I tried to add it as a Custom Resource using the Resource Editor, it didn't get added. Then I added some text in the text file & when I tried to add that text file as a Custom Resource, this time a new resource got created in the Resource Editor.
Re: What Does This Code Do?
I understand you want to save settings/options to a text file and that is very simple. Overwriting it is also easy. I do not see how a resoruce file will be helpful in this case.
To overwrite a text file, simply: Open path\file For Output As #ff. Replace ff with return value of VB's FreeFile() function. The file is immediately overwritten. If you add nothing to the file, it becomes zero-length. Don't forget to close the file when done writing to it.
Re: What Does This Code Do?
I want to add the text file as a resource so that users can't tamper with the contents of the text file. What if a user opens the text file & types, say, Russia, when there isn't any such option in the ComboBox? The app might crash due to this. So I want to keep the text file hidden from users by embedding it as a resource.
Re: What Does This Code Do?
Well, your resource file is compiled into your application when the application is compiled; therefore it is part of the exe. To edit your resource file means to edit your exe. Editing a compiled exe is not impossible, but is not recommended for many reasons. Storing settings for applications is very common, many applications do it using one of several ways:
1. INI file or CFG file, which is just a file but formatted or encrypted by you so the user won't know what they are looking at.
2. A password protected database file
3. The registry, again encrypting the entries
None of these solutions prevent the user from deleting the files or registry settings, none prevent the user from modifying bytes in the files or registry. That is where error checking comes in. If the saved settings are missing or corrupted, meaning can't be read by your program, then revert to "default" settings -- this is basically a set of routines in your code: VerifySettings & RestoreDefaultSettings. What goes in those routines is up to you.
Now if you insist on modifying your compiled exe, recommend searching this site and others -- again not recommended because you can corrupt your exe and/or trigger virus detectors, and probably some other nasty side effects too.