Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
PowerBASIC
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Programming language== ===Characteristics=== PowerBASIC is a native-code BASIC compiler whose reported merits are simplicity of use and speed compared to other languages.<ref>''New geometries for new materials'', Eric A. Lord, Alan Lindsay Mackay, Srinivasa Ranganathan, Cambridge University Press, 2006, {{ISBN|0-521-86104-7}} ("a very simple user interface ... speed and power of the underlying C++ ... runs extremely fast") [https://books.google.com/books?id=s22_x-O8pEoC&pg=PP3&vq=%22powerbasic%22&dq=%22powerBASIC%22&source=gbs_search_s&sig=uxOcCJGJsvTcUWasxzAaeRiDx3o Google Books]</ref><ref>''Chaos and Time-series Analysis'', Julien C. Sprott, Oxford University Press, 2003, {{ISBN|0-19-850840-9}} ("easy to learn, powerful, and as fast as any C compiler I have encountered") [https://books.google.com/books?id=SEDjdjPZ158C&pg=PR6&vq=PowerBASIC&dq=%22powerBASIC%22&source=gbs_search_s&sig=SBPpyPfT7S2V_-ixWTYrYvlEnZI Google Books]</ref> Although the compiled code is fast enough for most purposes, the compilers also support inline [[assembly language|assembler]] which can be used for hand optimization of critical routines. The Windows compilers (PBWin & PBCC) support almost all of the [[x86 instruction listings|x86 instruction set]], including [[floating-point unit|FPU]], [[Streaming SIMD Extensions|SIMD]], and [[MMX (instruction set)|MMX]], the main exceptions being a few which are useful mostly to systems programmers. One can insert any unsupported instructions by inserting their [[opcode]]s with the "db", "dw", and "dd" statements. Lines of assembler code can be freely interspersed with lines of BASIC code, although one must always consider the potential interactions between the two types of code. ===Hello world=== [["Hello, World!" program|Hello world]] is used to give a very small example of the [[syntax (programming languages)|syntax]] used by a programming language and is often the smallest possible program for any given programming language. Here is an example of a PBCC hello world program. By default PBCC creates a console window at runtime for displaying output. The use of Waitkey$ in this example prevents the console window from automatically closing until the operator sees the displayed text. <syntaxhighlight lang="vbscript"> Function PBMain Print "Hello, World!" Waitkey$ End Function </syntaxhighlight> Here is the PBWin version, which displays a Windows "dialog" message box. <syntaxhighlight lang="vbscript"> Function PBMain MsgBox "Hello, World!" End Function </syntaxhighlight> ===Structured control statements=== These structured control statements eliminate many instances that would require the use of GOTO and labels: * iterate - skips ahead to the next iteration of the loop containing it (iterate do, iterate loop, iterate for), like the [[continue statement]] in most languages * exit - sends execution to just after the loop (exit for, exit do, exit loop), conditional (exit if, exit select), or block (exit function, exit sub) containing it, like the [[break statement]] in most languages ===Object-oriented programming=== PBWin and PBCC support [[object-oriented programming]] in the form of [[Component Object Model|COM]] classes, however the compilers do not force you to use OOP, it is merely an option. In-process and out-of-process COM Servers can also be built using these compilers. ====Graphics==== Both the Console Compiler and Windows Compiler can create graphic windows. The GRAPHICs statements are higher-level than Windows' [[Graphics Device Interface]] (GDI) library functions.<ref>{{cite web |title=PowerBASIC Console Compiler |website=PowerBASIC Peer Support Community |url=https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-console-compiler}}</ref><ref>{{cite web |title=PowerBASIC for Windows |website=PowerBASIC Peer Support Community |url=https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows}}</ref> =====Elements of the GRAPHIC statements===== GRAPHIC WINDOWS are dedicated dialogs each containing a single control which fills the dialog's client area. GRAPHIC controls are [[child window]]s which support the same GRAPHIC drawing functionality as GRAPHIC windows. GRAPHIC BITMAPS are also defined, again supporting the GRAPHIC drawing functionality, but as purely memory objects, like [[BMP file format|Windows bitmaps]] or [[BMP file format|DIB sections]]. Keyboard and mouse handling statements are included among the GRAPHIC statements. Character output to a GRAPHIC target uses fonts specified via the FONT NEW statement. =====Creating a GRAPHIC WINDOW application===== A GRAPHIC WINDOW is the equivalent of a Windows [[dialog box]] containing a static control on which drawing operations can be done. A single BASIC statement will create a GRAPHIC WINDOW and specify its size, position and title. It is not essential to specify a [[Windows USER|WNDPROC]] for the GRAPHIC WINDOW. A short source code example for a complete GRAPHIC WINDOW application follows: <syntaxhighlight lang="vbnet"> #Compile Exe ' using either PBCC6 or PBWIN10 compiler #Dim All Function PBMain Local GW As Dword ' start a GRAPHIC WINDOW Graphic Window New "graphic window", 100, 100, 200, 200 to GW ' show a coloured disc Graphic Ellipse (10, 10)-(190, 190), %rgb_Red, %rgb_SeaGreen, 0 ' wait for a keypress Graphic Waitkey$ End Function </syntaxhighlight> =====Comparison of PB GRAPHIC statements with the GDI API===== Using PB GRAPHIC statements, a GRAPHIC (WINDOW, BITMAP, or control) is first selected as the current GRAPHIC target, then operations are done on it without requiring it to be identified again. Contrast this with the GDI API approach, where the [[Device Context]] handle is required for every drawing operation. It is not necessary when using the PB GRAPHIC statements to define a brush or pen as a separate entity, nor is it necessary to redraw the GRAPHIC target (when in view) in response to [[Windows USER|Windows messages]] such as WM_PAINT and WM_ERASEBKGND. GRAPHIC targets are persistent. When GRAPHIC targets are attached, a REDRAW option can be specified which buffers the results of drawing operations until they are specifically requested. Using this technique reduces flicker in a similar way to the technique of drawing on memory [[Graphics Device Interface|DC]]s <ref>Petzold, Charles (1998). Programming Windows Fifth Edition, Microsoft Press, {{ISBN|978-1-57231-995-0}}</ref> when using the GDI API. Pixel operations are possible using the GRAPHIC GET|SET PIXEL statements, in a manner similar to GetPixel/SetPixel of the GDI API. GRAPHIC GET BITS allows the entire bitmap to be loaded into a dynamic string. This can be manipulated either as a string or by mapping an array onto it. It can be placed back into the GRAPHIC target by GRAPHIC SET BITS. =====Complementarity of GRAPHIC statements and the Windows GDI API===== The GRAPHIC statements contain all the commonly used GDI API functions, but if you need one that is not included it is possible to obtain the [[Graphics Device Interface|hDC]] of any GRAPHIC target and thereby use GDI API functions on it.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)