|
Basic4Android Keywords
Contents:
Abs (Number As Double) As Double
ACos (Value As Double) As Double
ACosD (Value As Double) As Double
Array
Asc (Char As Char) As Int
ASin (Value As Double) As Double
ASinD (Value As Double) As Double
ATan (Value As Double) As Double
ATanD (Value As Double) As Double
BytesToString (...) As String
CallSub (...) As String
CallSub2 (...) As String
CallSub3 (...) As String
CancelScheduledService (Service As Object)
Catch
cE As Double
Ceil (Number As Double) As Double
CharsToString (...) As String
Chr (UnicodeValue As Int) As Char
Continue
Cos (Radians As Double) As Double
CosD (Degrees As Double) As Double
cPI As Double
CRLF As String
Density As Float
Dim
DipToCurrent (Length As Int) As Int
DoEvents
Exit
ExitApplication
False As Boolean
File As File
Floor (Number As Double) As Double
For
GetDeviceLayoutValues As LayoutValues
GetType (object As Object) As String
If
InputList (...) As Int
InputMap (Items As Map, Title As String)
InputMultiList (Items As List, Title As String) As List
Is
IsBackgroundTaskRunning (...) As Boolean
IsNumber (Text As String) As Boolean
IsPaused (Component As Object) As Boolean
LastException As Exception
LoadBitmap (Dir As String, FileName As String) As Bitmap
LoadBitmapSample (...) As Bitmap
Log (Message As String)
Logarithm (Number As Double, Base As Double) As Double
Max (Number1 As Double, Number2 As Double) As Double
Min (Number1 As Double, Number2 As Double) As Double
Msgbox (Message As String, Title As String)
Msgbox2 (...) As Int
Not (Value As Boolean) As Boolean
Null As Object
NumberFormat (...) As String
NumberFormat2 (...) As String
PerXToCurrent (Percentage As Float) As Int
PerYToCurrent (Percentage As Float) As Int
Power (Base As Double, Exponent As Double) As Double
ProgressDialogHide
ProgressDialogShow (Text As String)
ProgressDialogShow2 (Text As String, Cancelable As Boolean)
QUOTE As String
Regex As Regex
Return
Rnd (Min As Int, Max As Int) As Int
Round (Number As Double) As Long
Round2 (Number As Double, DecimalPlaces As Int) As Double
Select
Sender As Object
Sin (Radians As Double) As Double
SinD (Degrees As Double) As Double
Sqrt (Value As Double) As Double
StartActivity (Activity As Object)
StartService (Service As Object)
StartServiceAt (...)
StopService (Service As Object)
Sub
TAB As String
Tan (Radians As Double) As Double
TanD (Degrees As Double) As Double
ToastMessageShow (Message As String, LongDuration As Boolean)
True As Boolean
Try
Type
Until
While
Abs (Number As Double) As Double
Returns the absolute value.
ACos (Value As Double) As Double
Returns the angle measured with radians.
ACosD (Value As Double) As Double
Returns the angle measured with degrees.
Array
Creates a single dimension array of the specified type.
The syntax is: Array As type (list of values).
Example:
Dim Days() As String
Days = Array As String("Sunday", "Monday", ...)
Asc (Char As Char) As Int
Returns the unicode code point of the given character or first character in string.
ASin (Value As Double) As Double
Returns the angle measured with radians.
ASinD (Value As Double) As Double
Returns the angle measured with degrees.
ATan (Value As Double) As Double
Returns the angle measured with radians.
ATanD (Value As Double) As Double
Returns the angle measured with degrees.
BytesToString (...) As String
Decodes the given bytes arrays as a string.
BytesToString (Data() As Byte, StartOffset As Int, Length As Int, CharSet As String) As String
- Data - The bytes array.
- StartOffset - The first byte to read.
- Length - Number of bytes to read.
- CharSet - The name of the character set.
Example:
Dim s As String
s = BytesToString(Buffer, 0, Buffer.Length, "UTF-8")
CallSub (...) As String
CallSub (Component As Object, Sub As String) As String
Calls the given sub. CallSub can be used to call a sub which belongs to a different module. However the sub will only be called if the other module is not paused. In that case an empty string will be returned.
You can use IsPaused to test whether a module is paused. This means that one activity cannot call a sub of a different activity. As the other activity will be paused for sure.
CallSub allows an activity to call a service sub or a service to call an activity sub.
Note that it is not possible to call subs of code modules.
CallSub can also be used to call subs in the current module. Pass an empty string as the component in that case. Example:
CallSub(Main, "RefreshData")
CallSub2 (...) As String
CallSub2 (Component As Object, Sub As String, Argument As Object) As String
Similar to CallSub. Calls a sub with a single argument.
CallSub3 (...) As String
CallSub3 (Component As Object, Sub As String, Argument1 As Object, Argument2 As Object) As String
Similar to CallSub. Calls a sub with two arguments.
CancelScheduledService (Service As Object)
Cancels previously scheduled tasks for this service.
Catch
Any exception thrown inside a try block will be caught in the catch block.
Call LastException to get the caught exception.
Syntax:
Sub SomeSub
Try
...some code...
Catch [only executes if error above]
Log(LastException) [optional]
...optional code for error correction...
End Try
...optional additional code...
End Sub
cE As Double
e (natural logarithm base) constant.
Ceil (Number As Double) As Double
Returns the smallest double that is greater or equal to the specified number and is equal to an integer.
CharsToString (...) As String
CharsToString (Chars() As Char, StartOffset As Int, Length As Int) As String
Creates a new String by copying the characters from the array.
Copying starts from StartOffset and the number of characters copied equals to Length.
Chr (UnicodeValue As Int) As Char
Returns the character that is represented by the given unicode value.
Continue
Stops executing the current iteration and continues with the next one.
Cos (Radians As Double) As Double
Calculated the trigonometric cosine function. Angle measured in radians.
CosD (Degrees As Double) As Double
Calculated the trigonometric cosine function. Angle measured in degrees.
cPI As Double
PI constant.
CRLF As String
New line character. The value of Chr(10).
Example: Log("Line 1" & CRLF & "Line 2")
Density As Float
Returns the device scale, which is DPI / 160.
(DPI stands for dots per inch).
This can be used to determine which layout to load.
Example:
Dim dens As Float
dens = Density
Dim lv As LayoutValues
lv = GetDeviceLayoutValues
If lv.Width > 599 Then
LayoutWidth = 800
If dens = 1.5 Then
Activity.LoadLayout("800x480x240")
Else
Activity.LoadLayout("800x480x160")
End If
Else
LayoutWidth = 480
Activity.LoadLayout("480x320x160")
End If
Dim
Declares a variable.
The default type is String.
Syntax:
Declare a single variable:
Dim variable name [As type]
Declare multiple variables.
All variables will be of the specified type.
Dim variable1, variable2, ..., [As type]
Note that this shorthand syntax only applies to Dim keyword, not for other uses such as Sub names:
Sub SomeSub(X as Int, Y as Int, Z as Int) and NOT
Sub SomeSub(X, Y, Z as Int) where X and Y will be strings by default and only Z will be an integer.
Declare an array:
Dim variable(Rank1, Rank2, ...) [As type]
Example:Dim Days(7) As String
The actual rank can be omitted for zero length arrays.
DipToCurrent (Length As Int) As Int
Scales the value, which represents a specific length on a default density device (Density = 1.0),
to the current device.
"dip" stands for "density independent pixel".
For example, the following code will set the width value of this button to be the same physical size
on all devices.
Button1.Width = DipToCurrent(100)
A shorthand syntax for this method consists of any number followed by the string 'dip', which will be converted in the same manner (no spaces are allowed between the number and 'dip').
So the previous code is equivalent to:
DoEvents
Processes waiting messages in the messages queue.
DoEvents can be called inside lengthy loops to allow the program to process waiting events.
Exit
Exits the most inner loop.
ExitApplication
Immediately ends the application and stops the process.
Most applications should not use this method and prefer Activity.Finish which lets the OS decide when the process is killed.
False As Boolean
File As File
Files related methods.
Floor (Number As Double) As Double
Returns the largest double that is smaller or equal to the specified number and is equal to an integer.
For
Syntax:
For variable = value1 To value2 [Step interval]
...
Next
Example:
For i = 1 To 10
Log(i) 'Will print 1 to 10 (inclusive).
Next
If the iterator variable was not declared before it will be of type Int.
GetDeviceLayoutValues As LayoutValues
Returns the device LayoutValues.
Example:
Log(GetDeviceLayoutValues)
GetType (object As Object) As String
Returns a string representing the object's java type.
If
Single line:
If condition Then true-statement [Else false-statement]
Multiline:
If condition Then
statement
Else If condition Then
statement
...
Else
statement
End If
InputList (...) As Int
Shows a modal dialog with a list of items and radio buttons. Pressing on an item will close the dialog.
Returns the index of the selected item or DialogResponse.Cancel if the user pressed on the back key.
InputList (Items As List, Title As String, CheckedItem As Int) As Int
List - Items to display.
Title - Dialog title.
CheckedItem - The index of the item that will first be selected.
Pass -1 if no item should be preselected.
InputMap (Items As Map, Title As String)
Shows a modal dialog with a list of items and checkboxes. The user can select multiple items.
The dialog is closed by pressing on the "Ok" button.
The items displayed are the map keys. Items with a value of True will be checked.
When the user checks or unchecks an item, the related item value gets updated.
Items - A map object with the items as keys and their checked state as values.
Example:
Dim m As Map
m.Initialize
m.Put("Item #1", True)
m.Put("Item #2", False)
m.Put("Item #3", False)
m.Put("Item #4", True)
InputMap(m, "Check items")
InputMultiList (Items As List, Title As String) As List
Shows a modal dialog with a list of items and checkboxes. The user can select multiple items.
The dialog is closed by pressing on the "Ok" button.
Returns a list with the indices of the selected items. The list is sorted.
Returns an empty list if the user has pressed on the back key.
Is
Tests whether the object is of the given type.
Example:
For i = 0 To Activity.NumberOfViews - 1
If Activity.GetView(i) Is Button Then
Dim b As Button
b = Activity.GetView(i)
b.Color = Colors.Blue
End If
Next
IsBackgroundTaskRunning (...) As Boolean
IsBackgroundTaskRunning (ContainerObject As Object, TaskId As Int) As Boolean
Tests whether a background task, submitted by the container object and with the specified id, is running.
IsNumber (Text As String) As Boolean
Tests whether the specified string can be safely parsed as a number.
IsPaused (Component As Object) As Boolean
Tests whether the given component is paused.
Will also return true for components that were not started yet.
Example:
If IsPaused(Main) = False Then CallSub(Main, "RefreshData")
LastException As Exception
Returns the last exception that was caught (if such exists).
LoadBitmap (Dir As String, FileName As String) As Bitmap
LoadBitmap (Dir As String, FileName As String) As Bitmap
Loads the bitmap.
Note that the Android file system is case sensitive.
You should consider using LoadBitmapSample if the image size is large.
The actual file size is not relevant as images are usually stored compressed.
Example:
Activity.SetBackgroundImage(LoadBitmap(File.DirAssets, "SomeFile.jpg"))
LoadBitmapSample (...) As Bitmap
LoadBitmapSample (Dir As String, FileName As String, MaxWidth As Int, MaxHeight As Int) As Bitmap
Loads the bitmap.
The decoder will subsample the bitmap if MaxWidth or MaxHeight are smaller than the bitmap dimensions.
This can save a lot of memory when loading large images.
Example:
Activity.SetBackgroundImage(LoadBitmapSample(File.DirAssets, "SomeFile.jpg", Activity.Width, Activity.Height))
Log (Message As String)
Logs a message. The log can be viewed in the LogCat tab.
Logarithm (Number As Double, Base As Double) As Double
Max (Number1 As Double, Number2 As Double) As Double
Returns the larger number between the two numbers.
Min (Number1 As Double, Number2 As Double) As Double
Returns the smaller number between the two numbers.
Msgbox (Message As String, Title As String)
Shows a modal message box with the specified message and title.
The dialog will show one OK button.
Example:
Msgbox("Hello world", "This is the title")
Msgbox2 (...) As Int
Msgbox2 (Message As String, Title As String, Positive As String, Cancel As String, Negative As String, Icon As android.graphics.Bitmap) As Int
Shows a modal message box with the specified message and title.
- Message - The dialog message.
- Title - The dialog title.
Positive - The text to show for the "positive" button. Pass "" if you don't want to show the button.
- Cancel - The text to show for the "cancel" button. Pass "" if you don't want to show the button.
- Negative - The text to show for the "negative" button. Pass "" if you don't want to show the button.
- Icon - A bitmap that will be drawn near the title. Pass Null if you don't want to show an icon.
Returns one of the DialogResponse values.
Example:
Dim result As Int
result = Msgbox2("This is the message", "This is the title", "Good", "", "Bad", LoadBitmap(File.DirAssets, "smiley.gif"))
If result = DialogResponse.Positive Then ...
Not (Value As Boolean) As Boolean
Inverts the value of the given boolean.
Null As Object
NumberFormat (...) As String
NumberFormat (Number As Double, MinimumIntegers As Int, MaximumFractions As Int) As String
Converts the specified number to a string.
The string will include at least Minimum Integers and at most Maximum Fractions digits.
Example:
Log(NumberFormat(12345.6789, 0, 2)) '"12,345.68"
Log(NumberFormat(1, 3 ,0)) '"001"
NumberFormat2 (...) As String
NumberFormat2 (Number As Double, MinimumIntegers As Int, MaximumFractions As Int, MinimumFractions As Int, GroupingUsed As Boolean) As String
Converts the specified number to a string.
The string will include -
at least Minimum Integers,
at most Maximum Fractions digits and
at least Minimum Fractions digits.
GroupingUsed - Determines whether to group every three integers.
Example:
Log(NumberFormat2(12345.67, 0, 3, 3, false)) '"12345.670"
PerXToCurrent (Percentage As Float) As Int
Returns the actual size of the given percentage of the activity width.
Example:
Button1.Width = PerXToCurrent(50) 'Button1.Width = 50% * Activity.Width
A shorthand syntax for this method is available.
Any number followed by the string '%x' will be converted in the same manner (no spaces are allowed between the number and '%x').
So the previous code is equivalent to:
PerYToCurrent (Percentage As Float) As Int
Returns the actual size of the given percentage of the activity height.
Example:
Button1.Height = PerYToCurrent(50) 'Button1.Height = 50% * Activity.Height
A shorthand syntax for this method is available.
Any number followed by the string '%y' will be converted in the same manner (no spaces are allowed between the number and '%y').
So the previous code is equivalent to:
Power (Base As Double, Exponent As Double) As Double
Returns the Base value raised to the Exponent power.
ProgressDialogHide
Hides a visible progress dialog. Does not do anything if no progress dialog is visible.
ProgressDialogShow (Text As String)
Shows a dialog with a circular spinning bar and the specified text.
Unlike Msgbox and InputList methods, the code will not pause.
To remove the dialog, you must call ProgressDialogHide.
The dialog will also be removed if the user presses on the Back key.
ProgressDialogShow2 (Text As String, Cancelable As Boolean)
Shows a dialog with a circular spinning bar and the specified text.
Unlike Msgbox and InputList methods, the code will not pause.
To remove the dialog, you must call ProgressDialogHide.
Cancelable - Whether the user can dismiss the dialog by pressing on the Back key.
QUOTE As String
Quote character. The value of Chr(34).
Regex As Regex
Regular expressions related methods.
Return
Returns from the current sub and optionally returns the given value.
Syntax: Return [value]
Rnd (Min As Int, Max As Int) As Int
Returns a random integer between Min (inclusive) and Max (exclusive).
Round (Number As Double) As Long
Returns the closest long number to the given number.
Round2 (Number As Double, DecimalPlaces As Int) As Double
Rounds the given number and leaves up to the specified number of fractional digits.
Select
Compares a single value to multiple values.
Example:
Dim value As Int
value = 7
Select value
Case 1
Log("One")
Case 2, 4, 6, 8
Log("Even")
Case 3, 5, 7, 9
Log("Odd larger than one")
Case Else
Log("Larger than 9")
End Select
Sender As Object
Returns the object that raised the event.
It is only valid while inside the event sub.
Example:
Sub Button_Click
Dim b As Button
b = Sender
b.Text = "I've been clicked"
End Sub
Sin (Radians As Double) As Double
Calculated the trigonometric sine function. Angle measured in radians.
SinD (Degrees As Double) As Double
Calculated the trigonometric sine function. Angle measured in degrees.
Sqrt (Value As Double) As Double
Returns the positive square root.
StartActivity (Activity As Object)
Starts an activity or brings it to front if it already exists.
The target activity will be started once the program is free to process its message queue.
Activity can be a string with the target activity name or it can be the actual activity.
After this call the current activity will be paused and the target activity will be resumed.
This method can also be used to send Intents objects to the system.
Note that you should usually not call StartActivity from a Service.
Example: StartActivity (Activity2)
StartService (Service As Object)
Starts the given service.
The service will be first created if it was not started before.
The target service will be started once the program is free to process its message queue.
Note that you cannot show a Msgbox after this call and before the service starts.
Service - The service module or the service name.
Example: StartService(SQLService)
StartServiceAt (...)
StartServiceAt (Service As Object, Time As Long, DuringSleep As Boolean)
Schedules the given service to start at the given time.
Service - The service module or service name. Pass an empty string when calling from a service module that schedules itself.
Time - The time to start the service. If this time has already past the service will be started now.
DuringSleep - Whether to start the service when the device is sleeping. If set to false and the device is sleeping at the specified time, the service will be started when the device wakes up.
StartServiceAt can be used to schedule a repeating task. You should call it under Service_Start to schedule the next task. This call cancels previous scheduled tasks (for the same service).
Example:
StartServiceAt(SQLService, DateTime.Now + 30 * 1000, false)
'will start after 30 seconds.
StopService (Service As Object)
Stops the given service.
Service_Destroy will be called.
Call StartService afterwards will first create the service.
Service - The service module or service name. Pass empty string to stop the current service (from the service module).
Example: StopService(SQLService)
Sub
Declares a sub with the parameters and return type.
Syntax: Sub name [(list of parameters)] [As return-type]
Parameters include name and type.
The lengths of arrays dimensions should not be included.
Example:
Sub MySub (FirstName As String, LastName As String, Age As Int, OtherValues() As Double) As Boolean
...
End Sub
In this example OtherValues is a single dimension array. The return type declaration is different than other declarations as the array parenthesis follow the type and not the name (which does not exist in this case).
TAB As String
Tab character.
Tan (Radians As Double) As Double
Calculated the trigonometric tangent function. Angle measured in radians.
TanD (Degrees As Double) As Double
Calculated the trigonometric tangent function. Angle measured in degrees.
ToastMessageShow (Message As String, LongDuration As Boolean)
Shows a quick little message that goes out automatically.
Message - The text message to show.
LongDuration - If true then shows the message for a long period, otherwise shows the message for a short period.
True As Boolean
Try
Any exception thrown inside a try block will be caught in the catch block.
Call LastException to get the caught exception.
Syntax:
Try
...
Catch
...
End Try
Type
Declares a structure.
Can only be used inside sub Globals or sub Process_Globals.
Syntax:
Type type-name (field1, field2, ...)
Fields include name and type.
Example:
Type MyType (Name As String, Items(10) As Int)
Dim a, b As MyType
a.Initialize
a.Items(2) = 123
Until
Loops until the condition is true.
Syntax:
Do Until condition
...
Loop
While
Loops while the condition is true.
Syntax:
Do While condition
...
Loop
|