B4J Programming Press on the image to return to the main documentation page.

Core

List of types:

Bit
DateTime
Exception
Keywords
String
StringBuilder
Timer

Bit

Bit is a predefined object containing bitwise related methods.
Example:
Dim flags As Int
flags = Bit.Or(100, 200)

Events:

None

Members:


  And (N1 As Int, N2 As Int) As Int

  ArrayCopy (SrcArray As Object, SrcOffset As Int, DestArray As Object, DestOffset As Int, Count As Int)

  InputStreamToBytes (In As java.io.InputStream) As Byte()

  Not (N As Int) As Int

  Or (N1 As Int, N2 As Int) As Int

  ParseInt (Value As String, Radix As Int) As Int

  ShiftLeft (N As Int, Shift As Int) As Int

  ShiftRight (N As Int, Shift As Int) As Int

  ToBinaryString (N As Int) As String

  ToHexString (N As Int) As String

  ToOctalString (N As Int) As String

  UnsignedShiftRight (N As Int, Shift As Int) As Int

  Xor (N1 As Int, N2 As Int) As Int

Members description:

And (N1 As Int, N2 As Int) As Int
Returns the bitwise AND of the two values.
ArrayCopy (SrcArray As Object, SrcOffset As Int, DestArray As Object, DestOffset As Int, Count As Int)
Copies elements from SrcArray to DestArray.
SrcArray - Source array.
SrcOffset - Index of first element in the source array.
DestArray - Destination array.
DestOffset - Index of the first element in the destination array.
Count - Number of elements to copy.
InputStreamToBytes (In As java.io.InputStream) As Byte()
Reads the data from the input stream and writes it into an array of bytes.
The input stream is automatically closed at the end.
Not (N As Int) As Int
Returns the bitwise complement of the given value.
Or (N1 As Int, N2 As Int) As Int
Returns the bitwise OR of the two values.
ParseInt (Value As String, Radix As Int) As Int
Parses Value as an integer using the specified radix.
Radix - Should be between 2 to 36.
ShiftLeft (N As Int, Shift As Int) As Int
Shifts N left.
Shift - Number of positions to shift.
ShiftRight (N As Int, Shift As Int) As Int
Shifts N right.
Keeps the original value sign
Shift - Number of positions to shift.
ToBinaryString (N As Int) As String
Returns a string representation of N in base 2.
ToHexString (N As Int) As String
Returns a string representation of N in base 16.
ToOctalString (N As Int) As String
Returns a string representation of N in base 8.
UnsignedShiftRight (N As Int, Shift As Int) As Int
Shifts N right.
Shifts zeroes in the leftmost positions.
Shift - Number of positions to shift.
Xor (N1 As Int, N2 As Int) As Int
Returns the bitwise XOR of the two values.

DateTime

Date and time related methods.
DateTime is a predefined object. You should not declare it yourself.
Date and time values are stored as ticks. Ticks are the number of milliseconds since January 1, 1970 00:00:00 UTC.
This value is too large to be stored in an Int variable. It should only be stored in a Long variable.
The methods DateTime.Date and DateTime.Time convert the ticks value to a string.
You can get the current time with DateTime.Now.
Example:
Dim now As Long
now = DateTime.Now
Msgbox("The date is: " & DateTime.Date(now) & CRLF & _
  "The time is: " & DateTime.Time(now), "")

Events:

None

Members:


  Add (Ticks As Long, Years As Int, Months As Int, Days As Int) As Long

  Date (Ticks As Long) As String

  DateFormat As String

  DateParse (Date As String) As Long

  DateTimeParse (Date As String, Time As String) As Long

  DeviceDefaultDateFormat As String [read only]

  DeviceDefaultTimeFormat As String [read only]

  GetDayOfMonth (Ticks As Long) As Int

  GetDayOfWeek (Ticks As Long) As Int

  GetDayOfYear (Ticks As Long) As Int

  GetHour (Ticks As Long) As Int

  GetMinute (Ticks As Long) As Int

  GetMonth (Ticks As Long) As Int

  GetSecond (Ticks As Long) As Int

  GetTimeZoneOffsetAt (Date As Long) As Double

  GetYear (Ticks As Long) As Int

  Now As Long [read only]

  SetTimeZone (OffsetHours As Double)

  TicksPerDay As Long

  TicksPerHour As Long

  TicksPerMinute As Long

  TicksPerSecond As Long

  Time (Ticks As Long) As String

  TimeFormat As String

  TimeParse (Time As String) As Long

  TimeZoneOffset As Double [read only]

Members description:

Add (Ticks As Long, Years As Int, Months As Int, Days As Int) As Long
Returns a ticks value which is the result of adding the specified time spans to the given ticks value.
Pass negative values if you want to subtract the values.
Example:
Dim Tomorrow As Long
Tomorrow = DateTime.Add(DateTime.Now, 0, 0, 1)
Log("Tomorrow date is: " & DateTime.Date(Tomorrow))
Date (Ticks As Long) As String
Returns a string representation of the date (which is stored as ticks).
The date format can be set with the DateFormat keyword.
Example:
Log("Today is: " & DateTime.Date(DateTime.Now))
DateFormat As String
Gets or sets the format used to parse date strings.
See this page for the supported patterns:
formats.
The default pattern is MM/dd/yyyy (04/23/2002 for example).
DateParse (Date As String) As Long
Parses the given date string and returns its ticks representation.
An exception will be thrown if parsing fails.
Example:
Dim SomeTime As Long
SomeTime = DateTime.DateParse("02/23/2007")
DateTimeParse (Date As String, Time As String) As Long
Parses the given date and time strings and returns the ticks representation.
DeviceDefaultDateFormat As String [read only]
Returns the default date format based on the device selected language.
DeviceDefaultTimeFormat As String [read only]
Returns the default time format based on the device selected language.
GetDayOfMonth (Ticks As Long) As Int
Returns the day of month component from the ticks value.
Values are between 1 to 31.
GetDayOfWeek (Ticks As Long) As Int
Returns the day of week component from the ticks value.
Values are between 1 to 7, where 1 means Sunday.
You can use the AHLocale library if you need to change the first day.
GetDayOfYear (Ticks As Long) As Int
Returns the day of year component from the ticks value.
Values are between 1 to 366.
GetHour (Ticks As Long) As Int
Returns the hour of day component from the ticks value.
Values are between 0 to 23.
GetMinute (Ticks As Long) As Int
Returns the minutes within a hour component from the ticks value.
Values are between 0 to 59.
GetMonth (Ticks As Long) As Int
Returns the month of year component from the ticks value.
Values are between 1 to 12.
GetSecond (Ticks As Long) As Int
Returns the seconds within a minute component from the ticks value.
Values are between 0 to 59.
GetTimeZoneOffsetAt (Date As Long) As Double
Returns the offset measured in hours from UTC at the specified date (offset can change due to daylight saving settings).
GetYear (Ticks As Long) As Int
Returns the year component from the ticks value.
Now As Long [read only]
Gets the current time as ticks (number of milliseconds since January 1, 1970).
SetTimeZone (OffsetHours As Double)
Sets the application time zone. This setting affect the conversions of dates to ticks value and vice versa (device default settings are not changed).
TicksPerDay As Long
TicksPerHour As Long
TicksPerMinute As Long
TicksPerSecond As Long
Time (Ticks As Long) As String
Returns a string representation of the time (which is stored as ticks).
The time format can be set with the TimeFormat keyword.
Example:
Log("The time now is: " & DateTime.Time(DateTime.Now))
TimeFormat As String
Gets or sets the format used to parse time strings.
See this page for the supported patterns:
formats.
The default pattern is HH:mm:ss (23:45:12 for example).
TimeParse (Time As String) As Long
Parses the given time string and returns its ticks representation.
Note that the returned value date will be today.
TimeZoneOffset As Double [read only]
Returns the current offset measured in hours from UTC.

Exception

Holds a thrown exception.
You can access the last thrown exception by calling LastException.
For example:
Try
Dim in As InputStream
in = File.OpenInput(File.DirInternal, "SomeMissingFile.txt")
'...
Catch
Log(LastException.Message)
End Try
If in.IsInitialized Then in.Close

Events:

None

Members:


  IsInitialized As Boolean

  Message As String [read only]

Members description:

IsInitialized As Boolean
Message As String [read only]

Keywords


Events:

None

Members:


  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

  ATan2 (Y As Double, X As Double) As Double

  ATan2D (Y As Double, X As Double) As Double

  ATanD (Value As Double) As Double

  BytesToString (Data() As Byte, StartOffset As Int, Length As Int, CharSet As String) As String

  CallSub (Component As Object, Sub As String) As Object

  CallSub2 (Component As Object, Sub As String, Argument As Object) As Object

  CallSub3 (Component As Object, Sub As String, Argument1 As Object, Argument2 As Object) As Object

  CallSubDelayed (Component As Object, Sub As String)

  CallSubDelayed2 (Component As Object, Sub As String, Argument As Object)

  CallSubDelayed3 (Component As Object, Sub As String, Argument1 As Object, Argument2 As Object)

  Catch

  cE As Double

  Ceil (Number As Double) As Double

  CharsToString (Chars() As Char, StartOffset As Int, Length As Int) As String

  Chr (UnicodeValue As Int) As Char

  Continue

  Cos (Radians As Double) As Double

  CosD (Degrees As Double) As Double

  cPI As Double

  CreateMap

  CRLF As String

  Density As Float

  Dim

  DipToCurrent (Length As Int) As Int

  Exit

  ExitApplication

  ExitApplication2 (ExitCode As Int)

  False As Boolean

  File As File

  Floor (Number As Double) As Double

  For

  GetEnvironmentVariable (Key As String, DefaultValue As String) As String

  GetSystemProperty (Key As String, DefaultValue As String) As String

  GetType (object As Object) As String

  If

  Is

  IsDevTool (ToolName As String) As Boolean

  IsNumber (Text As String) As Boolean

  LastException As Exception

  Log (Message As String)

  Logarithm (Number As Double, Base As Double) As Double

  LogDebug (Message As String)

  LogError (Message As String)

  Max (Number1 As Double, Number2 As Double) As Double

  Me As Object

  Min (Number1 As Double, Number2 As Double) As Double

  Not (Value As Boolean) As Boolean

  Null As Object

  NumberFormat (Number As Double, MinimumIntegers As Int, MaximumFractions As Int) As String

  NumberFormat2 (Number As Double, MinimumIntegers As Int, MaximumFractions As Int, MinimumFractions As Int, GroupingUsed As Boolean) As String

  Power (Base As Double, Exponent As Double) As Double

  QUOTE As String

  Regex As Regex

  Return

  Rnd (Min As Int, Max As Int) As Int

  RndSeed (Seed As Long)

  Round (Number As Double) As Long

  Round2 (Number As Double, DecimalPlaces As Int) As Double

  Select

  Sender As Object

  SetSystemProperty (Key As String, Value As String)

  Sin (Radians As Double) As Double

  SinD (Degrees As Double) As Double

  Sleep (Milliseconds As Int)

  SmartStringFormatter (Format As String, Value As Object) As String

  Sqrt (Value As Double) As Double

  StartMessageLoop

  StopMessageLoop

  Sub

  SubExists (Object As Object, Sub As String) As Boolean

  TAB As String

  Tan (Radians As Double) As Double

  TanD (Degrees As Double) As Double

  True As Boolean

  Try

  Type

  Until

  While

Members description:

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, or Object if the type is not specified.
The syntax is: Array As type (list of values).
Example:
Dim Days() As String = 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.
ATan2 (Y As Double, X As Double) As Double
Returns the angle measured with radians.
ATan2D (Y As Double, X As Double) As Double
Returns the angle measured with degrees.
ATanD (Value As Double) As Double
Returns the angle measured with degrees.
BytesToString (Data() As Byte, StartOffset As Int, Length As Int, CharSet As String) As String
Decodes the given bytes array as a 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 (Component As Object, Sub As String) As Object
Dynamically calls a sub based on the sub name.
Note that unlike Basic4android CallSub is not required unless you need to call a sub based on the sub name.
CallSub2 (Component As Object, Sub As String, Argument As Object) As Object
Similar to CallSub. Calls a sub with a single argument.
CallSub3 (Component As Object, Sub As String, Argument1 As Object, Argument2 As Object) As Object
Similar to CallSub. Calls a sub with two arguments.
CallSubDelayed (Component As Object, Sub As String)
Dynamically calls a sub. The sub will be called after the current code execution completes.
CallSubDelayed2 (Component As Object, Sub As String, Argument As Object)
Similar to CallSubDelayed. Calls a sub with a single argument.
CallSubDelayed3 (Component As Object, Sub As String, Argument1 As Object, Argument2 As Object)
Similar to CallSubDelayed. Calls a sub with two arguments.
Catch
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
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 (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
Calculates the trigonometric cosine function. Angle measured in radians.
CosD (Degrees As Double) As Double
Calculates the trigonometric cosine function. Angle measured in degrees.
cPI As Double
PI constant.
CreateMap
Creates a Map with the given key / value pairs.
The syntax is: CreateMap (key1: value1, key2: value2, ...)
Example:
Dim m As Map = CreateMap("January": 1, "February": 2)
CRLF As String
New line character. The value of Chr(10).
Density As Float
Returns the monitor scale, which is DPI / 96.
(DPI stands for dots per inch).
Dim
Declares a variable.
Syntax:
Declare a single variable:
Dim variable name [As type] [= expression]
The default type is String.

Declare multiple variables. All variables will be of the specified type.
Dim variable1 [= expression], variable2 [= expression], ..., [As type]
Note that the shorthand syntax only applies to Dim keyword.
Example:Dim a = 1, b = 2, c = 3 As Int

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.
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)

Note that a shorthand syntax for this method is available. Any number followed by the string 'dip'
will be converted in the same manner (no spaces are allowed between the number and 'dip').
So the previous code is equivalent to:
Button1.Width = 100dip 'dip -> density independent pixel
Exit
Exits the most inner loop.
Note that Exit inside a Select block will exit the Select block.
ExitApplication
Immediately ends the application and stops the process.
ExitApplication2 (ExitCode As Int)
Immediately ends the application and stops the process.
The specified ExitCode will be returned as the process exit code (0 means no errors).
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
If the iterator variable was not declared before it will be of type Int.

Or:
For Each variable As type In collection
...
Next
Examples:
For i = 1 To 10
Log(i) 'Will print 1 to 10 (inclusive).
Next
For Each n As Int In Numbers 'an array
Sum = Sum + n
Next

Note that the loop limits will only be calculated once before the first iteration.
GetEnvironmentVariable (Key As String, DefaultValue As String) As String
Returns the value of the environment variable mapped to the given key.
Returns the DefaultValue parameter if there is no such variable.
GetSystemProperty (Key As String, DefaultValue As String) As String
Gets the value of the system property mapped to the given key.
Returns the DefaultValue parameter if there is no such property.
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
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
IsDevTool (ToolName As String) As Boolean
Returns true if ToolName equals B4J.
IsNumber (Text As String) As Boolean
Tests whether the specified string can be safely parsed as a number.
LastException As Exception
Returns the last exception that was caught (if such exists).
Log (Message As String)
Logs a message to StdOut stream.
Logarithm (Number As Double, Base As Double) As Double
LogDebug (Message As String)
Logs a message. The message will only be logged in Debug mode.
LogError (Message As String)
Logs a message to StdErr stream.
Max (Number1 As Double, Number2 As Double) As Double
Returns the larger number between the two numbers.
Me As Object
For classes: returns a reference to the current instance.
For activities and services: returns a reference to an object that can be used with CallSub, CallSubDelayed and SubExists keywords.
Cannot be used in code modules.
Min (Number1 As Double, Number2 As Double) As Double
Returns the smaller number between the two numbers.
Not (Value As Boolean) As Boolean
Inverts the value of the given boolean.
Null As Object
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 (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"
Power (Base As Double, Exponent As Double) As Double
Returns the Base value raised to the Exponent power.
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).
RndSeed (Seed As Long)
Sets the random seed value.
This method can be used for debugging as it allows you to get the same results each time.
Round (Number As Double) As Long
Returns the long number closest 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 = 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.
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
SetSystemProperty (Key As String, Value As String)
Sets the system property indicated by the given key.
Sin (Radians As Double) As Double
Calculates the trigonometric sine function. Angle measured in radians.
SinD (Degrees As Double) As Double
Calculates the trigonometric sine function. Angle measured in degrees.
Sleep (Milliseconds As Int)
Pauses the current sub execution and resumes it after the specified time.
SmartStringFormatter (Format As String, Value As Object) As String
Sqrt (Value As Double) As Double
Returns the positive square root.
StartMessageLoop
Calling this method causes the thread to start managing the message queue.
This method should only be called in non-UI applications.
StopMessageLoop
Calling this method will cause the thread to stop managing the message queue.
This method should only be called in non-UI applications.
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).
SubExists (Object As Object, Sub As String) As Boolean
Tests whether the object includes the specified method.
Returns false if the object was not initialized or not an instance of a user class.
TAB As String
Tab character.
Tan (Radians As Double) As Double
Calculates the trigonometric tangent function. Angle measured in radians.
TanD (Degrees As Double) As Double
Calculates the trigonometric tangent function. Angle measured in degrees.
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

String

Strings are immutable in Basic4android, which means that you can change the value of a string variable but you cannot change the text stored in a string object.
So methods like SubString, Trim and ToLowerCase return a new string, they do not change the value of the current string.
Typical usage:
Dim s As String
s = "some text"
s = s.Replace("a", "b")

You can use StringBuilder if you need a mutable string.
Note that string literals are also string objects:
Log(" some text ".Trim)

Events:

None

Members:


  CharAt (Index As Int) As Char

  CompareTo (Other As String) As Int

  Contains (SearchFor As String) As Boolean

  EndsWith (Suffix As String) As Boolean

  EqualsIgnoreCase (other As String) As Boolean

  GetBytes (Charset As String) As Byte()

  IndexOf (SearchFor As String) As Int

  IndexOf2 (SearchFor As String, Index As Int) As Int

  LastIndexOf (SearchFor As String) As Int

  LastIndexOf2 (SearchFor As String, Index As Int) As Int

  Length As Int

  Replace (Target As String, Replacement As String) As String

  StartsWith (Prefix As String) As Boolean

  SubString (BeginIndex As Int) As String

  SubString2 (BeginIndex As Int, EndIndex As Int) As String

  ToLowerCase As String

  ToUpperCase As String

  Trim As String

Members description:

CharAt (Index As Int) As Char
Returns the character at the given index.
CompareTo (Other As String) As Int
Lexicographically compares the two strings.
Returns a value less than 0 if the current string precedes Other.
Returns 0 if both strings are equal.
Returns a value larger than 0 if the current string comes after Other.
Note that upper case characters precede lower case characters.

Examples:
"abc".CompareTo("da") ' < 0
"abc".CompareTo("Abc") ' > 0
"abc".CompareTo("abca")' < 0
Contains (SearchFor As String) As Boolean
Tests whether the string contains the given string parameter.
EndsWith (Suffix As String) As Boolean
Returns true if this string ends with the given Suffix.
EqualsIgnoreCase (other As String) As Boolean
Returns true if both strings are equal ignoring their case.
GetBytes (Charset As String) As Byte()
Encodes the string into a new array of bytes.
Example:
Dim Data() As Byte
Data = "Some string".GetBytes("UTF8")
IndexOf (SearchFor As String) As Int
Returns the index of the first occurrence of SearchFor string in the string.
Returns -1 if SearchFor was not found.
IndexOf2 (SearchFor As String, Index As Int) As Int
Returns the index of the first occurrence of SearchFor string in the string.
Starts searching from the given Index.
Returns -1 if SearchFor was not found.
LastIndexOf (SearchFor As String) As Int
Returns the index of the first occurrence of SearchFor string in the string.
The search starts at the end of the string and advances to the beginning.
LastIndexOf2 (SearchFor As String, Index As Int) As Int
Returns the index of the first occurrence of SearchFor string in the string.
The search starts at the given index and advances to the beginning.
Length As Int
Returns the length of this string.
Replace (Target As String, Replacement As String) As String
Returns a new string resulting from the replacement of all the occurrences of Target with Replacement.
StartsWith (Prefix As String) As Boolean
Returns true if this string starts with the given Prefix.
SubString (BeginIndex As Int) As String
Returns a new string which is a substring of the original string.
The new string will include the character at BeginIndex and will extend to the end of the string.

Example:
"012345".SubString(2) 'returns "2345"
SubString2 (BeginIndex As Int, EndIndex As Int) As String
Returns a new string which is a substring of the original string.
The new string will include the character at BeginIndex and will extend to the character at EndIndex, not including the last character.

Example:
"012345".SubString2(2, 4) 'returns "23"
ToLowerCase As String
Returns a new string which is the result of lower casing this string.
ToUpperCase As String
Returns a new string which is the result of upper casing this string.
Trim As String
Returns a copy of the original string without any leading or trailing white spaces.

StringBuilder

StringBuilder is a mutable string, unlike regular strings which are immutable.
StringBuilder is especially useful when you need to concatenate many strings.
The following code demonstrates the performance boosting of StringBuilder:
Dim start As Long
start = DateTime.Now
'Regular string
Dim s As String
For i = 1 To 5000
  s = s & i
Next
Log(DateTime.Now - start)
'StringBuilder
start = DateTime.Now
Dim sb As StringBuilder
sb.Initialize
For i = 1 To 5000
  sb.Append(i)
Next
Log(DateTime.Now - start)

Tested on a real device, the first 'for loop' took about 20 seconds and the second took less then tenth of a second.
The reason is that the code: s = s & i creates a new string each iteration (strings are immutable).
The method StringBuilder.ToString converts the object to a string.

Events:

None

Members:


  Append (Text As String) As StringBuilder

  Initialize

  Insert (Offset As Int, Text As String) As StringBuilder

  IsInitialized As Boolean

  Length As Int [read only]

  Remove (StartOffset As Int, EndOffset As Int) As StringBuilder

  ToString As String

Members description:

Append (Text As String) As StringBuilder
Appends the specified text at the end.
Returns the same object, so you can chain methods.
Example:
sb.Append("First line").Append(CRLF).Append("Second line")
Initialize
Initializes the object.
Example:
Dim sb As StringBuilder
sb.Initialize
sb.Append("The value is: ").Append(SomeOtherVariable).Append(CRLF)
Insert (Offset As Int, Text As String) As StringBuilder
Inserts the specified text at the specified offset.
IsInitialized As Boolean
Length As Int [read only]
Returns the number of characters.
Remove (StartOffset As Int, EndOffset As Int) As StringBuilder
Removes the specified characters.
StartOffset - The first character to remove.
EndOffset - The ending index. This character will not be removed.
ToString As String
Converts the object to a string.

Timer

A Timer object generates ticks events at specified intervals.
Using a timer is a good alternative to a long loop, as it allows the UI thread to handle other events and messages.
Note that the timer events will not fire while the UI thread is busy running other code.
The timer Enabled property is set to False by default. To make it start working you should change it to True.

Events:

Tick

Members:


  Enabled As Boolean

  Initialize (EventName As String, Interval As Long)

  Interval As Long

  IsInitialized As Boolean

Members description:

Enabled As Boolean
Gets or sets whether the timer is enabled (ticking).
Initialize (EventName As String, Interval As Long)
Initializes the timer with the event sub prefix and the specified interval (measured in milliseconds).
Example:
Timer1.Initialize("Timer1", 1000)
Timer1.Enabled = True

Sub Timer1_Tick
'Handle tick events
End Sub
Interval As Long
Gets or sets the interval between tick events, measured in milliseconds.
IsInitialized As Boolean

Top