Okay, as promised I will be posting code and thoughts as I teach myself PowerBASIC. After
my last bit with the ever popular "Hello, World!" I decided to head to variables.
First off, variables are much like those in
C. You declare them, then give them values. For example in C:
// quick program to show how variables work#include<stdio.h>int main(void);{ // Let's declare an integer variable int number; // Now let's assign it a value of 2 number = 2; // Now let's print the value of the variable to the console to see the value we assigned it printf("The value of number is %d", number);}When compiled the above will display "2" on your console (whether it be Windows, DOS, Linux, etc.). In PowerBASIC things are just a tad different:
#COMPILE EXE#DIM ALL
FUNCTION PBMAIN() AS LONG
' okay these are our integer variables
DIM a AS INTEGER
DIM b AS INTEGER
' this will be our string variable so it work's with MSGBOX (see above)
DIM answer AS STRING
' now we tack values into those integer and string variables
a% = 1
b% = 2
answer$ = STR$(a% + b%)
' we used the STR$ function to convert the integers to a string so MSGBOX will work
MSGBOX "1 + 2 = " & answer$
END FUNCTION
To declare a variable in PB you need to start with a DIM statement then follow with what type of variable you want it to be. DIM a AS INTEGER declares the variable "a" as an integer. Assigning values to variables is much like C as you can see from the code above.
Variable type specifiers in PB
% - integer
& - long integer
&& - quad integer
? - byte
?? - word
??? - double word
! - single-precision
# - double-precision
## - extended-precision
$ - string
As I get more comfortable with PB I'll discuss variable scope (local/global) in another post.