Simple Program
In just four lines you can write a PowerBASIC program. Just place the
following lines of code into a file, open it in the IDE, and press the
Compile/Execute button. A popup window will be displayed with the words
"Hello World". Clicking the OK button will end the program.
#COMPILE EXE Function PBMain() as Long MsgBox "Hello World" End Function
Programs in PowerBASIC start execution in the PBMain function, which is the only function this simple program includes. Once the message box OK button is pressed the PBMain function ends, which also ends the PowerBASIC program.
Sample Program
This slightly expanded example provides a better feel for what a complete
PowerBASIC program is all about. In this example, a single window is
created which contains a single button.
Unlike code created using the drag and drop capabilities of a Visual Basic program, the interface-defining PowerBASIC code is written manually. Event code (such as responding to a button click) is also written manually.
A companion product, PowerBASIC Forms, is available which supports VB-like drag and drop creation of the graphical user interface.
Here's the entire program, consisting of just 11 lines of code. Just place this text into a file, open it in the IDE, and press the Compile/Execute button. The program consists of a window containing a single button. When the button is pressed the program ends.
#Compile Exe #Include "Win32API.inc" Function PBMain() As Long Dim hDlg As Dword, hCtl As Dword Dialog New 0, "PowerBASIC",300,300,100,75, %WS_SysMenu,0 To hDlg Control Add Button, hDlg, 2, "Cancel", 25, 15, 40, 20 Dialog Show Modal hDlg Call DlgProc To Result& End Function CallBack Function DlgProc() As Long If CbMsg = %WM_Command Then Dialog End CbHndl, 0 End Function
Here's a line-by-line analysis of what the code does.
Because the DIALOG SHOW statement was executed as MODAL, the dialog window is displayed and no further statements in the PBMain() function are executed until the dialog window is closed. At that point, there are no more statements to execute in the PBMain() function so the PowerBASIC program ends.
During a modal display of a dialog, however, Windows will continue to send messages to the PowerBASIC application. In the example above, the CallBack Function is called whenever a Windows message is received by the PowerBASIC application. In that way, the application can respond to user events, such as the user clicking on the button with a mouse.