Newbie Question

Everything else that doesn't fall into one of the other PB categories.
Wombat
New User
New User
Posts: 1
Joined: Thu Apr 10, 2025 9:12 pm

Newbie Question

Post by Wombat »

Well not totally a newbie to Basic, but totally new to PureBasic. I used to program a lot as a hobby. ZX 81 Basic, ZX Spectrum Basic, QL Basic and lastly GFA 3.5 on the Atari ST. That was long ago, maybe early 1990's. Clearly I have forgotten more than I knew. I am now a long way past retirement and looking for ways to pass time. I really enjoyed programming, but I am sure things have changed. When I programmed you had a fixed screen size and only one screen, (or window). So my very short test program ending in: Print "The results of the calculation found a possible ";particle;" number out of a possible ";samplesize. Produced nothing on the screen, but I learned you have to surround the text with brackets in PureBasic, which I did but still nothing. So I am guessing you need to create a window or something for the text to appear in?

Basically what I am asking of anyone who remembers Basic from before Windows. How much of a leap is it?
miso
Enthusiast
Enthusiast
Posts: 455
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: Newbie Question

Post by miso »

Hello and welcome to the forums!
Pb can do a lot of things compared to old basics.

Try a console window first:

Code: Select all

OpenConsole("myconsole")
PrintN("Hello World")
Print("Hello ")
Print("World")

Input()
User avatar
mk-soft
Always Here
Always Here
Posts: 6224
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Newbie Question

Post by mk-soft »

And Compiler Option Executable Format -> Console

The leap from console to GUI is gigantic.
But it is easy to manage with PureBasic.

Here is a template which I use for testing programmes.

Code: Select all

;-TOP

#ProgramTitle = "Main Window"
#ProgramVersion = "v1.01.2"

Enumeration Windows
  #Main
EndEnumeration

Enumeration MenuBar
  #MainMenu
EndEnumeration

Enumeration MenuItems
  #MainMenuAbout
  #MainMenuExit
EndEnumeration

Enumeration Gadgets
  #MainEdit
  #MainButtonOk
  #MainButtonCancel
EndEnumeration

Enumeration StatusBar
  #MainStatusBar
EndEnumeration

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(#Main)
  dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
  ; Resize gadgets
  ResizeGadget(#MainEdit, 5, 5, dx - 10, dy - 45)
  ResizeGadget(#MainButtonok, 10, dy - 35, 120, 30)
  ResizeGadget(#MainButtonCancel, dx - 130, dy - 35, 120, 30)
EndProcedure

Procedure Main()
  Protected dx, dy
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, #ProgramTitle , #MainStyle)
    ; Menu
    CreateMenu(#MainMenu, WindowID(#Main))
    MenuTitle("&File")
    CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
      MenuItem(#PB_Menu_About, "")
    CompilerElse
      MenuItem(#MainMenuAbout, "About")
    CompilerEndIf
    ; Menu File Items
    
    CompilerIf Not #PB_Compiler_OS = #PB_OS_MacOS
      MenuBar()
      MenuItem(#MainMenuExit, "E&xit")
    CompilerEndIf
    
    ; StatusBar
    CreateStatusBar(#MainStatusBar, WindowID(#Main))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(#Main)
    dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
    EditorGadget(#MainEdit, 5, 5, dx -10, dy - 45)
    ButtonGadget(#MainButtonok, 10, dy - 35, 120, 30, "Ok")
    ButtonGadget(#MainButtonCancel, dx - 130, dy - 35, 120, 30, "Abbruch")
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
    
    ; Event Loop
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case #Main
              Break
              
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            CompilerIf #PB_Compiler_OS = #PB_OS_MacOS   
              Case #PB_Menu_About
                PostEvent(#PB_Event_Menu, #Main, #MainMenuAbout)
                
              Case #PB_Menu_Preferences
                
              Case #PB_Menu_Quit
                PostEvent(#PB_Event_CloseWindow, #Main, #Null)
                
            CompilerEndIf
            
          Case #MainMenuAbout
            MessageRequester("About", #ProgramTitle + #LF$ + #ProgramVersion, #PB_MessageRequester_Info)
              
          Case #MainMenuExit
            PostEvent(#PB_Event_CloseWindow, #Main, #Null)
            
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #MainEdit
              Select EventType()
                Case #PB_EventType_Change
                  ;
                  
              EndSelect
              
            Case #MainButtonOk
              ;
            Case #MainButtonCancel
              ;
              
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
Furthermore PureBasic has a very good help (F1) and also with a UserGuide for beginners
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Seymour Clufley
Addict
Addict
Posts: 1265
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: Newbie Question

Post by Seymour Clufley »

Wombat wrote: Thu Apr 10, 2025 9:39 pmPrint "The results of the calculation found a possible ";particle;" number out of a possible ";samplesize.

Code: Select all

OpenConsole("myconsole")
samplesize.d = 9999
particle.d = 99
PrintN("The results of the calculation found a possible "+Str(particle)+" number out of a possible "+Str(samplesize)+".")
Input()
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
User avatar
skywalk
Addict
Addict
Posts: 4213
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Newbie Question

Post by skywalk »

You chose well to reintroduce programming with Purebasic. It has an editor and a debug window for quick calcs. And a form editor when you decide to try some basic windows and gadgets.
Though, don't get too caught up in the form editor, as it may be more instructive to hand code the gui and events you need.
Good luck!
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply