Page 1 of 1

Stringgadget: Caption is a variable?

Posted: Fri Aug 09, 2013 8:38 pm
by HarryT
Please help a beginner.

How can I update the display after assigning a new value to the caption variable defined in Formdesigner?
Is there some kind of "refresh" procedure?

Harry

Re: Stringgadget: Caption is a variable?

Posted: Sat Aug 10, 2013 4:13 am
by TI-994A
HarryT wrote:How can I update the display after assigning a new value to the caption variable defined in Formdesigner?
Hello HarryT. If you were to assign, for example, the text string "Hello" to the caption field of a StringGadget(), it should be reflected immediately within the Form Designer window itself.

However, if the <Caption is a variable?> option is selected, typing the word "Hello" in the caption field would only assign a string variable named "Hello" to that StringGadget(). This string variable "Hello" must then be programmatically assigned some text value to be displayed in the StringGadget(), like this:

Code: Select all

Hello.s = "Some text for the caption"
But this cannot be done from within the Form Designer, or even when the Form Designer is active. Deselect the <Caption is a variable?> option, and whatever is typed in the caption field would be reflected immediately. :wink:

Re: Stringgadget: Caption is a variable?

Posted: Sat Aug 10, 2013 7:58 pm
by HarryT
TI-994A wrote: This string variable "Hello" must then be programmatically assigned some text value to be displayed in the StringGadget(), like this:

Code: Select all

Hello.s = "Some text for the caption"
Thanks for your answer. I know this, but if i assign a value to the variable, it will not update the stringgadget. What must i do to update the display?
I know that setgadgettext(..,..) will show the text immediatly. but i want to use the variable.

And another question: can I use a Array element like Mytext(3) as a caption variable ?

Re: Stringgadget: Caption is a variable?

Posted: Sun Aug 11, 2013 8:02 am
by TI-994A
HarryT wrote:I know this, but if i assign a value to the variable, it will not update the stringgadget. What must i do to update the display?
I know that setgadgettext(..,..) will show the text immediatly. but i want to use the variable.

And another question: can I use a Array element like Mytext(3) as a caption variable ?
Hello again HarryT. As far as I know, if variables are used, there's no way to assign or display their values within the Form Designer environment, because only code for layout and events are allowed. Accordingly, you would not be able to add the SetGadgetText() function to the form code; such additions can only be made from an external .pb source file, or if the .pbf form file is opened as a .pb or .pbi source file (not recommended).

In any case, it is not strictly necessary to initialise the StringGadget() with any caption values or variables, as the Form Designer assigns them null values which can be re-assigned later, something like this:

(in these examples, myForm.pbf is a default form generated by Form Designer, with a single, uninitialised StringGadget() added):

Code: Select all

IncludeFile "myForm.pbf"

OpenWindow_0()
SetWindowTitle(Window_0, "My Added Title")
SetGadgetText(String_0, "My Added Caption")
While Window_0_Events(WaitWindowEvent()) : Wend
Even variables and arrays can be used:

Code: Select all

IncludeFile "myForm.pbf"

Dim MyText.s(2)

MyText(1) = "My Added Title"
MyText(2) = "My Added Caption"

OpenWindow_0()
SetWindowTitle(Window_0, MyText(1))
SetGadgetText(String_0, MyText(2))
While Window_0_Events(WaitWindowEvent()) : Wend
Hope it helps. :)

Re: Stringgadget: Caption is a variable?

Posted: Sun Aug 11, 2013 9:18 pm
by HarryT
Thanks again for your help. I am sorry, that i couldn't make clear what i want.
But English is not my native language.

in the form Definition i have something like this:

Code: Select all

Global Window_0
Global Text_0

Procedure OpenWindow_0(x = 0, y = 0, width = 600, height = 400)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, Wincap, #PB_Window_SystemMenu)
  Text_0 = TextGadget(#PB_Any, 80, 60, 110, 30, Mytext, #PB_Text_Border)
EndProcedure
In my main program i want to have something like:

Code: Select all

Mytext = "This is the text to be displayed in Textgadget Text_0"
Of course, I can use

Code: Select all

SetgadgetText(Text_0, MyText)
but with this I can use any other variable too, and any string constant.
I want to display the variable defined in the gadget definition (Mytext) WITHOUT using setgadgettext().
If this does not work, what sense makes it to have a variable as the caption?

Thanks again for your answer.
Harry

Re: Stringgadget: Caption is a variable?

Posted: Mon Aug 12, 2013 12:15 am
by em_uk
If I think I understand what you mean :

You want to set up a text gadget with the text string mytext, then change the contents of mytext and you expect the textgadget to update?

If that is the case, then you cannot do that - the text gadget doesn't care what you feed into the text area as long as it's a string, it doesn't remember where you fed the string from either, just a copy of the string is sent . You will need to do a setgadgettext to tell the gadget to change the text, unless you go the WinAPI route which will be much more complex.

Re: Stringgadget: Caption is a variable?

Posted: Mon Aug 12, 2013 4:34 am
by TI-994A
HarryT wrote:...I want to display the variable defined in the gadget definition (Mytext) WITHOUT using setgadgettext()...
Hello HarryT. That's absolutely possible, but only for the initial values; any subsequent changes to the caption variables Mytext or Wincap require calls to the SetGadgetText() and SetWindowTitle() functions to update them accordingly. Here are the modified examples to do this:

(myForm.pbf: the form code as per your example)

Code: Select all

Global Window_0
Global Text_0

Procedure OpenWindow_0(x = 0, y = 0, width = 600, height = 400)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, Wincap, #PB_Window_SystemMenu)
  Text_0 = TextGadget(#PB_Any, 80, 60, 110, 30, Mytext, #PB_Text_Border)
EndProcedure
(the calling code)

Code: Select all

Global Wincap.s = "Variable Title"
Global Mytext.s = "Variable Caption"

IncludeFile "myForm.pbf"

OpenWindow_0()
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
Hope this is what you're looking for. :)