Manual Kbasic
Manual Kbasic
1 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Note Of Thanks
I am very grateful to all the people who helped me to complete this book. Special thanks goes to
Nadja, my girlfriend, and to everyone who bought KBasic Professional or has supported me
otherwise. A big thanks also goes to my parents.
Supporter
Thank you! Nadja Hepp for proofreading this manual and for beta testing. Thanks to everyone on
the Internet who submitted corrections and suggestions, especically Christopher Scott Wyatt and his
wife Susan; you have been tremendously helpful in improving the quality of this book and I could
not have done it without you: Thank you all!
Give Us Feedback
Please help me improve this book. As the reader, you are the most important commentator and critic
of my book. We respect your opinion and would like to know what improvements we could make.
If you find an error in any example program or in the text, sent an e-mail to [email protected].
Thank you! Please note that we cannot help you with technical problems related to the topic of this
book, and that due to the high volume of mail we receive, we might not be able to reply to every
message. Our primary goal is the satisfied customer. In order to improve, we need your help. If we
have made any mistakes, please tell us.
Please write to [email protected] – we would like to get positive comments, too. Thank you very
much.
2 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Table of Contents
First Edition................................................1 Starting KBasic.........................................14
About this book...........................................1 FAQ...........................................................14
Why You Should Read This Book..............1 What is the difference between
Note Of Thanks...........................................2 KBasic and Visual Basic 6?.............14
About The Author.......................................2 Can I import existing Visual Basic 6
Supporter.....................................................2 programs automatically?.................15
Give Us Feedback.......................................2 On which platform is KBasic
New set of manuals about KBasic..............2 available?.........................................15
Conventions used in this book / Way of KBasic-Syntax..........................................15
writing.........................................................2 KBasic is not one programming language,
Sources for further information..................3 but three....................................................16
Introduction.................................................6 Software development with KBasic.........16
The Big Mystery.........................................6 Event controlled programming vs.
What is a Computer Program?....................7 traditional programming......................17
Programming Languages............................7 How does an event controlled
History of the Name....................................7 application run?....................................17
All Kinds of BASIC....................................8 Three Programming Steps....................17
Compilers and Interpreters.........................8 Object orientated programming with
The Programming Process..........................8 KBasic..................................................17
Attack of the Bugs......................................9 Objects and classes...............................18
How much KBasic do I need to know to use Inheritance of classes...........................19
it?................................................................9 KBasic-Syntax.....................................19
Something You Need to Know...................9 Statements and expressions......................19
Introduction to the KBasic programming Multi-Line statements...............................19
language....................................................10 Variables and DataTypes...........................20
What is KBasic?...................................10 Declaration of Variables / Explicit
Warning................................................10 declaration............................................20
Examples..............................................10 Declarations of variables in different
KBasic is Object-Orientated................10 scopes...................................................21
KBasic is Easy to Learn.......................11 Declaration of variables automatically /
KBasic is object-orientated..................11 implicit declaration..............................23
KBasic is easy to learn.........................11 Local variables.....................................23
Interpreted............................................11 Assignment-statement..........................23
Stable....................................................12 Lifetime of variables............................24
KBasic is Fast.......................................12 Place of declaration..............................24
Why KBasic Succeeds.........................12 Data Types................................................25
A Simple Example...............................13 Simple Data Types...............................25
Rapid application development................13 User defined types................................26
How Can I Get KBasic?...........................14 Class types/Objects..............................26
Installation of KBasic / Installation Type Variant.........................................26
description / System needs........................14 Suffix of variables................................27
3 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
4 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
5 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Property................................................85 String....................................................86
Read-Only Property.............................86 String Literal........................................86
Relational Operator..............................86 Subprogram..........................................86
Return Value.........................................86 Unconditional Branch..........................86
Runtime Error......................................86 User Interface.......................................87
Scope....................................................86 Variable................................................87
Single...................................................86 Variable Scope......................................87
Source Code.........................................86 Variant..................................................87
Introduction
You heard probably already much about Kbasic and have probably downloaded the Personal
Edition of KBasic and played a little with the sample programs. Now you want to write your own
KBasic programs… Have you ever wanted to know how a computer program works? Did you ever
want to sit down at your keyboard and create digital magic on your computer’s screen? If so, there
might be a computer programmer somewhere inside you, waiting to get out.
You might have found computer programming not only intimidating but downright frightening. Do
you get new grey hairs every time you try to write a simple script file? If you feel this way, The
KBasic Book is here to prove that programming your computer is fun, rewarding, and not difficult.
Before you get started with developing computer programs, it might help to have a basic
understanding of what programming is all about. You probably have some ideas about what a
program is and how it works or you would not have gotten this book to begin with. After reading
this introduction, you may find that your knowledge about programming is good or you might
realize you know as much about programming a computer as you do about building a plane. In
either case, it is worth it…
6 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Programming Languages
Computers do not understand German or English or any other human language. They cannot even
understand BASIC, the computer language upon which KBasic is based. Computers understand
only one thing, machine language, which is entirely composed of the numbers 1 or 0. Programming
languages like BASIC allow people to write programs in an English-like language. The BASIC
interpreter changes the program into machine language so the computer can understand it. KBasic
programs are a dialect of the BASIC computer language that was developed not to help computers,
but to help people make sense out of the numerical code machines use to function. KBasic replaces
many of the numbers used by machine language with words and symbols we can more easily
understand and remember. Moreover, KBasic enables a programmer to visually assemble a
program’s window from parts in a toolbox. It is much easier for you to communicate with your
computer as an software developer; instead of thinking as a machine you can think as an human
being.
7 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Java, C++ and BASIC. However, all computer languages have one thing in common: they can be
read by humans and therefore must be converted to machine language before the computer can
understand them.
8 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
9 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
What is KBasic?
KBasic is a powerful programming language designed to be intuitive and easy to learn. KBasic also
represents a further bridge between Linux, Mac OS X, and Windows. KBasic is a new programming
language, a further BASIC dialect related to Visual Basic 6 and Java. More precisely, KBasic is an
object-oriented and event-controlled programming language, developed by KBasic Software
(www.kbasic.com), and is designed particularly for the needs of GUI-developers and therefore
strenghens GUI-application development. C/C++ developers feel that BASIC is a beginner,s
language, but with KBasic you can write many applications that may otherwise have been written in
the more difficult C/C++ were it not for KBasic. KBasic is an easy, usable, object-oriented,
interpreted, stable, platform-independent, modern programming language. Briefly and well in a
sentence KBasic is a easy-usable, object-oriented, interpreted, stable, platform-independent, fast
and modern programming language.
Warning
In order to have compatibility to future version of KBasic, you should avoiding certain old elements
of the KBasic language, which are still supported for historical reasons. Use instead the modern
elements of the language. You can find more details in the respective help entries. Please consider
also the references to the migration from Visual Basic 6 at the end of this book. In addition, only the
new, current and modern language features are described in this book, since many language
elements are only supported for historical reasons by KBasic, e.g. ‘GoSub’, ‘DefInt’, ‘On Error
GoTo’ are outdated elements of the language and therefor are not described in this book.
Examples
The examples in this book are in English. KBasic’s Past, Present and Future KBasic was originally
developed as open source software. The project was started by Bernd Noetscher in summer 2000.
After many disappointments, due to lack of volunteer support, he decided to develop the
programming language as a commercial product for Linux, Mac OS X, and Windows. At present,
KBasic version 2.0 is under construction. Version 2 is more user-friendly, more efficient, and has
more programming libraries and new object-oriented features. What is still needed to know about
KBasic?
KBasic is Object-Orientated
As a programmer, you concentrate on the data and on the methods in your application - how to
manipulate the data, instead of thinking only in procedures. If you are familiar with procedural
programming in BASIC, you may think you have to change how you write your programs when
using KBasic. You can program further with procedures only. Once you learn how powerful this
new object-oriented paradigm is, you will see how easy it is to develop reusable complex
application programs clearly and modularly. KBasic is object-oriented regarding the binding to C++
programming libraries, or built in KBasic classes, with true inheritance. Contrary to other
10 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
KBasic is object-orientated
That means for you as a programmer that you concentrate on the data and on the methods in your
application - how to manipulate the data, instead of thinking only in procedures. If you are familiar
with procedural programming in BASIC, you will probably get the conviction that you must change
the kind, how you write your programs, if you use KBasic. But you do not have to use it that way.
You can program further with procedures only. If you get to know with it, how powerfully this new
object-oriented paradigma is, you will get used to it, because you will see how easy it is to develop
re-useable complex application programs clearly and in a modular way. KBasic is object-oriented
regarding the binding to C++ programming libraries, or builtin KBasic classes, with true
inheritance. Contrary to other programming languages KBasic is designed from the beginning as an
object-oriented programming language. So most things in KBasic are objects; the simple data types,
like numeric, strings and boolean values, are the only exceptions. Although KBasic is designed in
such a way, that it looks similar to VB6, you will notice that KBasic avoids many problems of VB6
in an elegant way.
Interpreted
KBasic produces pseudo code instead of machine code. In order to run a KBasic program you can
use the KBasic development environment (IDE) or the menu entry ‘Make Runtime’ (only in the
Professional version). KBasic is thus a interpreted programming language. KBasic pseudo codes is
an architecture-independent format: the code was designed to run programs efficiently on different
11 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
platforms.
Stable
KBasic is designed to write very reliable and durable software. Of course, KBasic does not
eliminate the need for quality control. It is still possible to write unreliable software. However
KBasic eliminates certain kinds of programming errors so that it is easier to write reliable software.
KBasic is a typed language, which enables KBasic to do very detailed examinations of the potential
type inconsistencies in your KBasic program. KBasic is more strictly typed than standard BASIC.
One of the most important characteristics regarding the reliability is the memory management.
KBasic does not support pointers, which excludes the danger of making memory useless and
overwriting data. Similarly, KBasic’s garbage collector prevents memory leaks and other malicious
errors with dynamic memory allocation and deallocation. In addition, the KBasic interpreter
examines at run time different things, e.g. whether arrays and strings are still within their borders.
The exception handling is another new possibility. An exception is a signal for a exceptional
program condition, which occurs like an error. When you use the try/catch/finally statements, you
can place all your error processing routines at one place, making it easier to manage and fix errors.
KBasic is Fast
KBasic is an interpreted programming language. Therefore, it will never be as fast as a machine-
code compiled language, like C. Actually, KBasic is 20 times slower than C. But instead of running
away, keep in mind this speed is fast enough for nearly all kind of GUI applications, which often
wait for the user to input something. When analyzing the power of KBasic, think about the
placement of KBasic between the other programming languages. On one end are high-level, full-
interpreted languages like PHP and UNIX-shells. These languages are very useful to create a draft,
but they are slowly executed. On the other end are the fully machine language compiled
programming languages. These languages provide extremely fast programs but are not very
portable or reliable. KBasic is in the middle of these languages. The performance of KBasic is much
better than high-level programming languages, but have the ease and portability of those languages.
Though KBasic is not as fast as a C compiled program, it is a platform-independent environment,
providing the ability to write stable programs for Windows, Mac OS X, and Linux.
12 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
syntax and programming model. It allows you to continue creating useful code, applying the
features gradually as you learn and understand them. This may be one of the most important reasons
for the success of KBasic. In addition, most of your existing VB6 code is still viable in KBasic.
A Simple Example
Enough! Now that you have an insight into what KBasic is all about, let us stop discussing abstract
phrases and instead study a KBasic code example. Here is the much loved favorite “Hello World”:
' program beginning
CLS
Print "Hello World!"
Print
Print
Print " / `._ . . _.' \"
Print " '.@ = `. \ / .' = @.'"
Print " \ @`.@ `. \ / .' @.'@ / "
Print " \;`@`.@ `. \ / .' @.'@`;/ "
Print " \`.@ `.@ `'.(*).'` @.' @.'/ "
Print " \ '=._`. @ :=: @ .'_.=' / "
Print " \ @ '.'..'='..'.' @ / "
Print " \_@_.==.: = :.==._@_/ "
Print " / @ @_.: = :._@ @ \ "
Print " /@ _.-' : = : '-._ @\ "
Print " /`'@ @ .-': = :'-.@ @`'`\ "
Print " \.@_.=` .-: = :-. `=._@./ "
Print " \._.-' '.' '-._./ "
Print
Print "... you just did your first kbasic program!"
Input these lines into a new KBasic code window. After running it in KBasic you will see a nice
butterfly on your screen. Now let us go on to the next chapter.
13 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Specifically, you can: Use the completely integrated visual debugger to examine code while it is
running; and Browse your code at the level of project, class, or method
Starting KBasic
You can start KBasic by doing one of the following:
• For Linux, select KBasic on the desktop
• For Windows, select KBasic in the program menu
• For Mac OS X, select KBasic on the desktop
Now that KBasic is up and running, the main window of KBasic appears. Use this window to
access other windows, create program elements, and view the contents of program elements.
FAQ
14 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
VB6 it is possible to have a global namespace, global functions or subs, and global variables.
KBasic does not support a pre-processor, but this is planned for the future. (e.g. '#ifdef’ and '#if’).
Theoretically it is not needed because KBasic is a platform-independent programming language and
therefore there does not have platform-related dependence. Furthermore, the simple data types are
the same except their size might change. Changed sizes are: ‘Boolean’ is 1 Byte, ‘Integer’ is 32bit
and ‘Long’ is 64bit in KBasic.
KBasic-Syntax
The syntax of sub, function, or statement in the KBasic help entry shows all elements needed to
correctly use the sub, function, or statement. Example: Syntax of the MsgBox-Function
MsgBox(prompt[, buttons] [, title] [, helpfile, context])
Arguments listed inside brackets [ ] are optional. (Do not write these [ ] in your KBasic code). The
only argument, what you have to 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 by their position, you cannot 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")
To use an 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!")
15 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
The following example declares a variable of type ‘String’. If you have declared the data type 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 data type of each
variable explicitly. Variables without declared data type get the default data type, which is ‘Variant’.
Dim x As Integer, y As Integer, z As Integer
X and y get in the data type ‘Variant’ in the following statement. Only z has the ‘Integer’ data type.
Dim x, y, z As Integer
You have to put ( ) or [] (modern 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(100)
Dim myArrayModernStyle[200]
16 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
the program, ignoring the events. The application starts with the first code of line and goes through
its source codes as the developer has defined. If needed some procedures are called.
In event controlled applications, user action or a system event triggers the execution of the event
procedure. The order in which the code is executed depends upon the order of the events, which
occur based upon user actions. This is the principle of graphical user interfaces and event controlled
programming. The user performs an action and your program reacts.
17 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
18 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Inheritance of classes
Inheritance is an important part of object-orientated programming. KBasic, like Java, supports
single inheritance, meaning every class inherits one parent class. It is not possible to inherit from
many classes. In the far future, it will be possible to use an interface to do many things you could do
with multi-inheritance. As in Java, all objects in KBasic are created with ‘New.' A class is a
collection of data and methods working on those data. Data and methods describe the content and
the behavior of an object.
Objects are instances of a class. You cannot do much with a single class but can do much more with
an instance of a class, a single object containing variables and methods. Object-orientated means the
objects are the centerpiece, not procedures and variables.
KBasic-Syntax
To read and write programs quickly you must know the syntax of KBasic. The syntax defines how
to write programs. It defines how to write each language element, how they work together, and how
to use them. The following pages cover these language elements.
Multi-Line statements
Normally every statement fits into one line, but sometimes is more readable to split one statement
into several lines. If so, use the line continuous underscore (_). In the following example the (_) is
used:
Sub field()
Dim myVar As String
myVar = "Bernd"
MsgBox Prompt:="Hello " & myVar, _
Title:="Hello"
End Sub
You can write many statements in one line using a colon (:) to separate the statements. For example:
Print „Hi“: Print „Ho“
19 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Variables can be declared everywhere in procedures, functions, and subs, not only at the top of
procedures, functions, and subs. However, most or the time they are at the top.
Sub doEvent()
Dim myName As Integer
End Sub
Every line of your source code can contain many declaration statements for many variables. Which
data type the variables have, depends upon the way you declare the variables. If you give every
variable explicitly a data type specifier, the default data type for variables will not be used. The
default data type depends upon the mode chosen for your program. In ‘KBasic Mode’ and
‘OldBasic Mode’ the default data type is ‘Variant,' in ‘VeryOldBasic’ it is ‘Double.'
Dim firstname, sirname, lastname As String
To use a data type you have to write it for every variable, otherwise the default data type would be
used. In the following statement all variables are declared as ‘Integer.'
Dim intX As Integer, intY As Integer, intZ As Integer
20 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
In the following statement intX and intY are declared as ‘Variant’ and intZ as ‘Integer.'
Dim intX, intY, intZ As Integer
Variables can have a start value for initial. In order to do so, you have two ways:
Either
Dim name = „sunny sun“ As String
or
Dim name As String = „sunny sun“
If many variables are declared in one line, only lastname has the value “sunny sun.”
Dim name, sirname, lastname = „sunny sun“ As String
21 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
A variable named sName with type of ‘String’ is declared in the following example:
Dim sName As String
If this statement is part of a procedure, then it is possible to use this variable in the same procedure
only. Is this statement part of a module declaration section, you can use it in all procedures of the
module, but not outside the module (in fact it is declared as ‘Private’ implicitly). To be able to use it
everywhere, you can use the keyword ‘Public’. Example:
Public sName As String
Use of the ‘Public’-Statement You can use the ‘Public’-statement to declare public variables in
module scope or class scope, making the variable accessible from everywhere.
Public sName As String
Use of the ‘Private’-Statement Use the ‘Private’-statement to declare private variables in module
scope or class scope, making the variable accessible only from the same scope (module scope, all
module procedures, class scope, all class methods).
Private myName As String
If the ‘Dim’-statement is used in module scope or class scope, it is treated as a ‘Private’-statement.
Use the ‘Private’-Statement to have cleaner, more readable code.
Use of the ‘Protected’-Statement Use the ‘Protected’-statement to declare protected variables in
class scope, making the variable accessible from within the same scope (class scope, all class
methods, sub-classes, all sub-classes methods). This allows you to underline the inheritance
hierarchy of your classes.
Protected myName As String
Use of the ‘Static’-Statement Static has three different meanings, depending upon the context used.
• Static inside a class, but outside a method. If you use a ‘Static’-statement instead of a
‘Dim’-statement, the variable is declared as class variable, meaning it can be used without
instance (objects) of this class. A class-variable exists only one time at runtime.
• Static outside a class, but inside a procedure (sub or function) or method. If you use a
‘Static’-statement instead of a ‘Dim’-statement, the variable is declared as local static
variable. The variable, once it has been declared, it is not destroyed by leaving the
procedure. The next time the procedure is entered, the value of the variable still exists.
Therefore, a local static variable is only one time declared when using recursive calls of a
procedure.
• Static outside a class, but before a procedure (sub or function) or method. If you use a
‘Static’-statement before the keyword ‘Sub’ or ‘Function’ all local declared variables are
declared as ‘Static’ variables, which means that a variable, once it has been declared, it is not
destroyed after leaving the procedure. The next time the procedure is entered, the value of
the variable still exists. Therefore, a local static variable is only one-time declared when
using recursive calls of a procedure.
You can add the keyword ‘Static’ to other keywords (‘Public’, ‘Protected’, ‘Private’).
22 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
special mode in which all variables are declared automatically when using a variable name that has
not been used before. Important! You should not use this mode unless you want to use old BASIC
code without changing it. Good programming style dictates declaring all variables with their types.
This also makes it easier for others to understand your code and minimizes typing errors.
In order to activate implicit declaration, write the following line in top of your program:
Option OldBasic
Option Explicit Off
Use of the ‘Option Explicit’-statement (supported within ‘Mode OldBasic’ and ‘Mode
VeryOldBasic’ only) As mentioned previously, you can implicitly declare a variable in KBasic by
using a assignment statement or expression with the variable name. All implicitly declared variables
have the data type ‘Variant’ (‘Option OldBasic’) or ‘Double’ (‘Option VeryOldBasic’). Variables of
type ‘Variant’ need more space in memory than most of the other data types. Your program is faster
when you explicitly declare your variables with the smallest data type possible. Another advantage
is that using declaration avoids name collisions or typing errors.
To explicitly declare variables within ‘Option OldBasic’ or ‘Option VeryOldBasic,' write on top of
all module and class files ‘Option Explicit On.' This creates a compilation error when a variable
name is not declared. If you are using the ‘KBasic Mode’ you must declare all variables. It is like
‘Option Explicit On.' By the way, the ‘KBasic Mode’ is set to default in all programs.
Important! You must declare dynamic arrays or fixed arrays at all times. Furthermore, you can mix
the modes in your program. One file is set ‘Option OldBasic,' another file is set ‘Option
VeryOldBasic.' You are free to set ‘Option Explicit Off’ for the old modes.
Local variables
The value of a local variable is available inside the procedure only. You cannot access the value
from outside the procedure. This makes it possible to have the same variable name for different
variables in different procedures without name collision.
Example:
Sub test1()
Dim i As Integer
i = 1
End Sub
Sub test2()
Dim i As Integer
i = 19
End Sub
Assignment-statement
Assignment-statements give or assign a variable a value or expression with variables, constants,
numbers, etc. An assignment always includes a sign ( . The following example shows an
assignment.
Dim yourName As String
yourName = InputBox("What is your name?")
23 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
You do not need the ‘Let’ keyword. It is outdated and optional. An example shows how to ‘Let’:
Let yourName = InputBox("What is your name?")
Use the ‘Set’ statement VB6 to assign an object to an object-variable. ‘Set’ is not needed in KBasic
and must not be used. After the declaration of a variable, you can use it, e.g. make an assignment (
.
Dim Cool As Boolean
Dim myName As String
Cool = True
Name = „Julie“
Lifetime of variables
The lifetime of variables is the time in which the variable exists or has a value. The value of a
variable can be changed during its lifetime. If a variable is outside its scope, it has no value. If a
procedure is executed, a variable exists after its ‘Dim’-statement. Local variables exists until the
procedure completed; after reentering the procedure all variables are created again after their
respective ‘Dim’-statements.
If you do not change the value of a variable during its lifetime in a program, it contains the
initialized value at program start. A variable declared in a sub contains an assigned value until the
sub is left. If the same sub is called again, the value is reset to the initialized value.
When using static-declared variables in procedures, the variables only exist once in memory, unless
the procedure is called multiple times using recursion. If you use global-declared module variables
or class-variables, it is the same. The variables exist once in memory at runtime. If you use
instance-variables you must consider that they only exist together with the instance (object) to
which they belong.
Place of declaration
Declare every variable and every procedure inside a class or at least inside a module.
Syntax:
Data Types
Data types describe the type of data stored inside a variable. If you declare a variable you must also
give it a data type. KBasic supports all VB6 data types and much more. You can use one of the
following data types:
24 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
25 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
• User defined data type / see next chapter - size depends on its elements
Type Name
Name [(Index)] As Type
...
End Type
Class types/Objects
Variables can store objects (actually, references to objects). These variables are object variables of
data type ‘Object’ and are 4 bytes. Unlike in VB6, assignment of objects to an object variable do not
need the ‘Set’-keyword. The '='-statement is recognized by KBasic correctly.
Though an object variable can contain any object (actually, the reference to that object), the binding
is done at runtime (late binding). If you would like to have early binding, use a class that inherits
the object class, like TextBox. Force early binding using a cast statement, too.
Type Variant
The data type ‘Variant’ is automatically used if you do not specifiy a data type for an argument,
constant, procedure or variable. An exception, is using a variable in ‘VeryOldBasic’-Mode. It has no
‘Variant’ but ‘Double’-data type. Variables of type ‘Variant’ can contain strings, dates, time values,
boolean values or even numerical values. The size of ‘Variant’ is 40 bytes. Accessing variant data
types is slower. The following example creates two variables of type ‘Variant’:
hisVar = 3
Dim myVar
Suffix of variables
Names of variables can determine their data types. Historically, you can append a special symbol
showing the variable’s data type. KBasic supports this old style of programming for historically
reasons. Example:
Dim i% ' Integer variable
Dim l& ' Long variable
26 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Comments
The comment symbol (') is used in many code lines in this book. Comments can explain a
procedure or a statement. KBasic ignores all comments while compiling and running your program.
To write a comment, use the symbol (') followed by the text of the comment. Comments are printed
in green on screen. KBasic recognizes four ways to write comments, as shown below.
REM this is a comment
Comments are extremely helpful when it comes to explaining your code to other programmers. So
comments, normally, describe how your program works.
Way of naming
When coding in KBasic, declare and name elements, like procedures (functions and subs),
variables, and constants and so on. All names
• must start with a letter;
• must contain letters, numbers, or the sign (_); periods and commas are forbidden;
• must not be longer than a defined length; and
• must not contain reserved words
A reserved word is a part of KBasic and has a predefined meaning. These include keywords (e.g.
‘if’ or ‘then’), builtin-functions (e.g. ‘mid’) and operators (e.g. ‘mod’). A complete list of reserved
words is at the end of this book.
Literals
Besides keywords, symbols, and names, a KBasic program contains literals. A literal is a number or
string representing a value. There are different numerical literals.
• Byte, Short, Integer, Long - 1, 2, -44, 4453
• Hex - &HAA43
27 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
• Binary - &B11110001
• Octal - &O1234
• Single (Decimal), always English formatted - 21.32, 0.344, -435.235421.21
• Double (Decimal), always English formatted - 212.23
• Currency, always English formatted - 45.3@
• Date / Time, always English formatted - #1993-12-31#
• String - Is simply text, but it must start with a (“) and end with a (“) so that KBasic can
recognize it as string. A double (“) inside a string is interpreted as single (“). There are no
escape sequences like in C++. They can be used with builtin-functions. Unicode is supported
in future.
• Boolean - When you cast a numerical value to Boolean. Values with 0 are ‘False’. Values
with -1 are ‘True’.
Expressions
Expressions stand for values. They can contain keywords, operator, variables, constants or even
other expressions. Examples for expressions are:
• 1 + 9 (number operator number)
• myVar (variable)
• myVar TypeOf Object (variable keyword classname)
Expressions can return a value or not. If an expressions is to the right of an assignment statement (
, the expression gives or must give a value back.
myVar = 1 + 9
1 + 9 is 10 and this expression value (10) is stored in myVar. It is exactly the same when the
expression is used as a parameter in a function call.
MyProcedure(1 + 9)
Expressions are calculated at runtime and represents a value. The result can be assigned to a
variable or to other expressions listed above.
Constants
Constants are similar to variables but they cannot change values. When you declare a constant you
assign a value to it that annot be altered during lifetime of your program. Example:
Const border As Integer = 377
This ‘Const’-Statement declares a constant border with data type ‘Integer’ and a value of 377. Use
the same rules for declaring constants as for variables. A ‘Const’-statement has the same scope as
the variable statement. To declare a constant inside a procedure, place the ‘Const’-statement inside
this procedure (normally one of the first statements). To declare a constant as accessible for all
procedures, place it within the module (or class) where the procedures are.
This ‘Const’-Statement declares a constant conAge as public with data type ‘Integer’ and a value of
34.
Public Const conAge As Integer = 34
Constants can contain all simple data types: Boolean, Byte, Short, Integer, Long, Currency, Single,
28 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Double, Date, String or Variant. You can also declare many constants in one line.
Const conAge As Integer = 39, conSalary As Currency = 3500
Const Name [As Type] = Expression [, Name [As Type] = Expression] ...
Normally, the result has the data type of the operand (= expression) with more precision.
Assignment-operators
At this time, KBasic supports more than the normal assignment operator ( . Like C++, KBasic
supports the extended assignment operators.
• += Add-Assignment (e.g. var += 1 is like var = vara + 1)
• -= Subtract-Assignment (e.g . var -= 1 is like var = vara - 1)
29 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Comparision
KBasic has different operators to compare expressions: These operators compare between two
operands (expressions) and the result is ‘True’ or ‘False’:
• = Equal - e.g. x = 3
• <> Unequal - e.g. x <> y
• < Smaller - e.g. x < 3
• > Bigger - e.g. x > 4
• ⇐ Smaller or equal - e.g. x ⇐ 4
• >= Bigger or equal - e.g. x >= 3
If you use the bindings, you can use further C/C++-comparision operators like ==-Assignment. See
binding documentation for more details.
If you use the bindings, you can additionally use further C/C++-comparision operators like ==-
Assignment. See Binding documentation for more details.
30 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Other Operators
• ^ Power - Useful if you want to use power. If they are many powers in one expressions they
are processed from left to right.
• Like - Useful to compare two strings (using a pattern). If string and pattern match, the result
is ‘True’.
• New - creates a new object using a class
• ( ) or [ ] - Accesses indexes of arrays or argument holders for procedures
• . dot operator - Needed for calling methods or elements in types or enumerations
• & String concatenating - Appends one string to another
• Eqv - means x Eqv y = Not (x Xor y)
• Imp - means x Imp y = Not (x And Not y)
• Is – Determines if two objects are based on the same class.
If you use the bindings, you can use the following C/C++-operators. See binding documentation for
more details.
• ++ increment
• – decrement
• [ ] index access
• |= or-assignment
• &= and-assignment
• | or
• ! not
• == is equal
• != unequal
• ^= power-assignment
• « shift left
• » shift right
String concatenating
It is possible to add two strings, or append one string to another. The result is data type ‘String’. To
append, there exist two operators: '+' and '&'. The '+' works incorrectly when one operand is a
different type than ‘String’. To be sure of the correct types, use '&' for string concatenating.
• '+'
• '&'
Example: Name + “is a” + color + “bird” If the first operand is a string, using '+' forces all other
operands to be treated as strings.
Operator order
KBasic supports die operator order of VB6. Normally, an expression is executed from left to right
following standard mathematical rules.
e.g: x = 10 + 10 / 2 results in 15 and not 10, because / is calculated before +. Here is the overview
about operator order/priority from top to bottom, which means ‘*’ is executed before ‘And.' The
bindings operators are included in braces ():
• 1. . ( ) [ ]
• 2. Not, BitNot, !, ++, –, (unary +), (unary -)
31 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
• 3. New
• 4. ^
• 5. * / \ Mod
• 6. + - &
• 7. Imp Eqv
• 8. < > ⇐ >= = Is Like == !=
• 9. And BitAnd (& C/C++ And)
• 10. Or Xor BitOr BitXor (| C/C++ Or) (^ C/C++ Xor)
• 11. AndAlso
• 12. OrElse
Use paranthesis () to change the order. e.g. X = (10 + 10) / 2 results in 10 and not 15, because + is
calculated before / thanks to the braces.
32 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Use of New
A variable, which contains the object and is declared, does not create the object at once. This
variable only has the data type of an object and represents only a reference to an object still to be
created. Create objects using the special keyword ‘New.' This creates an object by giving it the
desired class name and returns a reference to the new object. The reference is stored in a variable of
the class type. In this way, creating objects in KBasic is the same as for Java or C++. Example:
s = New Control()
You do not need to use the braces (), but when creating an object you have arguments that must be
written inside braces. ‘New’ is followed by the class name of the new object. The class has a special
procedure called constructor, called by ‘New’.
This constructor does some initial work for an object and returns a reference to the new created
object. Unlike regular procedures, you cannot call a constructor by calling it directly; instead
constructors are called by KBasic automatically when you create a new object with the ‘New’
command. Yet another example:
s = New Timer(begin, end)
Several Constructors
Sometimes, you may want to use an object differently or perform the initial stuff differently. You
can do so by using different constructors for the same class. Every class can have different
constructors with different arguments.
Example:
Class test1
Constructor test1()
End Constructor
33 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
End Class
Objects that are no longer referenced are automatically deleted by KBasic. This happens when no
object variable references to the object because the object variable has been deleted or the value has
been explicitly set to ‘Null.' For example:
objectVar = Null
objectVar = Nothing ' old style
You do not have to release objects, you can just forget about them. This is much different from C++
and other programming languages.
Create a class
Normally every class is a child of the special class ‘Object’ directly or indirectly through another
class. A class can inherit from another class (be child of that class). The declaration of a class
consists of a class name and the parent class name. Furthermore, you have constructors, sometimes
destructors, some variables (class-variables and instance-variables), and procedures (methods, class-
methods, instance-methods) and, of course, some properties and constants.
Class oak Inherits tree
Parts are:
Variables/ Constants / Properties / Types / Enumerations
Constructors
Destructors
Functions
Subs
End Class
A class can only be declared inside a module-file (not recommended) or inside a class file. To
declare a class inside a form-module-file is not possible, though actually it contains a class that
inherits from class ‘Form’ implicitly. It is possible to declare many classes in one class-file.
34 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Accessing objects
Accessing objects is done by using the dot operator (.).
Example:
classeName.variable
This syntax is quite the same as accessing elements of user defined types (‘Type’ … ‘End Type’).
When accessing class-variables, use the class name. When accessing instance-variables, use the
name of the object variable:
className.classVariable
objectName.instanceVariable
Important! Class-variables only exist one time, so it is not important how many objects of that class
exists. The class itself exists only one time, so do the class variables. You can use the class-variables
without having created an object of that class before. The class is available while running your
program at any time. It is like a global variable
However, instance-variable are part of an object of a class, so a instance-variable exists how often
objects exists of that class and only at during the lifetime of the object. If you declare a variable
inside a class, you can mark a variable with the keyword ‘Static’ if it should be a class-variable. If
you do not, it is by default a instance-variable. Example:
Static myClassVariable As Integer
Private myInstanceVariable As String
Another example:
myClass.classVariable = 23
Dim o As myClass
35 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
When you define a method, use the keyword ‘Static’ to define a class-method. If you leave it out,
the method is by default an instance-method.
Example:
Static Sub myClassMethod()
...
End Sub
Sub myInstanceMethod
...
End Sub
Calling methods
Again, use the dot opertator (.) to access the methods.
myObject.myMethod()
References to objects
Using the '='-Assignment you can assign a reference of an object variable to another object variable.
Both variables then reference the same object.
Example:
Dim i As tree
Dim s As tree
i = New tree
s = i
Both variables then reference the same object. Important! ‘Set’ known from VB6 is not allowed and
not needed to assign objects in KBasic, because it is obsolete.
Copying objects
Because objects are not passed by values in procedures, an assignment of an object does not copy
an object. Instead you must provide proper methods in the classes that can copy an object. In the
future, KBasic will provide objects with a clone method to copy objects.
Comparision of objects
The '='-comparison operator tests if two object variables reference the same object,not if both
variables’ objects have the same content. Instead you have to provide proper methods in the classes
to compare objects. In the future, KBasic will provide objects with a compare method that will be
able to compare objects. This will be the equals method.
36 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Accessing by index:
Sub myClose()
Forms(1).Close
End Sub
Accessing by name:
Sub closeForm()
Forms("myForm2").Close
End Sub
If the collection contains methods usable for all elements of that collection, you can access it using
the collection name and the desired method.
Sub closeAll()
Forms.Close
End Sub
A method is part of an object and contains executable code, which can be called at any time.
Sub addNewEntry(newEntry As String)
Combo1.Add(newEntry)
End Sub
A property is part of an object that stores a values like size, color, or position of an object. You can
change the value of a property by writing the object name, a dot (.), property name, equal sign (
Some properties are only readable. See the proper help entry of a property for more details. Getting
a property value:
An event is an action recognized by an object, e.g. if someone clicked with the mouse or pressed a
key then an event procedure is executed. Event procedures can be called by system events or
manually by your program, like normal procedures.
Sub CheckBox1_Click(.....)
Print "Hi"
End Sub
37 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
When using an object variable without a declaration, the object variable has the default data type
‘Variant’ (using without declaration is possible only in OldBasic Mode!).
The declaration of an object variable with data type object is useful when you do not know which
object type you would like to have in a generic sub.
If you know the specific object, declare the object variable with the same data type as the object.
Example with normal object type and specific object type:
Dim Objekt1 As Object ' Object
The declaration of specific object types has some advantages, such as type checking and more
readable or faster code execution.
Combine the declaration of an object variable with the creation of an object when you use the
keyword ‘New’ and the '='-statement.
Example:
Dim Object1 As Object = New Object ' creation and assignment
When assigning the value ‘Null’ to an object variable that has previously contained an object
reference, use the object variable to avoid accidentally changing the object. Example:
If Not Object1 Is Null Then
' object variable references an object
...
End If
38 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Sub printName
print sMovieName
End Sub
End Class
End Class
Dim k As Integer = 9
m.printName()
39 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Upcasting, the object ‘h’ contains lesser methods, variables than ‘m’ and is therefore reduced:
Dim h As Control
Dim k As CommandButton ' control is parent class
h = k
Comparing objects
When using '=' with object variables in an expression, the expression becomes ‘True’ if both
variables points to the same object. To compare both objects’ variables or contexts, you must
provide proper methods inside the classes used to compare these objects.
Returns ‘True,' if the class name is the seeked name, or ‘False’ if it is different Syntax:
TypeOf objectVariable Is ClassName
40 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Sub printName
print sMovieName
End Sub
End Class
Because, every class has a parent class, all classes forms together a class hierarchy (or inheritance
hierarchy). The inheritance hierarchy like a tree, with a root (parent class ‘Object’) and many twigs
(many child classes).
Constructor chaining
When declaring a class, KBasic guarantees that the class can be used to create an object because it
automatically inserts a hidden default constructor with no arguments that is called when using this
class without arguments. If you create a constructor, KBasic looks after the first statement in this
constructor and inserts an automatic constructor call for the parent class if there is no explicit call
for the parent constructor. The hidden default constructor can always be overridden.
The call of constructors is like a chain. All constructors are connected together. Every time you
construct a object, it follows all constructors of all parent classes up to the parent class ‘Object.' The
first constructor called is the constructor of ‘Object,' then the child constructors of the child classes.
Hidden Variables
An existing variable in a parent class can be overloaded by a variable in the child class through
inheritance, though it is possible to access both variables with the same name. It is called hiding,
because it is not automatically visible anymore. To access the parent variable, enter ‘Parent’, dot (.)
and the variable name:
Parent.myVariable ' access parent variable
myVariable ' access me variable
Hidden Methods
An existing method, like a variable, in a parent class can be overloaded by a method in the child
class through inheritance, though it is possible to access both methods with the same name. This is
called hiding, because it is not automatically visible anymore. Hidden methods are also called
41 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
overridden methods. Overriding takes place if the child class has a method with the same methods’
signature (name, return type, same arguments) as the parent class. The parent method is now
overridden. If you would like to access the parent method, enter ‘Parent’ dot (.) and the method
name:
Parent.myMethod() ' access parent method
myMethod() ' access me method
Overriding methods
Overriding occurs if the child class has a method with the same method signature (name, return
type, same arguments) as the parent class. The parent method is now overridden. If this method is
called within the child class, the new defined method is used, even by the parent methods (included
by the child class).
Overriding methods is a very important technique in object-orientated programming. However, do
not confuse overriding with overloading. Overloading means having many methods with the same
name in a class but with different method signatures (different return type or arguments).
KBasic treats variables and methods equally within a class. It is no different when it comes to
overriding methods and hiding variables. You can easily access hidden variables by casting its type
to the parent type or using the keyword ‘Parent’. The difference is an internal meaning because
variables are different when used in child and parent class (they actually use their own variable),
while methods are used by both (both parent and child class use the same method!).
Dynamic-searching of methods
While compiling, KBasic cannot know which methods in which class should be called because it
could be coded to dynamically search at runtime. This is called late binding, meaning it is not as
fast as early binding that takes place when you call functions or procedures of a module.
Function f()
Return i
End Functon
End Class
Class B Inherits A
Dim i As Integer ' this variable hides i in A
42 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
If you override a method, you have two methods: the old method in the parent class and the new
method in the child class. Access the old method explicitly using ‘Parent.' Access the new method
using ‘Me’ or the standard call of a method. A further example:
' class example
Class being
Constructor being()
Print "being.Constructor!!!!"
End Constructor
Sub cry()
Print "being.cry"
End Sub
End Class
Constructor body()
Print "body.Constructor!!!!"
End Constructor
Sub cry()
Print "body.cry"
End Sub
End Class
Constructor face()
Print "face.Constructor!!!!"
End Constructor
Sub cry()
Print "face.cry"
End Sub
End Class
' polymorphism
l[3].cry()
l[4].cry()
l[5].cry()
Hiding data
Hiding data (variables and constants…) is a very important technique in object-orientated
programming. Hiding data means not all data in a class can be accessed by other modules or
43 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
classes, but through methods of the same class in which the data is present so that it is only visible
within this class. This helps reduce mistakes when using internal data of a class by other classes or
modules. You have public methods and variables that are accessible by all others and you have
private methods and variables that should only be used by the class itself and those public methods.
Further reasons for hiding data are:
Internal variables, which are externally visible, mixing up the API for other coders etc. Hiding them
leads to small, smart classes with a few variables and methods visible to others. If a variable is
visible you must document it. Hiding variables reduces documentation time.
Scope modifiers
To hide variables or methods you must declare them as ‘Private’:
Class plane
End Class
A private variable is visible for the class in which it has been declared. This means the methods of
this class can only use this private variable. Private methods and variables are not visible to child
classes of the class in which they are declared (in fact they are present in the memory of that object,
but not visible). Non-private methods and variables are always visible to child classes.
Besides ‘Private,' there exists ‘Public’ and ‘Protected’ as scope modifiers. Protected is useful if the
variable or method should be visible only to child classes and the class in which they are declared.
Public means that every part of your program (any other class or module) can access and use the
public declared part of your class (variable or method). The default modifier is ‘Public.' If you do
not write ‘Public’ in front of your variable or method, it is automatically declared as public.
44 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
An abstract class cannot be used to create an object. A child class of an abstract class can be used to
create an object if all abstract methods have been overridden with a code implementation. It is non-
abstract now. If a child class of an abstract class does not override all abstract methods it become an
abstract class.
Arrays
If you have worked with other programming languages, you understand the concept of arrays.
Arrays are variables that look like a chain. All elements of that chain have the same data type and
can be accessed by an index. These variables have one name but a different index and are placed as
one block in memory. You can use the array as one block or as one element of the array. Arrays are
declared the same as other variables are declared (use ‘Dim’, ‘Static’, ‘Private’, ‘Public’ or
‘Protected’).
Using arrays leads to cleaner, more flexible code because you can use loops to use or access
thousands of variables (the arrays). Arrays have an upper and a lower boundary and elements of that
array are between those boundaries. If an array has the data type ‘Variant,' each element of the array
can contain a different data type.
Declaration
Declare an array using ‘Dim’ and length declaration in ( ) or [ ]:
Syntax:
Dim variableName(Index) As Type
Example:
Dim i(100) As Integer
Creates an array with 100 'Integer'-variables.
Accessing array elements
Access an element of an array when you write an integer expression in braces ()
or [] after the name of an array:
i(3) = 10
45 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
The index is always checked. If it is too small or too big you run into an error. This is a further
feature of KBasic to avoid program crashes. The expression, which stands for the index, can be
calculated at runtime. Any numerical expression is allowed:
n = 100
Dim i(n) As Integer
Default: An array with declared 10 elements is counted from 0..10 (including 10). Therefore, 0 and
10 are usable indexes and there are 11 elements declared. In fact, an array contains always one more
element than declared when you do not specify lower and upper bound.
Explicitly declaring the lower bound
Dim i(50 To 100) As Integer
Sub createArray ()
Dim curCosts (364) As Currency
Dim intI As Integer
46 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
An array with two dimensions is like a matrix. The first argument can be considered the row and the
second the column. If you use arrays with two dimensions or more, you can easily use the ‘For-
Next’ loop to iterate and access the elements of that array.
Sub changeArray ()
Dim intI As Integer, intJ As Integer
Dim sngMulti(1 To 5, 1 To 10) As Single
You can also use the ‘Array’-Function, which returns an array of type ‘Variant’ to create an array.
Example:
Dim varDaten As Variant
varData = Array(" Christiane Roth", "60529 Frankfurt", 26)
Accessing the array is the same for both methods: use the index. Example:
Print "Data " & varDaten(0) & " has been stored."
Reserve the right count of array elements with ‘Redim.' The statement ‘Redim’ can only be used
inside procedures. It has the same syntax as ‘Dim.' Every ‘Redim’-statement can change the number
47 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
of elements and also the lower and upper bound of that array. The number of dimensions cannot be
changed with ‘Redim’.
Every time you use ‘Redim,' all values of the array are deleted if you do not use the keyword
‘Preserve.' KBasic sets the values to ‘Empty’ (when type is ‘Variant’), or value 0 (numerical types),
or “” (if ‘String’). Object types will be ‘Null’. Example:
Function calc() As Integer
Dim Matrix1 () As Integer
Syntax:
Redim variableName(Index)
Redim variableName[Index]
Array-reset / array-delete
The command ‘Erase’ deletes arrays and frees the memory of arrays.
Erase array1[, array2]
Decisions
The term ‘decisions’ refers to the use of conditional statements to decide what to execute in your
program. Conditional statements test if a given expression is ‘True’ or ‘False.‘Then, statements are
executed. Normally a condition uses an expression in which a comparison operator is used to
compare two values or variables. KBasic supports all VB6 conditional statements and more.
48 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Single decision - If
A single decision is used to execute a set of statements if a condition is set (‘If’-statement). If the
condition is ‘True’ then the statements after the ‘Then’ are executed and the statements after the
‘Else’ are skipped. If the condition is ‘False,' the statements after the ‘Else’ are executed. If the item
after ‘Then’ is a line number, a goto is executed. If the condition is ‘True’ and there is no ‘Then’
statement on the same line, statements are executed until a line with an ‘End If’ is found. If you run
in ‘KBasic Mode’ the expression must be a boolean expression, otherwise any other numerical
expression is allowed. Syntax:
If Expression Then Statement
If Expression Then
[Statements]
End If
If Expression Then
[Statements]
Else
[Statements]
End If
If Expression Then
[Statements]
ElseIf Expression
[Statements]
Else
[Statements]
End If
If Expression Then
[Statements]
ElseIf Expression
[Statements]
ElseIf Expression
[Statements]
Else
[Statements]
End If
If Expression Then
[Statements]
ElseIf Expression
[Statements]
End If
49 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
‘Else’-statement if it is ‘False’. KBasic allows multi-line ‘If’-statements with ‘Else’ and ‘ElseIf’
cases, ending with ‘End If’. This works as zero is interpreted to be ‘False’ and any non-zero is
interpreted to be ‘True’
Example:
Dim i As Integer
Dim n As Integer
If i 1 Then
n = 11111
ElseIf i = 2 * 10 Then
n = 22222
Else
n = 33333
End If
IIf – short if
IIf returns a value of two values depending on an expression. Example: testing = IIf(Test1 > 1000,
“big”, “small”)
Syntax:
IIf(Expression, ThenReturnExpression, ElseReturnExpression)
Select Case
The ‘Select Case’-statement is much more complicated than the ‘If’-statement. In some situations,
you may want to compare the same variable or expression with many different values and execute a
different piece of code depending on which value it equals to. This is exactly what the ‘Select
Case’-statement is for. ‘Select Case’ introduces a multi-line conditional selection statement. The
expression given as the argument to the ‘Select Case’-statement will be evaluated by
‘Case’-statements following. The ‘Select Case’-statement concludes with an ‘End
Select’-statement. As currently implemented, ‘Case’-statements may be followed by string values,
in this case complex expression can be performed. The test expression can be ‘True,' ‘False,' a
numeric, or string expression. ‘Select Case’ executes the statements after the ‘Case’-statement
matching the ‘Select Case’-expression, then skips to the ‘End Select’-statement. If there is no match
and a ‘Case Else’-statement is present, then execution defaults to the statements following the ‘Case
Else.' Syntax:
Select Case Expression
Case Expression
[Statements]
Case Expression
[Statements]
End Select
50 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
[Statements]
End Select
Example:
Dim i As Double
Dim n As Integer
i = 4
Select Case i
Case 0
n = 0
Case 1, 2
n = 1122
Case 4 TO 10
n = 441000
Case Is = 9
n = 9999
Case Else
n = 999999
End Select
Syntax:
Switch(Expression, ReturnExpression[, Expression, ReturnExpression, ... ])
Syntax:
Choose(Expression, ReturnExpression[, ReturnExpression, ... ])
Unconditional jumping
Most of this chapter has been dedicated to conditional branches. If you recall, however,
programmers can also use unconditional branches. This type of branching can be performed using
the ‘GoTo’-instruction. ‘GoTo’ forces program execution to branch to a specific line number or
label. Because line numbers in KBasic programs are now obsolete, you do not have to worry about
how to use them. You may, however, want to use labels. ‘GoTo’ performs a unconditional jump.
51 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
GoTo myExit:
GoTo nextStep:
With-Statement A very useful statement is the ‘With’-statement. When using the ‘With’-statement,
you are able to group assignments or statements that reference the same object. This makes your
code becomes more readable in addition to reducing redundant code.
Sub formSection ()
With myClass.
.Value = 30
.Font.Bold = True
End With
End Sub
Loop-statements
The statements that control decisions and loops in KBasic are called control structures. Normally
every command is executed only one time but in many cases it may be useful to run a command
several times until a defined state has been reached. Loops repeat commands depending upon a
condition. Some loops repeat commands while a condition is ‘True,' other loops repeat commands
while a condition is ‘False.' There are other loops repeating a fixed number of times and some
repeat for all elements of a collection.
For Next
The For-Next loop is useful when you know how often statements should be repeated. For-Next
defines a loop that runs a specified number of times.
Syntax:
For counter = start To stop [Step stepExpression]
[Statements]
Next [counter]
‘Counter’ is a numerical variable used to store the current counter number while the loop is running.
‘Start’ is a numerical expression that determines the starting value of the loop countings. ‘Stop’ is a
numerical expression that determines the ending value at which the loop will stop. To count in steps
other than the default value of 1, use ‘stepExpression’ to determine a specific value for
incrementing the counter. If you use ‘Exit For,' this exits the ‘For Next’ loop immediately and
continues with the line following to the ‘Next’ statement. This is usually used in connection with an
52 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
‘If’ clause (If something Then Exit For) to exit the loop before its specified end.
The ‘Next’ statement is the lower end of the loop and increments ‘counter’ by the value given by
‘stepExpression’ or by 1 if no ‘stepExpression’ incrementation is defined. The loop repeats as long
as the value of ‘counter’ is smaller/less than or equals the value of ‘stop.' The indication of ‘counter’
may be left out for the ‘Next’ statement, however this is depreciated as it can lead to confusion
when nesting several ' ‘For Next’ loops.
Notes: The speed of ‘For Next’ loops depends on the variable types used. ‘For Next’ loops run
fastest when ‘counter’ is an integer variable and ‘start,' ‘stop,' and ‘stepExpression’ are integer
expressions. Count backwards using ‘stepExpression’ with a negative incrementation value. Take
extra care when nesting ‘For Next’ loops. Remember to end the loop last initiated (see example) or
an infinite loop occurs.
’ Example 1:
Dim ctr As Integer
For ctr = 1 To 5
Print "Z";
Next ctr
' Output:
' ZZZZZ
' Example 2:
' Here we use STEP
' The resulting string is the same
' as in example 1
' Output:
' ZZZZZ
' Example 3:
' These are nested loops.
' The "y" loop is the INNER one
' and thus will end first:
Dim x, y As Integer
For x = 1 To 5
Print "Line" + Str$(x)
For y = 1 To 5
Print "Z";
Next y
Print "-"
Next x
' Output:
' Line 1
' ZZZZZ-
' Line 2
53 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
' ZZZZZ-
' Line 3
' ZZZZZ-
' Line 4
' ZZZZZ-
' Line 5
' ZZZZZ-
Optimize For...Next-Loops
Use counter variables of type ‘Integer’ instead of ‘Variant,' because ‘Integer’ is much faster.
Example:
Dim rabbit As Integer ' counter of type Integer
The first example runs faster. The smaller the data type, the faster it runs. Variables of type ‘Variant’
are always slower than the directly used data type.
Sub SubAfter()
Counter = 0
myNumber = 9
Do
myNumber = myNumber - 1
Counter = Counter + 1
Loop While myNumber > 10
MsgBox "Loop has been executed " & Counter & " time(s)."
54 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
End Sub
Two possibilities allow you to use the keyword ‘Until’ to test a condition of a ‘Do…
Loop’-statement. You can test the condition before the loop (see procedure ‘SubBefore’ in the
example), or you can test the condition after the loop has been entered (see procedure ‘SubAfter’ in
the following example). The loop repeats as long as the condition is ‘False’.
Sub SubBefore()
Counter = 0
myNumber = 20
Do Until myNumber = 10
myNumber = myNumber - 1
Counter = Counter + 1
Loop
MsgBox "Loop has been executed " & Counter & " time(s)."
End Sub
Sub SubAfter()
Counter = 0
myNumber = 1
Do
myNumber = myNumber + 1
Counter = Counter + 1
Loop Until myNumber = 10
"Loop has been executed " & Counter & " time(s)."
End Sub
Do While...Loop
A ‘Do While’ loop is a group of statements enabling you to define a loop that will repeat until a
certain condition remains ‘True’. ‘Do’: launches the loop and must be the first statement ‘Loop’:
ends the loop and must be the last statement ‘While’: lets the loop repeat while the condition is
‘True’ Condition: a numeric or string expression with a result of ‘True’ or ‘False’ ‘Exit Do’: exits
the loop at this very line and lets the program continue behind the ‘Loop’-statement ‘Iterate Do’:
jumps directly to the ‘Loop’-condition
Syntax:
Do While Expression
[Statements]
Loop
Examples: In the first example, the loop repeats as long as ‘xyz’ remains 5:
Do While xyz = 5
(lines of code)
Loop
Please note the lines of code will never be executed if ‘xyz’ is not 5 when entering the loop. To
overcome the problem of “never executed code” move the condition to the end of the loop:
Do
(lines of code)
Loop While xyz = 5
Now the lines of code execute at least one time before the loop checks for the value of ‘xyz’ and
55 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
decides whether to exit or repeat execution. If there is a second condition that arises somewhere
within the loop making it necessary to exit the loop before the lines of code within it end, the
‘Exit’-statement may be helpful:
Do
(lines of code)
If abc = 0 Then Exit Loop
(lines of code)
Loop While xyz <> 5
If ‘abc’ becomes zero at the ‘If’-statement within the loop, the program exits the loop. The rest of
the code lines are skipped. Sometimes it is necessary to skip the rest of the code lines but
nevertheless stay in the loop to be repeated. Now you may use ‘Iterate’ instead:
Do
(lines of code)
If abc = 0 Then Iterate Loop
(lines of code)
Loop While xyz <> 5
If ‘abc’ becomes zero at any moment within the loop,the program skips the rest of the code lines
within the loop and jumps directly to its “Loop While xyz = 5." The loop checks for the value of
xyz and decides what to do. You may use the condition with a number of expressions like ‘And’ and
‘Or’:
Do While x < 10 And y < 10
(lines of code)
Loop
The loops repeats while x and y are smaller than 10. Note: Please be careful when nesting several
loops within each other. Sometimes a variable checked for the outer loop is changed within the
inner loop. In this case, the outer loop never ends:
Do While counter < 10
(lines of code)
counter = 0
Do
counter = counter + 1
Loop While counter <> 5
Loop
Good programming practice would recommend using separate variables for each loop. The same
might happen with a ‘For…Next’ loop within:
Do While counter < 10
(lines of code)
For counter = 1 To 5
(lines of code)
Next counter
Loop
56 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Next i
Do...Loop Until
A ‘do loop until’ repeats until a condition is set. Example:
x = 0
Do
Print x
x = x + 1
Loop Until x > 3
Syntax:
Do
[Statements]
Loop Until Expression
Do...Loop While
A ‘do loop while’ repeats while a condition is set. Example:
x = 0
Do
Print x
x = x + 1
Loop While x < 3
Syntax:
Do
[Statements]
Loop While Expression
Do Until...Loop
The ‘do until loop’ is a group of statements enabling you to define a loop that repeats until a certain
condition remains ‘True.'
x = 0
Do Until x > 3
Print x
x = x + 1
Loop
Syntax:
Do Until Expression
[Statements]
Loop
57 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
While...Wend
‘While’ initiates a ‘While…Wend’-loop. The loop ends with ‘Wend’ and execution reiterates
through the loop as long as the expression is ‘True’. Example:
While True
Print 1234
Wend
Syntax:
While Expression
[Statements]
Wend
While...End While
This is the same as ‘While…Wend’, but with slightly different keywords. This loop reiterates
through the loop as long as the expression is ‘True’.
While True
Print 1234
End While
Syntax:
While Expression
[Statements]
End While
58 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Iterate For
Iterate Do
Procedures
Your programs have been short, each designed to demonstrate a single programming technique.
When you start writing real programs, however, you will discover they can grow to many pages of
code. When programs increase in length, they become harder to organize and read. Professional
programmers use modular programming to decrease the length of programs. Modular programming
uses procedures. A procedure is like a small program within your main program. KBasic source
code is inside a procedure, normally. A procedure is a set of commands inside the written words
‘Sub’ and ‘End Sub’ or ‘Function’ and ‘End Function’. There are different types of procedures.
• Sub (inside a module or class) - Sub-procedures contain commands and statements but do
not return a value or cannot be used in expressions. Event-procedures are always sub-
procedures. An event-procedure is related to a form or control. When KBasic notices an
event of a control occurred, it calls the related event-procedure.
• Functions (inside a module or class) - Function-procedures contain commands and
statements. Function-procedures always return a value, e.g. the result of a complex math
operation. Because functions return values, they can be used in expressions. Functions like
subs can have arguments.
• Sub (inside a class) - Better named as method, without return value. This is like a sub-
procedure.
• Function (inside a class) - Better named as method with return value. This is like a function-
procedure
Sub-Procedure
A sub-procedure can have arguments, e.g. variables, expressions, or constants that are given to the
sub-procedure while calling it. Many built in-functions of KBasic have arguments.
Syntax:
Sub Name([Arguments])
[Statements]
End Sub
Function-Procedure
A sub-procedure can have arguments, variables, expressions, or constants that are given to the sub-
procedure when calling it. Function-procedures return values. Many built in-functions of KBasic
59 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
End Function
Arguments
For all practical purposes, a procedure can have as many arguments as needed. You must be sure the
arguments you specify in the procedure’s call exactly match the type and order of the arguments in
the procedure’s sub line. To use more than one argument in a procedure, separate the arguments
with commas. You can pass one or more arguments to a procedure. Keep in mind the arguments are
passed to the procedure in the order in which they appear in the procedure call. The procedure’s sub
line must list the arguments in the same order they are listed in the procedure call. If a procedure
does not have arguments, you must not write any expression or variable inside the braces when
calling it.
All statements and commands are executed only after calling the procedure. Arguments have
names. If you have many arguments, you can separate them by a comma (,). Every argument is like
a variable declaration and leads to automatically declared variables when the statements and
commands of a procedure are executed.
Syntax of arguments:
Name As Type
The type can be one of the built in types (scalar types), ‘Variant’ or object/class type. If you do not
tell KBasic the type, it assumes the default type that is normally ‘Variant’.
‘ByRef’ and ‘ByVal’ are modifiers. If you call a procedure and one argument is a variable and the
matching argument is declared ‘ByRef’, then KBasic performs all operations on that argument on
the given variable and does not copy the variable’s value. ‘ByVal’ leads to a copy of the variable’s
value. If the commands inside the procedure changes the value of the argument, the variable is not
affected. If you use ‘ByRef’ it is changed!
60 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Named arguments:
PassArg(intAge = 26, birthDate := #2/28/79#, strName := "Frank")
If you use named arguments, you are able to list the arguments in the order as you like. It is
probably more readable. Example:
Sub passArg(strName As String, intAge As Integer, birthDate As Date)
Print strName, intAge, birthDate
End Sub
A named argument contains the argument name, colon (:) and equal sign ( , and the
expression the argument should have. Named arguments are also useful when you use procedures
with optional arguments. Optional arguments are not always present in the procedure, depends upon
if they have been given to the procedure. Optional arguments can have default values as seen in the
following example:
Sub optionaleArg(str As String, Optional strCountry As String = "Germany")
...
End Sub
If you do not give a optional argument to a procedure, the default value is used.
It might be useful to check the argument with the ‘IsMissing’-function:
Sub optionalArg(str As String, _
Optional strCountry As String = "Germany")
If IsMissing(strCountry) Then
Print str
Else
Print str, strCountry
End If
End Sub
You can call the procedure above with the following lines:
optionalArg(str := „test1“, strCountry := "Germany")
optionalArg(str := „test1“)
Arguments with a default value are also possible as seen in the following example:
Sub optionaleArg(str As String, strCountry As String = "Germany")
...
End Sub
Writing function-procedure
A function-procedure contains commands and statements, which are after ‘Function’ and before
‘End Function.' A function-procedure is like a sub-procedure but it can return a value. That is the
only difference between them. A function-procedure can also have arguments. A value can be
returned using the function name as an variable, which is used in an assignment statement (old
style). You should use the keyword ‘Return’ for return values (new style). Example:
Sub Main()
temp = InputBox(Prompt:= _
"Fahrenheit?")
61 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Function Celsius(fGrad)
Celsius = (fGrad - 32) * 5 / 9
End Function
Main()
Sub MultiBeep(no)
Dim counter As Integer
For counter = 1 To no
Beep
Next counter
End Sub
Sub DoMessage()
Print "Tee time!"
End Sub
Main()
62 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Leave procedure
You can leave the procedure at any line inside of a procedure. For that, use the keywords ‘Exit Sub’
inside a sub-procedure or ‘Exit Function’ inside a function-procedure.
Syntax:
Exit Sub
Calling procedures with more than one argument The following example shows calling a sub-
procedure with more than one argument.
Sub Main()
costs (99800, 43100)
Call costs (380950, 49500) ' old style
End Sub
If you do not need the return value, ignore it and use the function-procedure like an ordinary sub-
procedure. Example:
MsgBox "Task done!"
These errors can be hidden when two procedures are calling each other once and once again or if no
break out condition is used. In some situations recursive procedures might be useful. Example:
Function Fakulty (N)
If N <= 1 Then ' end of recursive
Fakulty = 1 ' (N = 0) no more calls
Else ' Fakulty is called again
' wenn N > 0.
Fakulty = Fakulty(N - 1) * N
End If
End Function
63 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Carefully test a recursive procedure to verfiy it works as expected. If an error occurs, check the
break out condition. Try to minimize memory consumption:
Overloading of procedures
In other languages, the name of the method (or function, or procedure) is enough to distinguish it
from other methods in the program. In KBasic, procedures are not only distinguished by their name
but also by their arguments. If you call a procedure and there are two or more procedures with the
same name, KBasic tries to verify which procedure you mean by checking the arguments.
Defining procedures with the same name, but different arguments is called overloading. It might be
useful in some situations. Do not mix it up with overriding.
Event procedures
When KBasic recognizes that a form or control has raised an event, it automatically calls the related
event-procedure within a form.
General procedures
KBasic calls an event-procedure after an event occurs. Normal procedures are only called explicitly.
If you need several event-procedures to perform a task, create one sub-procedure that is called
inside the event-procedure. This is better than copying all code in each event-procedure and
duplicating code. Create normal procedures in forms or modules. If the normal procedure is related
to a form only, place it there. If it is related to the entire program, place it in a module.
Functions
Functions are very similar to subs in that both are procedures, but functions return a value and can
be used in expressions.
Syntax:
Function Name([Arguments])[As Type]
[Statements]
End Function
64 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
you also define a return type, which is the data type of the function. If you do not define a return
type, the default data type is assumed to be ‘variant.'
Function Return
If you would like to set the return value of a function and exit the function, use ‘Return.' With this
statement you immediately leave the function.
Syntax:
Return Expression
Properties
Most objects and controls have properties that you can think of as nothing more complicated than
attributes. For example, a ‘CommandButton’ control has a property called ‘Caption’ that determines
the text that appears in the button. Many other controls, such as the familiar ‘Label’ control, also
have a ‘Caption’ property. Some properties are common in KBasic whereas others are associated
with only a single control or object. Those properties are built into KBasic, but it is also possible to
define your own properties within your user defined class.
Defining a property is like defining a procedure. In fact, a property contains two property-
procedures. One property-procedure reads the property (Get) and the other writes the property (Set).
Additionally, you have to declare a variable that contains the value of the property. Why should I
use a property, when I use a variable instead? It is easier to access a variable but it might be useful
to check something when accessing a variable; with properties you are able to check values or
conditions when you try to access the property. It is like data hiding. You can code so that the value
of the property is always correct.
For details, please refer to the examples that come with KBasic.
Syntax:
Property Set Name(Argument)
[Statements]
End Property
Get
[Statements]
End Get
Set(Argument)
[Statements]
End Set
End Property
65 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Conversion
Normally you do not have to change the a data type of an expression. It is usually done for you
without notice. Sometimes it might be important to force a conversion because your calculating
would be else wrong. There exists some conversion built in-functions for any data type:
y% = CInt (expression) ' returns Integer
y% = CLng (expression) ' returns Long
y! = CSng (expression) ' returns Single
y' = CDbl (expression) ' returns Double
y@ = CCur (expression) ' returns Currency
y = CVar (expression) ' returns Variant
y = CBool (expression) ' returns Boolean
y = CByte (expression) ' returns Byte
y = CShort (expression) ' returns Short
y = CDate (expression) ' returns Date
Modifiers / Scopes
Modifiers and scopes are a very important aspect of the KBasic programming language and of
modern programming languages in general.
Scopes tell KBasic when a variable, a constant, or a procedure can be used, from which place in the
source code files, actually. There are different scopes (abstract places in code):
• Procedure scope
• Global scope
• Private module scope
• Public module scope
• Private class scope
• Protected class scope
• Public class scope
Scopes are useful when you would like to organize your program or want to avoid name collisions
of variables.
When you refer to a variable within your method definitions, KBasic checks for a definition of that
variable first in the current scope, then in the outer scopes of the current method definition. If that
variable is not a local variable, KBasic then checks for a definition of that variable as an instance or
class variable in the current class, and then, finally, in each parent class in turn.
Because of the way KBasic checks for the scope of a given variable, it is possible for you to create a
variable in a lower scope such that a definition of that same variable hides the original value of that
variable. This can introduce subtle and confusing bugs into your code. The easiest way to get
around this problem is to make sure you do not use the same names for local variables as you do for
instance variables. Another way to get around this particular problem, however, is to use
‘Me.variableName’ to refer to the instance variable and just variable to refer to the local variable.
By referring explicitly to the instance variable by its object scope you avoid the conflict.
Local scope
A variable declared inside a procedure is not usable outside the procedure, only the code of the
procedure in which the variable has been declared can use it. The following example demonstrates
how a local variable may be used. There are two procedures, one of them has a variable declared:
66 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Sub localVar()
Dim str As String
str = "This variable can only be used inside this procedure"
Print str
End Sub
Sub outOfScope()
Print str ' causes an parser error
End Sub
Sub setPrivateVariable()
str = "This variable may be only used inside this module"
End Sub
Sub usePrivateVariable()
Print str
End Sub
All procedures are as default ‘Public’ except the event-procedures because KBasic automatically
writes ‘Private’ for every event-procedure declaration. If you want to have a normal procedure as
‘Private,' write the keyword ‘Private’ before the declaration of that procedure.
67 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Enum Name
Name [= Expression]
...
End Enum
Classes
A simple application can contain a form, while all source code is inside the form module of that
form. But if the application grows bigger and bigger it might be useful, to write source codes from
different forms at one place, so you need a place to write the source codes down outside the forms.
Here comes the classes. Create a class, which contains a methods, which is useful for your forms.
You KBasic code is stored in classes or modules. You can archive your code within classes. Every
class consists of the declaration part and the methods you have inserted. A class can contain:
• Declarations - for variables, types, enumerations and constants
• Methods (also called procedures) - which are not assigned to a special event or object. You
can create as many procedures as you want, e.g. sub-procedures without return value or
function-procedures.
• Signal/Slots-Methods - These are special methods, which are only useful together with the
bindings. See the documentation of the bindings in the KBasic IDE for more information.
• Properties - Are variables, which are accessed through two special methods (get and set
method). Properties are accessable without the need to write braces, when you use them.
You can put several classes or modules in one file, but you should not do that.
Edit Class
It is not much different editing text in a word processor or in KBasic’s Software Atelier. You have a
cursor showing the current position you can type. You can also find and replace inside your source
code as in a word processor.
Syntax:
[Abstract] Class Name Inherits ParentClassName
68 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Get
[Statements]
End Get
Set(Argument)
[Statements]
End Set
End Property
...
69 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
End Class
Bigger example:
Class Salsa Inherits Waltz
Const classConst = 4
Sub meExplicit()
Dim localVar = Me.publicInstanceVar ' it is the same with parent
Dim localVar2 = Me.publicClassVar
Dim localVar3 = Salsa.publicClassVar
Dim localVar4 = Salsa.classConst
Dim localVar5 = Me.classConst
'
Dim localVar6 As class_enum
localVar6 = Salsa.class_enum.Entry
' Dim localVar7 As Me.class_enum ' full type name not allowed
Dim localVar8 As class_type
End Sub
Sub meImplicit()
Dim localVar = publicInstanceVar
Dim localVar2 = publicClassVar
70 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
End Sub
Sub classSub()
Const localConst = 6
Dim n = localConst
End Sub
Get
Print "Hi"
End Get
End Property
End Class
Module
A simple application can consist of only one form while the complete source code is in one form
module. As your applications grow larger you probably would like to use the same code in different
forms. To do so, place this code in a global module file as it is accessible by the entire application.
You KBasic code is stored in classes or modules. You can archive your code within modules. Every
module consists of the declaration part and the procedures you have inserted.
A module can contain:
• Declarations - for variables, types, enumerations and constants
• Procedures - which are not assigned to a special event or object. You can create as many
procedures as you want, e.g. sub-procedures without return value or function-procedures.
You can put several classes or modules in one file but you should not.
71 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Global Modules
Global modules are always present. You can access them from everywhere in your program. Put
procedures you often use in forms or event-procedures within global modules.
[Public | Private]
Enum Name
Name As Type
...
End Enum
...
[Public | Private]
Type Name
Name As Type
...
End Type
...
[Public | Private]
Function Name([Arguments]) [As Type] [Throws Name, ...]
[Statements]
End Function
...
[Public | Private]
Sub Name([Arguments]) [Throws Name, ...]
[Statements]
End Sub
...
End Module
<code>
72 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Bigger example:
<code>
Module module1
Const moduleConst = 7
Sub moduleExplicit()
Dim localVar = module1.publicModuleVar
Dim localVar2 = module1.moduleConst
Dim localVar3 As module_enum
localVar3 = module1.module_enum.Entry
End Sub
Sub moduleImplicit()
Dim localVar = publicModuleVar
Dim localVar2 = moduleConst
Dim localVar3 As module_enum
localVar3 = module_enum.Entry
Dim localVar4 As module_type
End Sub
Sub moduleSub()
Const localConst = 6
Dim n = localConst
End Sub
73 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Sub subOverloading ( )
Print "sub1"
End Sub
subOverloading()
subOverloading(88)
Return "hello"
End Function
''i = i + 1
Return moduleFunctionRecursive(1)''i)
End Function
End Module
Error handling
Developers in any language always wanted to write bug-free programs, programs that never crash,
programs that can deal with any situation with grace and that can recover from unusual situations
without causing the user any undue stress. Good intentions aside, programs like this do not exist. In
real programs, errors occur either because the programmer did not anticipate every situation the
code would get into or because of situations out of the programmer’s control, bad data from users,
corrupt fields that do not have the right data in them, and so on.
Three possible error sources exist:
• Error while compiling - These kind of errors occur when statements are written incorrectly.
Maybe you wrote a keyword wrong, or misused a keyword in the wrong place, or you forgot
to write all needed marks (braces, dots and so on).
• Runtime error - These kind of errors occur when KBasic finds an error when your program
executes. An example of such an error is a division by zero, which is not allowed in any
math expression.
• Logic error – Logic errors occur when syntax and runtime behavior is okay, but the program
does not work as intended or expected. You can only be sure that your program works as you
want if you test and analyze any result.
When a runtime error occurs, KBasic stops the execution of your program if no error handler has
been defined in the place the error occurred. Old error handling syntax is supported like ‘On Error
GoTo,' but you should use the new error handling syntax (exceptions).
74 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Exceptions
In KBasic, the strange events/errors that may cause a program to fail are called exceptions.
Exception handling is an important feature of KBasic. An exception is a signal showing that a non-
normal stage has been reached (like an error). To create an exception means to signal this special
stage. To catch an exception is to handle an exception; performing some commands to deal with this
special stage to return to a normal stage.
Example:
Public Sub tt2() Throws samba
Try
test()
Catch (b As rumba)
Print "tt2: got you!"
b.dance()
Finally
Print "tt2: will be always executed, whatever happend"
End Catch
End Sub
Exceptions are walking from the origin to the next control structure (caller of the current
procedure). First it is tested if a ‘Try-Catch’-statement or a throw statement has been defined in the
current scope (procedure etc.). If not, KBasic looks up the caller of the current scope and tries again
to find a ‘Try-Catch’-statement or a ‘Throw’- statement and so on. If it is not caught, KBasic shows
the error to the user and the execution of the program stops. Exception-objects
An exception is an object that is an instance of a ‘Object’ or any other class. Because exceptions are
objects, they can contain data and methods as any other class or object. Exception handling
The ‘Try-Catch’-statement is needed to catch an exception. ‘Try’ encloses the normal code, which
should run fine. ‘Catch’ contains the commands that should be executed if an exception has been
raised. ‘Finally’ has some commands that should be executed whether an exception has happened or
not.
Try
'Try' encloses the normal code, which should run fine. 'Try' does not work
alone. It comes with at least one 'Catch'-statement or 'Finally'-statement.
Catch
After a ‘Try’ and its commands, define as many ‘Catch’-statements as necessary. ‘Catch’-statements
are like a variable declaration, but the exception object is only created, then it matches.
Finally
‘Finally’ is useful when you have file accessing or database closing commands that must always
execute even when an exception occurs. If you have defined a ‘Catch’-statement and
‘Finally’-statement and the matching exception is raised, first the ‘Catch’-statement executes,then
the ‘Finally’-statement.
Declaration of exceptions
KBasic demands that every procedure that can raise an exception must define a exception with a
‘Throw’-statement in its declaration. Example:
75 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
If an exception is thrown, the normal program execution is left and KBasic tries to find a proper
‘Catch’-statement for these exception. It searches all statements including the place the exception
was thrown. All ‘Finally’-Statements are executed on this path. To use exceptions is a creative way
of dealing with errors; it is easy and clean to read. Often you can use a simple error object, but
sometimes it is better to use a newly created error object. Syntax:
Try
[Statements]
Catch (Name As Exception)
[Statements]
End Catch
Try
[Statements]
Catch (Name As Exception)
[Statements]
Catch (Name As Exception)
[Statements]
End Catch
Try
[Statements]
Catch (Name As Exception)
[Statements]
Finally
[Statements]
End Catch
Complete example:
Class rumba
Sub dance
Print "rumba.dance"
End Sub
End Class
Class samba
Sub dance
Print "samba.dance"
End Sub
76 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
End Class
Try
test()
Catch (b As rumba)
Print "tt2: got you!"
b.dance()
Finally
Print "tt2: will be always executed, whatever happend"
End Catch
End Sub
tt2()
Catch (c As samba)
Print "tt: got you!"
c.dance()
Finally
Print "tt: will be always executed, whatever happend"
End Sub
tt()
tt2()
Catch (c As samba)
Print "tt: got you!"
c.dance()
Finally
Print "tt: will be always executed, whatever happend"
End Sub
Syntax:
Catch (Name As Exception)
[Statements]
77 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Finally
[Statements]
End Catch
Windows
KBasic windows are used to develop your programs, including monitoring the status of your
projects at any time. These windows include:
• Form designer – uses drag and drop controls, as well as arranges them in this main
development area. It is the primary tool you use to create your programs.
• Project window – works with the different parts of your project in the project window. Its
views include objects and files.
• Property window – lists and lets you control the properties for your controls. You can resize,
name, change visibility, assign values, and change colors and fonts of your controls.
• Toolbox window – the central place where often used controls can be accessed
• Source code editor – where you add and customize source code for your project in any phase
of the development cycle.
Toolbars
KBasic provides an extensive set of toolbars. Toolbars can be docked in the KBasic window or
floated on the screen.
Editor
KBasic has one editor for creating and managing KBasic projects. You can use this editor to control
the development of your projects, such as editing source code and manipulating classes. The source
code editor is a tool for editing source code.
Debugger
One of the most powerful tools in the KBasic environment is the integrated debugger (only in the
professional version). The debugger allows you to watch your programs execute line by line. As
your program executes, you can observe the various components of the program to see how they are
behaving. By using the debugger, you can monitor: the values stored in variables which
subs/functions/methods are called the order in which program events occur
78 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
control, is visible at runtime, and lets users interact with your application. It has a screen position, a
size, and a foreground color. Examples of visual objects are forms and buttons. An invisible object
is not visible at runtime, such as a timer. Some objects can contain other components, such as an
application window containing a button. With KBasic, you add visual objects/controls to your forms
to assemble applications.
Projects
Projects keep your work together. When developing an application in KBasic, you work mainly
with projects. A project is a collection of files that make up your KBasic application. You create a
project to manage and organize these files. KBasic provides an easy yet sophisticated system to
manage the collection of files making up a project. The project window shows each item in a
project. Starting a new application with KBasic begins with the creation of a project. So before you
can construct an application with KBasic, you need to create a new project. A project consists of
many separate files collected in one project directory, where one *.kbasic_project file is and many
other files:
• *.kbasic_module
• *.kbasic_class
• *.kbasic_form
Forms
In your Kbasic-application, forms are not only masks for inputting and changing data but they are
the graphical interface of your application. In the eyes of the beholder, they are the application! By
creating your application using forms, you control the program flow with events that are raised in
the forms.
Procedure in forms
The procedures in form modules of a form are private procedures of this form; you can use them
only inside the form module. Because the procedures are private inside a form module, you can use
the equally named procedures in many forms. But the names of procedures in global modules must
be equal. It is possible to create a procedure in a form module that has the same name as a
procedure in a global module. In this case, KBasic uses two rules to recognize the correct procedure
to execute:
79 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
All calls inside a module in which the procedure is declared reaches this procedure. Calls outside
the module run the public procedure. So all calls inside a module, in which the procedure is
declared, reaches this procedure. Calls outside the module run the public procedure.
80 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
generated by the KBasic-compiler and interpreted by the KBasic-interpereter. When the compiler
compiles a KBasic program it produces a set of p-codes and saves them. The KBasic-interpreter
executes these pseudo-codes. It is important to know that the name ‘KBasic’ means much more than
a programming language. It means also a complete computer environment. KBasic contains two
components: KBasic design (the programming language) and KBasic runtime (the virtual machine).
What are the main functions of the virtual machine?
The virtual machine (VM) does the following tasks:
• Assign allocated memory to created objects
• De-allocate memory automatically
• Handle the stack and registry of variables
• Access the host system, like using devices
Appendix
Argument
A value that is passed to a procedure or function. Also see Parameter.
Arithmetic Operations
Mathematical operations such as addition, multiplication, subtraction, and division that produce
numerical results.
Array
A variable that stores a series of values accessed using a subscript.
BASIC
Beginner’s All-Purpose Symbolic Instruction Code, the computer language upon which KBasic is
based.
Bit
The smallest piece of information a computer can hold. A bit can be only one of two values, 0 or 1.
Boolean
A data type representing a value of true or false.
Boolean Expression
A combination of terms that evaluates to a value of true or false. For example, (x = 5) and (y = 6).
Branching
When program execution jumps from one point in a program to another, rather than continuing to
execute instructions in strict order. Also see Conditional Branch and Unconditional Branch.
81 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Breakpoint
A point in a program at which program execution should be suspended to enable the programmer to
examine the results up to that point. By setting breakpoints in a program, you can more easily find
errors in your programs. Also see Debugging.
Byte
A piece of data made up of eight bits. Also see Bit.
Compiler
A programming tool that converts a program’s source code into an executable file. KBasic
automatically employs a compiler when you run a program or select the File menu’s Make
command to convert the program to an executable file (only Professional Version). Also see
Interpreter.
Concatenate
To join end to end two text strings into one text string. For example, the string “OneTwo” is a
concatenation of the two strings “One” and “Two.” Conditional Branch When program execution
branches to another location in the program based on some sort of condition. An example of a
conditional branch is an If/Then statement that causes the program to branch to a program line
based on a condition such as If (x=5).
Constant
A predefined value that never changes.
Data Type
The various types of values that a program can store. These values include Integer, Long, String,
Single, Double, and Boolean.
Debugging
The act of finding and eliminating errors in a program.
Decrement
Decreasing the value of a variable, usually by 1. Also see Increment.
Double
The data type that represents the most accurate floating-point value, also known as a double-
precision floating-point value. Also see Floating Point and Single.
Empty String
A string that has a length of 0, denoted in a program by two double quotes. For example, the
following example sets a variable called str1 to an empty string: str1 = “”.
82 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Event
A message that is sent to a program as a result of some interaction between the user and the
program.
Executable File
A file, usually an application, that the computer can load and run. Most executable files end with the
file extension .EXE on Windows.
File
A named set of data on a disk.
Floating Point
A numerical value that has a decimal portion. For example, 12.75 and 235.7584 are floating-point
values. Also see Double and Single.
Form
The KBasic object that represents an application’s window. The form is the container on which you
place the controls making up your program’s user interface.
Function
A subprogram that processes data in some way and returns a single value representing the result of
the processing.
Global Variable
A named value accessed from anywhere within a program module.
Increment
Increasing the value of a variable, usually by 1. Also see Decrement.
Infinite Loop
A loop that can’t end because its conditional expression can never evaluate to true. An infinite loop
ends only when the user terminates the program. Also see Loop and Loop Control Variable.
Initialize
Setting the initial value of a variable.
Integer
A data type representing whole numbers between –2,147,483,648 to 2,147,483,647. The values 240,
–128, and 2 are examples of integers. Also see Long.
83 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Interpreter
A programming tool that executes source code one line at a time unlike a compiler that converts an
entire program to an executable file before executing any of the program’s commands. Also see
Compiler.
Literal
A value in a program that is stated literally. That is, the value is not stored in a variable.
Local Variable
A variable accessed only from within the subprogram in which it is declared. Also see Global
Variable and Variable Scope.
Logic Error
A programming error that results when a program performs a different task than the programmer
thought he programmed it to perform. For example, the program line If X = 5 Then Y = 6 is a
logical error if the variable X can never equal 5. Also see Runtime Error.
Logical Operator
A symbol comparing two expressions and resulting in a Boolean value (a value of true or false). For
example, in the line if X = 5 and Y = 10 then Z = 1, and is the logical operator. Also see Relational
Operator.
Long
A data type that represents integer values from –2³² - 1 to +2³². Also see Integer.
Loop
A block of source code that executes repeatedly until a certain condition is met.
Machine Language
The only language a computer truly understands. All program source code must be converted to
machine language before the computer can run the program.
Mathematical Expressions
A set of terms using arithmetic operators to produce a numerical value. For example, the terms (X +
17) / (Y + 22) make up a mathematical expression. Also see Arithmetic Operations.
Method
A procedure associated with an object or control that represents an ability of the object or control.
84 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
For example, a Command Button’s Move method repositions the button on the form.
Numerical Literal
A literal value that represents a number, such as 125 or 34.87. Also see Literal and String Literal.
Numerical Value
A value that represents a number. This value can be a literal, a variable, or the result of an arithmetic
operation.
Object
Generally, any piece of data in a program. Specifically in KBasic, a set of properties and methods
that represent some sort of real-world object or abstract idea.
Order of Operations
The order in which KBasic resolves arithmetic operations. For example, in the mathematical
expression (X + 5) / (Y + 2), KBasic performs the two additions before the division. If the
parentheses had been left off, such as in the expression X + 5 / Y + 2, KBasic would first divide 5
by Y, then perform the remaining addition operations.
Parameter
Often meaning the same as “argument,” although some people differentiate argument and parameter
where an argument is the value sent to a procedure or function and a parameter is the variable in the
function or procedure that receives the argument. Also see Argument.
Procedure
A subprogram performing a task in a program but does not return a value. Also see Function.
Program
A list of instructions for a computer.
Programming Language
A set of English-like keywords and symbols that enable a programmer to write a program without
using machine language.
Program Flow
The order in which a computer executes program statements.
Property
A value representing an attribute of an object or control.
85 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
Read-Only Property
A property whose value cannot be changed from within a program. However, a program can
retrieve (read) a property’s value.
Relational Operator
A symbol that determines the relationship between two expressions. For example, in the expression
X > 10, the relational operator is >, which means “greater than.” Also see Logical Operator.
Return Value
The value a function sends back to the statement that called the function. Also see Function.
Runtime Error
An system error that occurs while a program is running. An example is a divide-by-zero error or a
type-mismatch error. Without error handling such as that provided by the Try/Catch statement,
runtime errors often result in a program crash.
Scope
See Variable Scope.
Single
The data type that represents the least accurate floating-point value, also known as a single-
precision floating-point value. Also see Double and Floating Point.
Source Code
The lines of commands making up a program.
String
A data type that represents one or more text characters. For example, in the assignment statement
str1 = “I’m a string,” the variable str1 must be of the String (or Variant) data type.
String Literal
One or more text characters enclosed in double quotes.
Subprogram
A block of source code that performs a specific part of a larger task. In KBasic, a subprogram can
be either a procedure or a function. Also see Function and Procedure.
Unconditional Branch
When program execution branches to another location regardless of any conditions. An example of
an unconditional branch is the GoTo statement.
86 / 87
KBasic Manual: „The KBasic Book“ - (C)opyright Bernd Noetscher’s KBasic Software 2000-2007. All rights reserved.
User Interface
The visible representation of an application, usually made up of various types of controls, that
enables the user to interact with the application.
Variable
A named value in a program. This value can be assigned and reassigned a value of the appropriate
data type.
Variable Scope
The area of a program in which a variable can be accessed. For example, the scope of a global
variable is anywhere within the program, whereas the scope of a local variable is limited to the
procedure or function that declares the variable. Also see Global Variable and Local Variable.
Variant
A special data type that can represent any type of data. More accurately, KBasic manages the data
type of a Variant value for you. This data type is very inefficient and should be avoided when
possible. KBasic manages the data type of a Variant value for you. This data type is very inefficient
and should be avoided when possible.
87 / 87