[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Having gpt-5 write a gambas scripter program


Well I guess writing a script program has become a simple trick:

here is a chat that produced a working gambas script

write an hello word program to display a gui in gambas3 scripter
ChatGPT said:

Got it 👍 — you want a Gambas3 Scripter program (so it can be run directly with gbs3) that opens a GUI window and displays "Hello World".

Here’s a minimal example:

#!/usr/bin/env gbs3

' Gambas3 script to display a GUI Hello World window

Library "gb.gui"

Public Sub Main()
  Dim hForm As Form
  Dim hLabel As Label

  hForm = New Form As "MainForm"
  hForm.Text = "Hello World"

  hLabel = New Label(hForm) As "lblHello"
  hLabel.Text = "Hello World!"
  hLabel.Move(50, 50, 200, 30)

  hForm.Show

  Application.Run
End

Instructions:

Save as hello_world.gbs.

Make it executable:

chmod +x hello_world.gbs


Run it:

./hello_world.gbs


This will open a simple window with a label saying Hello World!.

👉 Do you want me to also show you how to add a button that closes the window when clicked?

You said:
instead of using library you must use the Use statement with names in quotes
ChatGPT said:

Ah — I see 👍.
In Gambas3 Scripter (gbs3), instead of Library "gb.gui" you use the Use statement with quoted component names.

Here’s the corrected Hello World GUI script:

#!/usr/bin/env gbs3

Use "gb.gui"

Public Sub Main()
  Dim hForm As Form
  Dim hLabel As Label

  hForm = New Form As "MainForm"
  hForm.Text = "Hello World"

  hLabel = New Label(hForm) As "lblHello"
  hLabel.Text = "Hello World!"
  hLabel.Move(50, 50, 200, 30)

  hForm.Show

  Application.Run
End

Run it:
chmod +x hello_world.gbs
./hello_world.gbs


This should work directly in Gambas3 Scripter and pop up a small window with “Hello World!”.

👉 Do you want me to also show you a version that uses gb.gui.qt instead of the generic gb.gui? That would give you a Qt-based window.

You said:
why did you include an invalid statement application.run
ChatGPT said:
Thought for 1m 27s

You’re right — that was my mistake. In Gambas 3 there is no Application.Run method, and you don’t need to “start” the event loop yourself. After Main() finishes, Gambas automatically enters the event loop as long as there’s a top-level window (or other event sources) alive. Hence Application.Run is invalid and unnecessary.
gambaswiki.org
+1

Here’s the corrected “Hello World” GUI script using Use with quoted names (works with gbs3):

#!/usr/bin/env gbs3
Use "gb.gui"
Use "gb.form"

Public Sub Main()
  Dim f As New Form
  f.Text = "Hello"
  f.Resize(300, 120)

  Dim lbl As New Label(f)
  lbl.Text = "Hello, world!"
  lbl.AutoResize = True
  lbl.Move(12, 12)

  f.Center
  f.Show  ' No Application.Run needed
End


(Loading components with Use "gb.gui" / Use "gb.form" is the right way in scripts.)
gambaswiki.org

Thanks for the catch!

--
~~~~ Brian

Attachment: OpenPGP_0x78BFB26402F48419.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature