June 15, 2024, 10:58:34 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


String Resources

Started by Doc, July 10, 2011, 06:36:27 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Doc

Hey folks,
As a test for a project I have in mind, I'm trying to load a small text file (4 words) as an embedded resource, and then to display it in an edit control, using a button click event. I'm almost certain that I've done this before (probably in Creative), but for the life of me cannot get it to work now. Here's some code:

SUB OnClick_main_BUTTON1(),INT
'INT = LOADRESOURCE(identifier, type, var) <-- pattern code to load resources
def TextHolder:string
success = LOADRESOURCE("333", @RESSTRING, TextHolder) 'Does not work
'success = LOADRESOURCE(333, "STRING", TextHolder) 'Does not work
'success = LOADRESOURCE("333", "STRING", TextHolder) 'Does not work
'success = LOADRESOURCE("333", @RESSTRING, TextHolder) 'Does not work
SETCONTROLTEXT main,main_EDIT1, TextHolder

'SETCONTROLTEXT main,main_EDIT1,"Whoopie!!!" '<-- non resource text works just fine

RETURN FALSE
ENDSUB


I get no compile errors and the size of the executable seems to change enough to indicate that the little text file is being compiled. What to try next?
-Doc-

LarryMc

Doc,
What you ran into first appeared back in 2004.
Here's two solutions.

$main
openconsole
string A$
DECLARE "User32",LoadStringA(hInstance:int,ID:int,buffer:string,size:int),int

'read from a STRINGTABLE entry
IF LoadStringA(0,102,A$,255)=0 THEN A$="No Go"
print A$
IF LoadStringA(0,103,A$,255)=0 THEN A$="No Go"
print A$

'read from a RCDATA entry
IF LOADRESOURCE(101,@RESDATA,A$)=0 THEN A$="No Go"
print A$

waitcon
closeconsole
end
/*
101 RCDATA
BEGIN
  "From RCData"
END

STRINGTABLE
BEGIN
102 "Hello World"
103 "Works Doc"
END
*/


LarryMc

Note:
I think I'll look into adding STRINGTABLE resources to IWB+ :)

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Doc

Thank you for the info Larry.
I did a search in the forum and noticed something along the lines of what you posted as a solution, but thought that it may have been taken care of by now.

Do-able I guess, but it could get pretty messy if I wanted to use a hundred or so smallish String/IString resources, which is what I want to do with the project I have in mind.  :P

Appreciate ya!
-Doc-

LarryMc

Doing it with
STRINGTABLE
BEGIN
102 "Hello World"
103 "Works Doc"
END

only gives you three lines of overhead in the rc file

and substituting
IF LoadStringA(0,103,A$,255)=0 THEN A$="No Go"
for
IF LOADRESOURCE(101,@RESDATA,A$)=0 THEN A$="No Go"
is a wash.

I'm going to add "STRINGTABLE" to IWB+ at some point in the future.
You'd still have enter one line at a time.

If you create the STRINGTABLE entry yourself and you have all the stings listed somewhere you could write a little program to create the rc entry.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Doc

July 11, 2011, 08:32:44 AM #4 Last Edit: July 11, 2011, 08:56:19 AM by Doc
Thanks for the info Larry.

QuoteIf you create the STRINGTABLE entry yourself and you have all the stings listed somewhere you could write a little program to create the rc entry.

Okay... one way or another, I think I'll have to reassess what I want to do with the project at this point, just for the sake of design simplicity.

The way the thing is envisioned to work is to have -numerous- control (mostly checkbox and/or radio buttons) that they would select from, each of which tied to a group of small text resources with some "smarts" built in to determine what text to use in a given situation. The text resources would range from a short sentence or two, up to a few paragraphs of info. Once all of the selections are made, the user clicks a button and the program would build and display either a "printable" text or html file based on their selections and my predetermined programming choices.

Maybe I'll have a look at creating a useful tool one way or the other. :)

-Doc-

Edited again to add:
Maybe I can put all of my text and string data into a database and pull the info out from there... might be a better plan anyway. That adds the possibility to do data updates, without rebuilding the full program, any time I wish. :)

LarryMc

Or, you could do what I did in order to get rid of registry entries and put everything in one or more ini files.

I use multiple ini files and have similiar stuff grouped in a given file.
Reading and writing is pretty easy.  Plus I have a set of defaults in case the user messes up the working files some way.

Plus they are just plain text files.(no dbase overhead).

But regardless of how you do it your going to need:
1. The text itself
2. An ID number to identify it during retrival.

If you use a resource file embedded in you app you will have to update the whole thing including installer in order to change a single string.
with a dbase or ini file you could update separetly from the app.

dbase files have an awful lot of air in them because you have to set up you fields to hold the longest string or use memo fields.  still  a lot of air.

Because I don't use them, I don't know how or if an ini file will handle multiline strings.

The other thing is I don't know for a fact that a resource file has to be used from inside an exe file, since it is compiled separately from the rest of the source code.  Sapero can probably answer that one off the top of his head.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library