Coding techniques in FreeBasic 
Part 1
by VonGodric

	Hello to you all, it's been awhile since I wrote something for QBE, but here it is now once again. Before I continue I'd like to stress out few points about this small tutorial. First: do not take it all as absolute truth, Second: since FreeBasic is ever-changing then these snippets work with FB 0.13 so older ones may not work. And lastly: if you notice mistakes or misleadings then please do not kill me. And now to the point.

1. Variables and Var initializers
	FreeBasic as we all know is very compatible with several older Microsoft Basic variants. Thus also including a lot of hacks from them and I'd personally advise to avoid them. For one of them is no need for defining variables prior their use. While in a very small programs it may simplify things, then in big programs this can be one major source of bugs due misspelled identifier or just being for example out of bounds of the variable's reach. (like in another sub/function for instance). So the solution is to use OPTION EXPLICIT in your code. This forces the need to declare variable prior it's use thus we never have problems like I described before because compiler will give an error during compile.
	Another aspect of defining variables is FB's feature that allows you to declare several variables of the same type. Like this:
DIM AS STRING i, j, k

This way all variables that follow are STRING type. This method can also be used to declare user defined types for example. Rule is: 
DIM AS [type] var_1, var_2, ..., var_n
Inside Type fields just don't put DIM Like this:
TYPE test
    AS INTEGER i, j, k
    AS STRING m, s, t
END TYPE

Another new feature of FreeBasic are var initializers. This allows you to give a variable value when it is declared. But here's small problem. Outside of subs and functions only constant values can be given, but inside function / sub you can assign also non constant value. Also outside of function/sub you cannot assign dynamic length strings
DIM J AS INTEGER = 10
DIM S AS STRING = “non fixed”
DIM m AS STRING * 10 => “Fixed”

You might notice that for last example I used => instead of just =. They both are equal, but only time you have to use => is with fixed length strings.
While this is pretty straightforward it is also possible to assign values to created arrays and user defined types.
DIM i(5) AS INTEGER = {1,2,3,4,5}

It is pretty simple just use { and } to group them together. Now multidimensional array.
DIM i(5, 5) AS INTEGER = {{1,12,13,14,15}, _ 'i( 0, x )
                          {2,22,23,24   }, _ 'i( 1, x )
                          {3,32,33,34,35}, _ 'i( 2, x )
                          {4,45         }, _ 'i( 3, x )
                          {5,52,53,54,55}}   'i( 4, x )

As you see it's just a matter of grouping into { and } inside another group. Also you don't need to specify all variables. And like in FB in general -their value will be 0. And now to last major type of var initializers -user defined types.
TYPE var
    i AS INTEGER
    s AS STRING * 11
    m(5) AS INTEGER
END TYPE

DIM i AS var = ( 10, "hello world", {1,2,3,4,5} )

It's just simple as that. Note that user defined types are grouped together with ( and ) while arrays are grouped with { and }. Here's one more example:
TYPE udt1
    i(2) AS INTEGER
    s AS STRING * 5
END TYPE

TYPE udt2
    k(2) AS STRING * 10
    j AS udt1
END TYPE

DIM i AS udt2 = ({"k(0)", "k(1)", "k(2)"}, _ 'k(_)
                 ( {1,2,3}, "udt1" )) 'j as udt1

One thing you should keep in mind that var initializers work in the same order as you define elements in user defined type. 
This shall now conclude this first part of this small tutorial series I plan to write. If you are interested in some certain subject then please let me know -and now farewell and thanks for reading it!