|
-
Jan 10th, 2008, 03:22 PM
#1
Thread Starter
Frenzied Member
-
Jan 10th, 2008, 03:25 PM
#2
Re: What Does This Code Do?
It extracts the resource and writes it to the file
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 10th, 2008, 03:31 PM
#3
Thread Starter
Frenzied Member
-
Jan 10th, 2008, 03:33 PM
#4
Re: What Does This Code Do?
Yes thats whats its doing, overwritting the hello.gif file if it already exists too.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 10th, 2008, 03:36 PM
#5
Re: What Does This Code Do?
 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.
-
Jan 10th, 2008, 04:24 PM
#6
Thread Starter
Frenzied Member
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
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
-
Jan 10th, 2008, 04:27 PM
#7
Re: What Does This Code Do?
LoadResString is to read the resource, not write to it.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 10th, 2008, 04:28 PM
#8
Re: What Does This Code Do?
Assign LoadRestring to a variable. Don't put 101 in quotes, though that isn't the error.
-
Jan 10th, 2008, 04:44 PM
#9
Thread Starter
Frenzied Member
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.
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
-
Jan 10th, 2008, 05:24 PM
#10
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.
-
Jan 10th, 2008, 05:40 PM
#11
Thread Starter
Frenzied Member
-
Jan 10th, 2008, 06:53 PM
#12
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.
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
|