Dynamic reference to constant

In my web project I have forms that are all prefixed with “frm” e.g. frmMainMenu, frmContactUs etc. I have a container with a help button on it and the container is added to every page on the site. When the user presses the help button I want a label to contain the help text which is held in dynamic constants. The constants are the same name as the page names except that instead of “frm” they have “lng” as the prefix and a suffix of “Help” e.g. lngMainMenuHelp, lngContactUsHelp etc.

I understand how I can get the page name and I can then tweak it to have a string variable that contains the name of the help constant but I cant see how I I can convert the string variable so that Xojo sees it as the name of the constant. Is this possible?

Can’t you move the constants to their own forms so each form has its own help text? The help button would just pull its text out of its parent window from a known constant.

Yeah I could but as I have over 90 forms it makes the management a bit more messy (in my view) if they are spread over lots of forms. I would have thought it should be possible to copy the variable from a string to another class (not sure if I am using the right terminology) as pseudo code below:

Dim myString as String = “lngMainMenuHelp”
Dim HelpTextConstant as New Constant
HelpTextConstant.Name = myString
Label1.Text = HelpTextConstant.Text

Obviously the code above is not meant to be real but I am trying to show the concept. I am sure it was possible to do this sort of thing in VB but cant remember how.

How much text is in the help?
The label has a help text property already. You could just paste the text for each form into that.
It even appears as a popup yellow field when the mouse is over the label, and it can hold quite a lot of text.

Sounds less messy than having it as a constant (unless you are doing dynamic strings for languages)

Thanks for the suggestion but we are using the dynamic constants for multi language and the text is long and will appear using a dialog popup.

There is no direct mechanism for what you’re trying to do since you cannot access a variable or constant buy its name through a string. Consider setting up a database instead.

How about using a method passing the name and a ByRef in some way? I seem to remember that was the way it was done in VB days.

You cannot access the value of the constant MyConstant through the string “MyConstant”. You can set up a database or a Dictionary, you can move each constant into its form, or you can set up a method with a giant select case. I can’t think of any other way to do it. Others might have different ideas.

BTW, in the IDE, you can assign a constant to a property through “#ConstantName”, but that’s a convenience that has no equivalent at runtime.

Ok what about doing it the way you suggested first. If on each page I create a constant called “lngHelpText”, how in the control container would I reference it, I tried “parent.lngHelpText” but it gave me an error.

The error is “The item does not exist”

It has to know that the constant is there, so the best way would be to set up a WebPage subclass, add the constant there, then use something like:

MySubclass( parent ).IngHelpText

You’d have to change the super of all your web pages, of course.

Perfect, thanks

Ug, I was in a rush and got that wrong. You need a class interface and method instead, then create the constant in each form. Sorry about that.

Ok, I will now go read the manuals to learn about how that works, thanks for all your help as always.

OK, I have a few minutes to myself now, so let me make sure I’ve defined the problem correctly.

You have a container which needs to display window-specific help text. The text is currently spread among dynamic constants so they can be localized, is that it?

The problem is, you want to figure out a way for your container to access the right help for the window it’s on, right?

I’m going to recommend a different approach. In your container, create a property, WindowHelpText (or whatever) and make sure it shows up in the Inspector. Every time you add that container to a window, assign the following value to that property: “#IngMainMenuHelp” (or whatever the right constant name is). This will get the value from the constant. At runtime, the control will pull the help text out of the WindowHelpText property.

That is such a cool idea, talk about turning the problem on its head. I can totally see your logic and am going to give it a try. Thanks.