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
PureBasic
(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!
=== Procedural programming === PureBasic is a "Second generation BASIC" language, with structured conditionals and loops, and procedure-oriented programming supported. The user is not required to use procedures, so a programmer may opt for a coding style which includes {{mono|Goto, Gosub Label}}, and {{mono|Return}}. Below is a sample procedure for sorting an array, although SortArray is now a built-in function of PureBasic. <syntaxhighlight lang="blitzbasic" line highlight="1,15"> Procedure bubbleSort(Array a(1)) Protected i, itemCount, hasChanged itemCount = ArraySize(a()) Repeat hasChanged = #False itemCount - 1 For i = 0 To itemCount If a(i) > a(i + 1) Swap a(i), a(i + 1) hasChanged = #True EndIf Next Until hasChanged = #False EndProcedure</syntaxhighlight> Below is a sample program that displays a sizeable text editor with two menu items. <syntaxhighlight lang="blitzbasic"> ;Create Window: OpenWindow(0, #PB_Ignore, #PB_Ignore, 800, 600, "Simple Text Editor", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget) ;Add 2 menus: CreateMenu(0, WindowID(0)) MenuItem(1, "&OK") MenuItem(2, "&Cancel") ;Add Editor: EditorGadget(0, 0, 0, 0, 0) SetGadgetFont(0, LoadFont(0, "Courier New", 10)) ;Process window messages until closed: Repeat Select WaitWindowEvent() Case #PB_Event_Menu Select EventMenu() Case 1: MessageRequester("OK clicked directly or with '&' mnemonic.", GetGadgetText(0)) Case 2: Break EndSelect Case #PB_Event_SizeWindow: ResizeGadget(0, 0, 0, WindowWidth(0, #PB_Window_InnerCoordinate), WindowHeight(0, #PB_Window_InnerCoordinate)) Case #PB_Event_CloseWindow: Break EndSelect ForEver </syntaxhighlight> PureBasic does not escape double quotes in strings so these must be concatenated with {{mono|Chr(34)}}.
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)