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.
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: DimnowAsLong now = DateTime.Now Msgbox("The date is: " & DateTime.Date(now) & CRLF & _
"The time is: " & DateTime.Time(now), "")
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: DimTomorrowAsLong Tomorrow = DateTime.Add(DateTime.Now, 0, 0, 1)
Log("Tomorrow date is: " & DateTime.Date(Tomorrow))
Date (TicksAsLong) AsString
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))
DateFormatAsString
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 (DateAsString) AsLong
Parses the given date string and returns its ticks representation. An exception will be thrown if parsing fails. Example: DimSomeTimeAsLong SomeTime = DateTime.DateParse("02/23/2007")
DateTimeParse (DateAsString, TimeAsString) AsLong
Parses the given date and time strings and returns the ticks representation.
DeviceDefaultDateFormatAsString [read only]
Returns the default date format based on the device selected language.
DeviceDefaultTimeFormatAsString [read only]
Returns the default time format based on the device selected language.
GetDayOfMonth (TicksAsLong) AsInt
Returns the day of month component from the ticks value. Values are between 1 to 31.
GetDayOfWeek (TicksAsLong) AsInt
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 (TicksAsLong) AsInt
Returns the day of year component from the ticks value. Values are between 1 to 366.
GetHour (TicksAsLong) AsInt
Returns the hour of day component from the ticks value. Values are between 0 to 23.
GetMinute (TicksAsLong) AsInt
Returns the minutes within a hour component from the ticks value. Values are between 0 to 59.
GetMonth (TicksAsLong) AsInt
Returns the month of year component from the ticks value. Values are between 1 to 12.
GetSecond (TicksAsLong) AsInt
Returns the seconds within a minute component from the ticks value. Values are between 0 to 59.
GetTimeZoneOffsetAt (DateAsLong) AsDouble
Returns the offset measured in hours from UTC at the specified date (offset can change due to daylight saving settings).
GetYear (TicksAsLong) AsInt
Returns the year component from the ticks value.
NowAsLong [read only]
Gets the current time as ticks (number of milliseconds since January 1, 1970).
SetTimeZone (OffsetHoursAsDouble)
Sets the application time zone. This setting affect the conversions of dates to ticks value and vice versa (device default settings are not changed).
TicksPerDayAsLong
TicksPerHourAsLong
TicksPerMinuteAsLong
TicksPerSecondAsLong
Time (TicksAsLong) AsString
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))
TimeFormatAsString
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 (TimeAsString) AsLong
Parses the given time string and returns its ticks representation. Note that the returned value date will be today.
TimeZoneOffsetAsDouble [read only]
Returns the current offset measured in hours from UTC.
Holds a thrown exception. You can access the last thrown exception by calling LastException. For example: Try DiminAsInputStream in = File.OpenInput(File.DirInternal, "SomeMissingFile.txt")
'... Catch Log(LastException.Message)
EndTry Ifin.IsInitializedThenin.Close
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: DimDays() AsString = ArrayAsString("Sunday", "Monday", ...)
Asc (CharAsChar) AsInt
Returns the unicode code point of the given character or first character in 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: DimsAsString s = BytesToString(Buffer, 0, Buffer.Length, "UTF-8")
CallSub (ComponentAsObject, SubAsString) AsObject
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.
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
cEAsDouble
e (natural logarithm base) constant.
Ceil (NumberAsDouble) AsDouble
Returns the smallest double that is greater or equal to the specified number and is equal to an integer.
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 (UnicodeValueAsInt) AsChar
Returns the character that is represented by the given unicode value.
Continue
Stops executing the current iteration and continues with the next one.
Cos (RadiansAsDouble) AsDouble
Calculates the trigonometric cosine function. Angle measured in radians.
CosD (DegreesAsDouble) AsDouble
Calculates the trigonometric cosine function. Angle measured in degrees.
cPIAsDouble
PI constant.
CreateMap
Creates a Map with the given key / value pairs. The syntax is: CreateMap (key1: value1, key2: value2, ...) Example: DimmAsMap = CreateMap("January": 1, "February": 2)
CRLFAsString
New line character. The value of Chr(10).
DensityAsFloat
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:Dima = 1, b = 2, c = 3AsInt
Declare an array: Dim variable(Rank1, Rank2, ...) [As type] Example:DimDays(7) AsString The actual rank can be omitted for zero length arrays.
DipToCurrent (LengthAsInt) AsInt
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 (ExitCodeAsInt)
Immediately ends the application and stops the process. The specified ExitCode will be returned as the process exit code (0 means no errors).
FalseAsBoolean
FileAsFile
Files related methods.
Floor (NumberAsDouble) AsDouble
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: Fori = 1To10 Log(i) 'Will print 1 to 10 (inclusive). Next ForEachnAsIntInNumbers'an array Sum = Sum + n Next
Note that the loop limits will only be calculated once before the first iteration.
Gets the value of the system property mapped to the given key. Returns the DefaultValue parameter if there is no such property.
GetType (objectAsObject) AsString
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: Fori = 0ToActivity.NumberOfViews - 1 IfActivity.GetView(i) IsButtonThen DimbAsButton b = Activity.GetView(i)
b.Color = Colors.Blue EndIf Next
IsDevTool (ToolNameAsString) AsBoolean
Returns true if ToolName equals B4J.
IsNumber (TextAsString) AsBoolean
Tests whether the specified string can be safely parsed as a number.
LastExceptionAsException
Returns the last exception that was caught (if such exists).
Log (MessageAsString)
Logs a message to StdOut stream.
Logarithm (NumberAsDouble, BaseAsDouble) AsDouble
LogDebug (MessageAsString)
Logs a message. The message will only be logged in Debug mode.
LogError (MessageAsString)
Logs a message to StdErr stream.
Max (Number1AsDouble, Number2AsDouble) AsDouble
Returns the larger number between the two numbers.
MeAsObject
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 (Number1AsDouble, Number2AsDouble) AsDouble
Returns the smaller number between the two numbers.
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"
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 (BaseAsDouble, ExponentAsDouble) AsDouble
Returns the Base value raised to the Exponent power.
QUOTEAsString
Quote character. The value of Chr(34).
RegexAsRegex
Regular expressions related methods.
Return
Returns from the current sub and optionally returns the given value. Syntax: Return [value]
Rnd (MinAsInt, MaxAsInt) AsInt
Returns a random integer between Min (inclusive) and Max (exclusive).
RndSeed (SeedAsLong)
Sets the random seed value. This method can be used for debugging as it allows you to get the same results each time.
Round (NumberAsDouble) AsLong
Returns the long number closest to the given number.
Rounds the given number and leaves up to the specified number of fractional digits.
Select
Compares a single value to multiple values. Example: DimvalueAsInt = 7 Selectvalue Case1 Log("One")
Case2, 4, 6, 8 Log("Even")
Case3, 5, 7, 9 Log("Odd larger than one")
CaseElse Log("Larger than 9")
EndSelect
SenderAsObject
Returns the object that raised the event. Only valid while inside the event sub. Example: SubButton_Click DimbAsButton b = Sender b.Text = "I've been clicked" EndSub
SetSystemProperty (KeyAsString, ValueAsString)
Sets the system property indicated by the given key.
Sin (RadiansAsDouble) AsDouble
Calculates the trigonometric sine function. Angle measured in radians.
SinD (DegreesAsDouble) AsDouble
Calculates the trigonometric sine function. Angle measured in degrees.
Sleep (MillisecondsAsInt)
Pauses the current sub execution and resumes it after the specified time.
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: SubMySub (FirstNameAsString, LastNameAsString, AgeAsInt, OtherValues() AsDouble) AsBoolean ...
EndSub 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 (ObjectAsObject, SubAsString) AsBoolean
Tests whether the object includes the specified method. Returns false if the object was not initialized or not an instance of a user class.
TABAsString
Tab character.
Tan (RadiansAsDouble) AsDouble
Calculates the trigonometric tangent function. Angle measured in radians.
TanD (DegreesAsDouble) AsDouble
Calculates the trigonometric tangent function. Angle measured in degrees.
TrueAsBoolean
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: TypeMyType (NameAsString, Items(10) AsInt)
Dima, bAsMyType 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
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: DimsAsString 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)
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.
Tests whether the string contains the given string parameter.
EndsWith (SuffixAsString) AsBoolean
Returns true if this string ends with the given Suffix.
EqualsIgnoreCase (otherAsString) AsBoolean
Returns true if both strings are equal ignoring their case.
GetBytes (CharsetAsString) AsByte()
Encodes the string into a new array of bytes. Example: DimData() AsByte Data = "Some string".GetBytes("UTF8")
IndexOf (SearchForAsString) AsInt
Returns the index of the first occurrence of SearchFor string in the string. Returns -1 if SearchFor was not found.
IndexOf2 (SearchForAsString, IndexAsInt) AsInt
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 (SearchForAsString) AsInt
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.
Returns a new string resulting from the replacement of all the occurrences of Target with Replacement.
StartsWith (PrefixAsString) AsBoolean
Returns true if this string starts with the given Prefix.
SubString (BeginIndexAsInt) AsString
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.
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"
ToLowerCaseAsString
Returns a new string which is the result of lower casing this string.
ToUpperCaseAsString
Returns a new string which is the result of upper casing this string.
TrimAsString
Returns a copy of the original string without any leading or trailing white spaces.
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: DimstartAsLong start = DateTime.Now 'Regular string DimsAsString Fori = 1To5000 s = s & i Next Log(DateTime.Now - start)
'StringBuilder start = DateTime.Now DimsbAsStringBuilder sb.Initialize Fori = 1To5000 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.
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: DimsbAsStringBuilder sb.Initialize sb.Append("The value is: ").Append(SomeOtherVariable).Append(CRLF)
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.
Gets or sets whether the timer is enabled (ticking).
Initialize (EventNameAsString, IntervalAsLong)
Initializes the timer with the event sub prefix and the specified interval (measured in milliseconds). Example: Timer1.Initialize("Timer1", 1000)
Timer1.Enabled = True
SubTimer1_Tick 'Handle tick events EndSub
IntervalAsLong
Gets or sets the interval between tick events, measured in milliseconds.