How to make my first application?

The first program will just print a text in the console window saying "Hello world!"
Then some small variation will be added to supply an example of how to gain user input from the console window and using this data again to process it for output.



Hello world part I


Open XBasic and then create a new source environment by clicking the following button:  

You can also select menu's:"File" option "New".

In the next dialog you are given a couple of options, select "Program":


 


The Entry

Now as this is done you end up in the following situation:



As you notice, the entry is already filled with a comment and you have not done any serious thing yet.
XBasic guides you even while programming with comments to make you aware of what situation you are dealing with and how to handle when you want to make certain changes.

It is advisable to take hints and tips for granted (meaning:not deleting them from the source) if you have unsufficient experience with XBasic.

Here in the entry you are allowed to enter any statement or function that needs to process your solution. In other words:From here you can start your program to take actions.
The function-name does not nessesarily has to be called "Entry" but the entry function is the first declared function in the source-code. It does not matter where you place the function code itself, the first declared function will be assigned by XBasic as the "Entry" function from where Xbasic will start to process your program, that's why it's called so.
If you would place another function at the first place, this one will be placed as first in the function list.



The Prolog
In the PROLOG you are prohibited to use any statement or functions, the PROLOG is pure for declarations of functions and variables, inserting any statement or function call will lead to an error-message dialogue, the first statement should be called in the above described "Entry" function.

 


Making the program act

Good, if we will just go back to the Entry function() let's just make it display something on the console window by inserting the following code into the entry:

 
Make it look exactly as stated, thus PRINT in capitals!
Good, now run the program by pressing "F1" or clicking the exclamation point:
Or just select the "Run" menu option "Start"

Now examine the Console window:

 


Hip hip hurray, you got your first program running.

The next step is to expand it a little bit by asking for a name and then letting it print the name you supplied.

Go back to the coding window and change the code in the Entry function like this:


Okay again all statements in capitals?
When using functions / statements: Watch the parentheses use ( ), not < >!

Now run it and view the following output:

 


Type in anything you like and then hit enter...


Notice anything new?
Good, you now know how to print and supply user input.
But can it also print graphics like lines, circles or pictures?

Yes it can, displaying graphics requires some deeper study of the documents but I will help you with one practical example that gives you a quick show of how to display a bitmap image in the console window.
 
Just go to the PROLOG of your program and remove the "Comment" quote away from the lines that start with IMPORT "Xst" and IMPORT "Xgr"

 

Then you change the code in the entry to this:

 

Now, the UBYTE declares an image array where the bitmap picture will be stored in as soon as it will be loaded.
The XstGetConsoleGrid will retrieve the gridnumber of your console window, this is necessary since you need to let XBasic know in what window to display your picture, you just can't ask XBasic to print the picture on fried air.

The XgrLoadimage loads the picture into the array (Click here to download the example picture)
The XgrSetImage will just paste the picture from the array in the corner of your window.

As this is the resulting view:

Okay, not really a booming start to say so, but as this is just to show the possibilities of what you can do in the Console window, I will later explain how you can place your picture more easily in grids using the GUI-Designer statements and functions.

To be more specific, you can actually put anything in any window as long as you prepare the code good enough for it to place the output for you there.