Application is a special singleton object that allows you to handle application related events and holds other application related methods. The events can only be handled in the main module. The subs prefix should be Application. The Start event is raised when the application starts. Nav is the default navigation controller. The Active event is raised when the application becomes active. It is usually raised immediately after Start event and after resuming from the background. The InActive event is raised when the applications becomes inactive. This happens when there is an interruption such as a phone call or before the Background event. The Background event is raised when the process is moved to the background. You should expect the process to be killed a few seconds after this event. The Foreground event is raised when the app returns to the foreground after it was in the background (assuming that the process was not killed). The OpenUrl event is raised when another app has called OpenUrl with a scheme that this app has registered.
Events:
Start (Nav As NavigationController) Active Inactive Background OpenUrl (Url As String, Data As Object, SourceApplication As String) As Boolean Foreground ReceiveLocalNotification (LN As Notification) PushToken (Success As Boolean, Token() As Byte) RemoteNotification (Message As Map, CompletionHandler As CompletionHandler)
Gets or sets the app icon badge number. You need to call RegisterUserNotifications before setting this property.
CanOpenURL (UrlAsString) AsBoolean
Returns true if there is an app that can open the given url. Starting from iOS 9 you need to use the #QueriesScheme to list the schemes that will be passed to this method.
ClearLocalNotifications
Clears all scheduled local notifications.
GetScheduledNotificationsAsList
Returns a list with the scheduled local notifications.
IdleTimerDisabledAsBoolean
If true then the screen will not be locked automatically even if the user is not interacting with it, as long as the application is in the foreground.
iPadDeviceAsBoolean [read only]
Returns true if the current device is an iPad device.
Is64BitProcessAsBoolean [read only]
Returns true if the current process is a 64 bit process.
IsInitializedAsBoolean
Tests whether this object was initialized.
IsSimulatorAsBoolean
KeyControllerAsObject
Gets or sets the root controller. You can use this property to switch to a different controller.
LaunchOptionsAsMap
Returns a Map with data passed to the app during launch (if there is such data).
NetworkActivityIndicatorVisibleAsBoolean
Gets or sets whether the network activity indicator (in the top bar) is visible.
OpenURL (UrlAsString) AsBoolean
Sends the Url to the system. If there is an app registered to the Url scheme then the app will be started.
OpenURLAsync (UrlAsString)
Calls OpenUrl from a background thread. This is useful as OpenURL can sometimes take several seconds to complete.
Requests the user permission to use one of more of the notifications features. You must call this method before registering a local notification or setting the ApplicationIconBadgeNumber.
TagAsObject
Gets or sets the Tag object. This is a placeholder for any object you like to tie to this object.
A String with formatting attributes. Note that an AttributedString cannot be used instead of String unless the method explicitly expects an AttributedString.
A predefined object containing color constants. Colors are represented as Int values. The first byte is the alpha level and the other three values are the R, G and B components.
Similar to RGB. Allows you to set the alpha level.
BlackAsInt [read only]
BlueAsInt [read only]
CyanAsInt [read only]
DarkGrayAsInt [read only]
GrayAsInt [read only]
GreenAsInt [read only]
LightGrayAsInt [read only]
MagentaAsInt [read only]
RedAsInt [read only]
RGB (RAsInt, GAsInt, BAsInt) AsInt
Returns an integer value representing the color built from the three components. Each component should be a value between 0 to 255 (inclusive). The alpha is set to 255.
Date and time related methods. Date and time values are stored as ticks. Ticks represent 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. DateUtils module should be used for time calculations when working with intervals larger than hours.
Returns a ticks value which is the result of adding the specified time spans to the given ticks value. Pass negative values to substract. In most cases it is better to use DateUtils.AddPeriod.
Date (TicksAsLong) AsString
Returns a string representation of the date (which is stored as ticks). Example: Log("Today is: " & DateTime.Date(DateTime.Now))
DateFormatAsString
Gets or sets the process date format. The default format is MM/dd/yyyy (04/23/2002 for example). The patterns are the same as in B4A and B4J. Supported formats
DateParse (DateAsString) AsLong
Parses the given date string and returns its ticks representation. Example: DimSomeTimeAsLong = 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 device default date format.
DeviceDefaultTimeFormatAsString [read only]
Returns the device default time format.
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.
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 component from the ticks value. Values are between 0 to 23.
GetMinute (TicksAsLong) AsInt
Returns the minutes within hour component from the ticks value. Values are between 0 to 59.
GetMonth (TicksAsLong) AsInt
Returns the month component from the ticks value. Values are between 1 to 12.
GetSecond (TicksAsLong) AsInt
Returns the seconds within minute component from the ticks value. Values are between 0 to 59.
GetTimeZoneOffsetAt (TicksAsLong) AsDouble
Returns the offset measured in hours from UTC at the specified date.
GetYear (TicksAsLong) AsInt
Returns the year component from the ticks value.
NowAsLong [read only]
Returns the current time represented as the number of milliseconds since 1/1/1970 00:00 UTC.
SetTimeZone (OffsetHoursAsDouble)
Sets the process time zone.
TicksPerDayAsLong [read only]
Number of ticks per 24 hours. In almost all cases it is better to use DateUtils module when working with days. Note that there are days with less or more than 24 hours.
TicksPerHourAsLong [read only]
Number or ticks per hour.
TicksPerMinuteAsLong [read only]
Number of ticks per minute.
TicksPerSecondAsLong [read only]
Number of ticks per second (1000).
Time (TicksAsLong) AsString
Returns a string representation of the time (which is stored as ticks). Example: Log("The time now is: " & DateTime.Time(DateTime.Now))
TimeFormatAsString
Gets or sets the process time format. The default format is HH:mm:ss (23:45:12 for example). The patterns are the same as in B4A and B4J. Supported formats
TimeZoneOffsetAsDouble [read only]
Returns the current offset measured in hours from UTC.
Creates a single dimension array of the specified type. The syntax is: Array As type (list of values). Example: DimDays() AsString Days = ArrayAsString("Sunday", "Monday", ...)
Asc (CharAsChar) AsInt
Returns the unicode code point of the give character.
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 = BytesToString(Buffer, 0, Buffer.Length, "UTF-8")
CallSub (ComponentAsObject, SubAsString) AsObject
Dynamically calls a sub. This can be used to implement events. In most cases you should not use CallSub and instead directly call the target sub. Nothing happens if the sub does not exist. Component - The target module or instance. Sub - 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 [read only]
e (natural logarithm base) constant.
Ceil (NumberAsDouble) AsDouble
Returns the smaller whole number that is larger or equal to the specified number.
Chr (UnicodeValueAsInt) AsChar
Returns the character that is represented by the given unicode value.
ColorsAsColors
Colors related methods.
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 [read only]
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 [read only]
New line character. The value of Chr(10).
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
The logical scale of iOS device is always 1.0. This method returns the value of Length.
Exit
Exits the most inner loop. Note that Exit inside a Select block will exit the Select block.
FalseAsBoolean [read only]
FileAsObject
Files related methods.
Floor (NumberAsDouble) AsDouble
Returns the largest whole number that is smaller or equal to the specified number.
FontAsFont
Font related methods.
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.
GetDeviceLayoutValuesAsLayoutValues
Returns the device LayoutValues. Example: Log(GetDeviceLayoutValues)
GetType (ObjectAsObject) AsString
Returns the Objective C type of the given object.
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
IsAsBoolean
Tests whether the object is of the given type. Note that when a number is converted to object it might change its type to a different type of number (for example a Byte might be converted to an Int). Example: ForEachvAsViewinPage1.RootPanel.GetAllViewsRecursive IfvIsButtonThen DimbAsButton = v b.Color = Colors.Blue EndIf Next
IsDevTool (ToolNameAsString) AsBoolean
Returns true if ToolName equals "B4i".
IsNumber (ValueAsString) AsBoolean
Tests whether the specified string can be safely parsed as a number.
Shows a message box with the given message and title. The dialog is not a modal dialog. The code will not block. EventName - Sets the sub that will handle the Click event. Message - The dialog message. Title - The dialog title. Buttons - A List of strings that will be used as buttons.
Example: Msgbox2("Msg", "Do you want to do delete document?", "Title", Array ("Yes", "No"))
WaitForMsg_Click (ButtonTextAsString)
IfButtonText = "Yes"Then 'delete document EndIf This method returns an object that can be used as the Sender Filter parameter with Wait For.
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 - Whether to group every three integers. Example: Log(NumberFormat2(12345.67, 0, 3, 3, False)) '"12345.670"
PerXToCurrent (PercentageAsFloat) AsFloat
Returns the actual size of the given percentage of the page width. This value is only exact while inside the Page_Resize event. In other cases it is relative to the screen width.
PerYToCurrent (PercentageAsFloat) AsFloat
Returns the actual size of the given percentage of the page height. This value is only exact while inside the Page_Resize event. In other cases it is relative to the screen height.
Power (BaseAsDouble, ExponentAsDouble) AsDouble
Returns the Base value raised to the Exponent power.
QUOTEAsString [read only]
Quote character - Chr(34).
RegexAsObject
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).
Round (NumberAsDouble) AsDouble
Returns the whole number closest to the given number. In most cases it is better to use NumberFormat or NumberFormat2 instead.
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")
CaseElse Log("Larger than 9")
EndSelect
Sender () AsObject
Returns the object that raised the event. Only valid while inside the event sub. Example: SubButton1_Click DimbAsButton = Sender b.Text = "I've been clicked" EndSub
SetDebugAutoFlushLogs (EnabledAsBoolean)
This method has no effect in Release mode. If True then a short pause will be applied after each log message. This is useful for debugging hard crashes that prevent the logs from being printed.
Sin (AngleAsDouble) 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.
Internal keyword used by the Smart String literal.
Sqrt (ValueAsDouble) AsDouble
Returns the positive square root.
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).
Checks whether the given component has a sub with the given number of arguments.
TABAsString [read only]
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 [read only]
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
NativeObject is similar to B4A/B4J JavaObject. It allows you to call native methods and get or set fields. Note that only Objective C APIs can be used. C APIs cannot be called dynamically.
Creates a block that raises the given sub. SubName - The event prefix. The sub signature should be: SubName_Event (Args() As Object) As Object. NumberOfParameters - The number of parameters passed to the block. Should be between 0 to 2. Delayed - Whether the event is raised immediately or it is sent to the message queue.
GetField (FieldAsString) AsNativeObject
Gets the value of the given property or field.
Initialize (ClassNameAsString) AsNativeObject
Initializes a new object and sets it to reference the given class.
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 (SearchForAsString) AsBoolean
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. You can use ByteToString keyword to convert an array of bytes (encoded string) to a string. Example: DimData() AsByte = "Some string".GetBytes("UTF8")
IndexOf (SearchForAsString) AsInt
Returns the index of the first occurrence of the specified string in this string. Returns -1 if the string is not found.
IndexOf2 (SearchForAsString, IndexAsInt) AsInt
Similar to IndexOf. Starts the search from Index.
LastIndexOf (SearchForAsString) AsInt
Returns the index of the first occurrence of the specified string in this string. The search starts at the end of this 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. Example: "012345".SubString(2) 'Returns "2345"
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 as EndIndex (exclusive). Example: "012345".SubString(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.
Gets or sets whether the timer is enabled. New timers are not enabled.
Initialize (EventNameAsString, IntervalAsLong)
Initializes the timer and set the sub that will handle the tick event. The timer is disabled until the Enabled property is set to true. Interval - Timer interval in milliseconds.
IntervalAsLong
Gets or sets the interval, measured in milliseconds.