We start programming...
The following topics in this chapter should give you some ideas, where to start with PureBasic. It shouldn't replace any larger tutorial or the massive informations, which can be found on the popular PureBasic forums. So the following information texts are short, but they include some "keywords" and links to futher informations, which are included in this reference manual. This chapter covers only a small part of the 1100+ commands available in PureBasic! :)
Topics in this chapter:- First steps
- Decisions and Conditions
- Storing data in memory
- Input & Output
- Displaying text output
- Displaying graphics output & simple drawing
- Reading and writing files
First steps with the Debug output (variables & operators)
Normally we would present here the typical "Hello World". You want to see it? Ok here we go with two examples:"Hello World" in the Debug output window:We now continue with a short example using the available variable types, arithmetic operators and displaying the result:Debug "Hello World!""Hello World" in a MessageRequester():MessageRequester("", "Hello World!")a = 5 b = 7 c = 3 d = a + b ; we use the values stored in variables 'a' and 'b' and save the sum of them in 'd' d / c ; we directly use the value of 'd' (= 12) divided by the value of 'c' (= 3) and save the result in 'd' Debug d ; will give 4This way you have used variables "on the fly". To force the compiler always declaring variables before their first use, just use the keyword EnableExplicit.
Decisions and Conditions
... There are different ways of processing data you got via user input or on another way (loading from a file, ...). The common arithmetic functions (+, -, *, /, ...) can be combined with ...conditions (Bedingungen). You can use the "If : Else/ElseIf : EndIf" set of keywords or the the "Select : Case/Default : EndSelect" keywords, just you what is the best for your situation!
... Data, Events or many other things can also be processed using loops, which are always checking for a specific condition. This can be: "Repeat : Until/Forever", "While : Wend", "For : Next", ForEach : Wend", ....
Storing data in memory
Input & Output
Every PureBasic application can communicate and interact with the user on different ways.
Thereby we distinguish betweena) the pure output of informationsIt's not possible anymore, to use a simple "PRINT" command to output some things on the screen, like it was possible on DOS operating systems (OS) without a graphical user interface (GUI) years ago. Today such a GUI is always present, when you use an actual OS like Windows, Mac OSX oder Linux.
b) the interaction of the PureBasic application with the user, when user-input will be taken and the results will be outputted again.
For the output of informations we have different possibilities:- debug window (only possible during programming with PureBasic)To be able to record and process input by the user of the PureBasic application, the three last-mentioned output options have also the possibility to get user-input:
- MessageRequester (output of shorter text messages in a requester window)
- files (for saving the results in a text-file, etc.)
- console (for simple and almost non-graphic text output, most similar to earlier DOS times)
- windows and gadgets (standard windows with GUI elements on the desktop of the OS, e.g. for applications)
- Screen (Output of text and graphics directly on the screen, e.g. for games)
- in the console using Input()
- in the window using WaitWindowEvent() / WindowEvent(), which can get the events occured in the window, like clicking on a button or the entered text in a StringGadget
- in the graphics screen using the keyboard
- the is as well the possibility to get user-input using the InputRequester
Displaying text output
In previous chapter "Input & Output" you already got an overview about the different possibilities to output text to the user.
First we will store some data in memory, which will be used later in the output examples:And now we will see several examples of "How to output" text (using the previous stored data):
Displaying graphics output & simple drawing
Reading and writing files