User Tools

Site Tools


Language Reference

Welcome to the KBasic Language Reference!

This documentation refers to the V1.6 (or above) release of KBasic.

KBasic comes with extensive documentation, with hypertext cross-references throughout, so you can easily click your way to whatever interests you. The part of the documentation that you will probably use the most is the KBasic Language Reference. Each link provides a different way of navigating the KBasic Language Reference; try them all to see which work best for you. You might also like to try the “Manual: The KBasic Book”. This book contains detailed information about KBasic, and it provides a full text search facility. There are also a growing number of KBasic books.

You can always search in one of the following ordered lists:

Another way of finding your notion is going through the following list:


Please note that VB6 and QBasic support is provided, BUT IT IS STRONGLY RECOMMENDED NOT TO USE subs or functions, which are marked as VB6&QB!

In general, there is a better replacement in the KBasic Framework. www.kbasic.com_images_vb6.jpg

KBasic ships with lots of small and some medium-sized example programs that teach you how to implement various tasks with KBasic. Most of them will show how to use a certain class or module, others aim at programming techniques and KBasic basics, and some of them simply want to show you what is possible.

Note that most of the examples assume that you have some experience with KBasic and Object-oriented programming and therefore are not commented extensively. If you are interested in a line-by-line coverage please refer to the “Learning Coding for Beginners” and “Manual: The KBasic Book”.


The syntax of sub, function or statement in the KBasic help entry shows all elements, which are needed to correctly use the sub, function or statement. How you can understand those information shows the following lines.

Example: Syntax of the MsgBox-Function

MsgBox(prompt[, buttons] [, title] [, helpfile, context])

Arguments, which are inside of [ ], are optional. (Do not write these [ ] in your KBasic code). The only argument, what you have give the MsgBox-Function is the one for the showing the text: 'prompt'.

Arguments for functions or subs can be used with the help of their position or their name. In order to use the arguments defined with their position, you do not have to ignore the position written in the syntax. You must write them exactly in the same order they occur in the syntax. All arguments must be separated by a comma. Example:

MsgBox("The answer is right!", 0, "window with answer")

If you would like to use a argument with its name, use the name of the argument and colon and equals sign (:==) and the value of the argument. You can write these named arguments in any order you wish. Example:

MsgBox(title:="window with answer", prompt:="The answer is right!")

Some arguments are written inside of {} in the syntax of functions or subs.

Option Compare {Binary | Text}

In the syntax of the 'Option Compare'-statement: { } together with | means that one of the elements must be written.(Do not write these { } in your KBasic code). The following statement defines that text will be compared and sorted without case sensitive.

Option Compare Text

Syntax of the 'Dim'-Statement

Dim VarName[([Indexes])] [As Type] [, VarName[([Indexes])] [As Type]] …

'Dim' is a keyword in the syntax of the 'Dim'-Statement. The only needed element is VarName (the name of the variable). The following statement creates three variables: myVar, nextVar and thirdVar. These variables are declared as 'Variant'-variables automatically (or 'Double' in 'VeryOldBasic Mode').

Dim myVar, nextVar, thirdVar

The following example declares a variable of type 'String'. If you declared the datatype of the variable explicitly, it will help KBasic to optimize the RAM-usage and will help you to find errors in your code.

Dim myAns As String

If you want to declare many variables in one line, you should declare every datatype of each variable explicitly. Variables without declared datatype get the default datatype, which is 'Variant'.

Dim x As Integer, y As Integer, z As Integer

X and y get in the datatype 'Variant' in the following statement. Only z has the 'Integer' datatype.

Dim x, y, z As Integer

You have to put ( ) or [ ] (for new style), if you want to declare an array variable. The indexes of the array are optional. The following statement declares a dynamic array named myArray.

Dim myArray[]
language_reference.txt · Last modified: 2013/04/09 22:57 (external edit)