*General Keywords*

Back to the start


AppClose
ArrayCopy
ArrayLen
B4PObject
Dim
DoEvents
Do Until
Do While
Exit
ErrorLabel
For
Goto
Labels:
If
IsNull
Msgbox
Not
Return
RGB
Rnd
Select
SetTransparentColor
Shell
SIP
Sound
WaitCursor



AppClose Top

Closes all forms and ends the application.
Same as closing the main form (the first form that was shown).
Syntax: AppClose

ArrayCopy Top

Copies part of the source array to the target array.
Syntax: ArrayCopy (Source Array, Source Start, Count, Target Array, Target Start)
Source Array - The items will be copied from this array. .
Source Start - The first item that will be copied.
Count - Number of items to copy.
Target Start - The position in the target of the first copied item.

Example:
ArrayCopy (buffer(), 0, ArrayLen (buffer()), target(), 0)

ArrayLen Top

Returns the length (size) of an array.
Syntax: ArrayLen (Array [,Dimension])
Dimension - ArrayLen will return the length of the specified dimension. The default is 1.

Example:
i = ArrayLen (items())


B4PObject Top

B4PObject exposes an interface of Basic4ppc to external libraries.
Syntax: B4PObject (Number)

Example:

drawer.New2 (ImageList1.Item(0), B4PObject(5))

Dim Top


Declares regular and array variables.
Syntax: Dim Variable Name (Array length) [As Data Type]
Array dimension can be up to 3.
You can declare many variables on one row.

Example: Dim Counter(20), I, a, x(10,10,10), Matrix(10,10) as double

When declaring arrays, remember that the array's index starts from 0 and its last index is array length - 1.
In the last example, Counter starts from Counter(0) and ends with Counter (19).
Declare global variables in Sub Globals.
Array variables are always global and can be declared anywhere in the program.
Array (and only array) variables can declared to hold data of a specific data type.
The same array can be declared many times and its size can be changed.
Some methods (from external libraries) return arrays.
In this case you can declare the array as an empty array:

Example: Dim buffer(0) As Byte

Now use the declared array to receive the returned array.

Example: buffer() = Serial.InputArray

You can use ArrayLen to find the length (size) of an array.
Basic4ppc is not "Option Explicit" which means you can use variables without declaring them (except arrays).

Example:

To use a global variable named flags you can write:

Sub Globals
  flags = 10
End Sub

DoEvents Top

Allows a program to take care of waiting events.
Useful in cases that the processor is busy and you don't want the program to stop responding to the user.
Another case where you can use DoEvents is when you want the program to draw all waiting drawings.

Syntax: DoEvents

Do Until Top

Loops until a condition is true.
Syntax:
Do Until condition
 ...
 ...
Loop

Example:
Do Until Msgbox ("Add another?",,cMsgboxYesNo) = cNo
 i=i+1
Loop
Msgbox (i)

Result:
The loop will continue until the user chooses No.


Do While Top

Loops while a condition is true.
Syntax:
Do While condition
 ...
 ...
Loop

Example:
Do While Msgbox ("Add another?",,cMsgboxYesNo) = cYes
 i=i+1
Loop
Msgbox (i)

Result:
The loop will continue until the user chooses No.

Exit Top

Exits For, While, Until loops.
In case of nested loops, Exit will exit only the last level.
Syntax: Exit
Example:

For n = 1 to 100
  If n = TextBox1.Text Then Exit
Next

ErrorLabel Top

Sets a label that the program will jump to in case an error will occur in the current sub,
Syntax: ErrorLabel (Label)
Example:
Sub OpenFile
  ErrorLabel (errHandler)
  FileOpen (c,"data.dat",cRead)
  Return
  ErrHandler:
  Msgbox("Can't open file.")
End Sub

For Top

Loop statement that changes a variable value.
Syntax: For variable = Value To Value [Step Value]
Step default is 1.
Example:
For i = 10 To 0 Step -1
  Msgbox (i)
Next
Result: It will display a countdown from 10 to 0

Goto Top


Changes the program position.
Goto causes the program to move to a predefined label.

Labels: Top

Label syntax is a word starting with a letter and ending with a colon.

Example:
Sub Button1_Click
  ...
StartingPlace:
 ...
 Goto StartingPlace
End Sub

Result: When the program reaches the Goto keyword it will move to the first line after StartingPlace.

Although you can use Goto to jump between different subs it may cause unpredictable errors because the local variables will still be the variables of the previous sub. Goto is best used to jump inside a sub.

If Top

If can be used in two ways.

One line: If Condition Then DoSomething [Else DoSomething]
Example: If TextBox1 > TextBox2 Then Msgbox ("Bigger") Else Msgbox ("Smaller")
Note: You can't use the line separator ':' between Then and Else.

Multi line:
If Condition Then
 ...
Else If Condition Then
 ...
Else
  ...
End If


Example:
If TextBox1>TextBox2 Then
 Msgbox ("Bigger")
Else If TextBox1  Msgbox ("Smaller")
Else
 Msgbox ("Equal")
End If

IsNull Top

Checks whether the object returned from an external library is null (nothing).
Syntax: IsNull


Example:
If IsNull (Node.Parent) = true Then ...

Msgbox Top
Msgbox shows a message to the user and to receive the button the user pressed.
Using Msgbox Constants you can change the Msgbox buttons and icon.
Syntax: Msgbox (Message String[, Title String[, Buttons[, Icon]]])

Buttons can be:
 cMsgBoxAbortRetryIgnore
 cMsgBoxOK
 cMsgBoxRetryCancel
 cMsgBoxYesNo
 cMsgBoxYesNoCancel

Icon can be:
 cMsgBoxAsterisk
 cMsgBoxExclamation
 cMsgBoxHand
 cMsgBoxNone
 cMsgBoxQuestion

Msgbox returns one of the following:
 cAbort
 cCancel
 cIgnore
 cOK
 cNo
 cRetry
 cYes

Example:
 r = Msgbox ("Do you want to continue?", "Basic4ppc", cMsgboxYesNo, cMsgboxYesNo)

Not Top


Returns the opposite of the given value.
Syntax: Not (True | False)
Example: Menu1.Checked = Not (Menu1.Checked)

Return Top


Ends the current sub and returns to the calling sub.
If Return is followed by a value, then the value will be passed to the calling sub.
Syntax: Return [Value]

Example:
Sub Button1_Click
 If IsInteger (a) = true Then b=a
End Sub

Sub IsInteger (x)
 If x = Int(x) Then Return true Else Return false
End Sub

RGB

Returns the number that represents a certain color.
Syntax: RGB (R, G, B)

Example:
pen1.Color = RGB (255,255,255)

Rnd Top

Generates a random integer larger or equal to the minimum value and smaller than the maximum value.
Syntax: Rnd (Minimum Value, Maximum Value)
Example:
i = Rnd (30, 60)

Select Top

Select is used to test one value with several values.
Only the first case that matches will execute.
Syntax:
Select value
 Case Value1
   ...
 Case Value2,Value3,Value4 (True if one of the values matches)
   ...
 Case Else
   ...
End Select


Example:
Select StrToLower(TextBox1.Text)
 Case ""
   Return
 Case "red"
   Form1.Color = cRed
Case "blue"
   Form1.Color = cBlue
 Case Else
   Form1.Color = cWhite
End Select

SetTransparentColor Top

Sets the color that will be used as the transparent color in the Form's ForeLayer.

Syntax: SetTransparentColor (R,G,B | Color Constant)

Each form can include two graphical layers.
The ForeLayer supports transparency.
SetTransparentColor set the transparent color.
This keyword must be used before Form.ForeLayer = True.

Example:
Sub App_Start
 SetTransparentColor (cWhite)
 Form1.ForeLayer = True
 Form1.Show
End Sub

Shell Top

Runs an external program.
Syntax: Shell (Program File, Arguments)
Example:
Shell ("Calc.exe", "")

SIP Top

Shows / hides the soft input panel.
Syntax: SIP (True | False)
Example:
Sub TextBox1_GotFocus
 SIP(True)
End Sub


Sub TextBox1_LostFocus
 SIP(False)
End Sub

Sound Top

Plays a wave file.
Syntax: Sound (Wave File)
Example:
Sound ("\Sounds\Beep.wav")

See External Files for more information about using external files.

WaitCursor Top

Shows and hides the busy icon (in the middle of the screen).
Syntax: WaitCursor (true | false)
Example:
WaitCursor (True)
HeavySub
WaitCursor (False)