Assign text to StringGadget

Just starting out? Need help? Post your questions and find answers here.
carnch
New User
New User
Posts: 4
Joined: Fri Nov 22, 2013 4:03 pm

Assign text to StringGadget

Post 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






User avatar
skywalk
Addict
Addict
Posts: 4241
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Assign text to StringGadget

Post 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:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
carnch
New User
New User
Posts: 4
Joined: Fri Nov 22, 2013 4:03 pm

Re: Assign text to StringGadget

Post by carnch »

Thank you! That was exactly what I needed.

Sorry about that. I will do code blocks from now on.
User avatar
Demivec
Addict
Addict
Posts: 4281
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Assign text to StringGadget

Post by Demivec »

Code: Select all

SetGadgetText(#String_0, "Hello")
Post Reply