Page 1 of 1

Assign text to StringGadget

Posted: Fri Nov 22, 2013 5:02 pm
by carnch
Hello,

I'm new to PureBasic. I come from a long background of writing in vb.net but a couple of years ago I decided to switch to something else as .Net's reliance on the Windows CLR and lack of cross-platform compatibility were causing me grief. I bought Xojo (RealBasic at the time) which I like very much but as I use it more and more I'm beginning to see that it is extremely buggy so I started searching again and came across PureBasic.

I'm really intrigued by this dialect of BASIC. I haven't used procedural programming since my QB days 25 years ago. Unfortunately, I'm having problems getting my head wrapped around the whole Event thing. These forums have helped a lot in getting started and I've managed to create a project form using a source form and the form designer. The problem is having the code actually "do something"

I have a form (.pbf) with two controls, a StringGadget (String_0) and a ButtonGadget (Button_0). I want to make it so when the button is pressed it changes the text in the StringGadget to "Hello" or something.

In VB/Xojo it would be something like this in the button's action method:

txtString.Text = "Hello"

What is the correct syntax to change the StringGadget's text? I've tried things like "String_0 = "Hello" and WriteString_0("Hello") but nothing works.

Here is my MainWindow.pbf:

;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;

Global Window_0

Global Button_0, String_0

Declare Button_0_Event(EventType)

Procedure OpenWindow_0(x = 0, y = 0, width = 600, height = 400)
Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu)
Button_0 = ButtonGadget(#PB_Any, 50, 160, 100, 25, "Write")
String_0 = StringGadget(#PB_Any, 50, 130, 100, 25, "Hello")
EndProcedure

Procedure Window_0_Events(event)
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False

Case #PB_Event_Menu
Select EventMenu()
EndSelect

Case #PB_Event_Gadget
Select EventGadget()
Case Button_0
Button_0_Event(EventType())
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure

and my Test.pb

XIncludeFile "MainWindow.pbf"

OpenWindow_0()

Procedure Button_0_Event(EventType)
WriteString_0("Hello")
EndProcedure

Repeat
Event=WaitWindowEvent()

Select EventWindow()
Case Window_0
Window_0_Events(Event)
EndSelect
Until Event = #PB_Event_CloseWindow







Re: Assign text to StringGadget

Posted: Fri Nov 22, 2013 5:29 pm
by skywalk
You will have to read a bit more of the manual on gadgets...
Also, please use the Code blocks in your posts. :wink:

Re: Assign text to StringGadget

Posted: Fri Nov 22, 2013 5:42 pm
by carnch
Thank you! That was exactly what I needed.

Sorry about that. I will do code blocks from now on.

Re: Assign text to StringGadget

Posted: Fri Nov 22, 2013 5:49 pm
by Demivec

Code: Select all

SetGadgetText(#String_0, "Hello")