DataType

Integer


Description

Used to store Integer values. The default value is 0. Generally you will use the Integer data type (equivalent to Int32 on 32-bit apps or Int64 on 64-bit apps) or UInteger (equivalent to UInt32 on 32-bit apps or UInt64 on 64-bit apps). There are also other size-specific Integer data types that are available for use with external OS APIs.

Methods

Name

Parameters

Returns

Shared

FromBinary

theText As String

Integer

FromHex

theText As String

Integer

FromOctal

theText As String

Integer

FromString

value As String, Optional locale As Locale

Integer

Parse

theText As String, Optional locale As Locale

Integer

value As String, Optional locale As Locale

Integer

ToBinary

Optional minimumDigits As Integer

String

ToHex

Optional minimumDigits As Integer

String

ToOctal

Optional minimumDigits As Integer

String

ToString

Optional locale As Locale

String

locale As Locale, format As String

String

Method descriptions


Integer.FromBinary

FromBinary(theText As String) As Integer

Converts a text form of a binary number to an Integer.

Convert “0110” to the Integer value of 6:

Var value As Integer
value = Integer.FromBinary("0110") // value = 6

Integer.FromHex

FromHex(theText As String) As Integer

Converts a text form of a hexadecimal number to an Integer.

Convert “ff” to the Integer value of 255:

Var value As Integer
value = Integer.FromHex("ff") // value = 255

Integer.FromOctal

FromOctal(theText As String) As Integer

Converts a text form of an octal number to an Integer.

Convert “755” to the Integer value 493:

Var value As Integer
value = Integer.FromOctal("755") // value = 493

Integer.FromString

FromString(value As String, Optional locale As Locale) As Integer

Converts a string form of a decimal number to an Integer. Specify a locale to convert thousands separator.

If no locale is specified, then Locale.Raw is used.

An InvalidArgumentException will be raised when value contains anything other than an Integer (including when it is empty). Use Parse if you need to parse text that might contain non-numeric data or might be empty.

Convert a number in text to an Integer:

Var value As Integer
value = Integer.FromString("42") // value = 42

This code converts a number using the US locale:

Var locale As New Locale("en-US")
Var value As Integer
value = Integer.FromString("1,234", locale) // value = 1234

You can also use an exception to catch invalid data:

// Exception raised for invalid text, so you can handle your own
// special cases.
Var value As Integer
Try
  value = Integer.FromString("123ABC")
Catch e As InvalidArgumentException
  value = -1 // if data is invalid, just use -1
End Try

Integer.Parse

Parse(theText As String, Optional locale As Locale) As Integer

Converts theText to an Integer value.


Integer.Parse

Parse(value As String, Optional locale As Locale) As Integer

Converts theText to an Integer value.

If no locale is specified, then Locale.Raw is used.

Numbers are converted only if they are found at the beginning of the text. Any numbers that follow a non-numeric value are ignored. Empty text returns 0.

Convert String/Text to an Integer:

Var i As Integer
i = Integer.Parse("123ABC")
// i = 123

Integer.ToBinary

ToBinary(Optional minimumDigits As Integer) As String

Converts the Integer value to a Text containing its binary representation.

Convert an Integer value to the binary text value:

Var i As Integer = 8
Var binary As String = i.ToBinary(4) // binary = "1000"

Integer.ToHex

ToHex(Optional minimumDigits As Integer) As String

Converts the Integer value to a Text containing its hexadecimal representation.

Convert an Integer value to the hexadecimal text value:

Var i As Integer = 255
Var hex As String = i.ToHex(4) // hex = "00FF"

Integer.ToOctal

ToOctal(Optional minimumDigits As Integer) As String

Converts the Integer value to a Text containing its octal representation.

Convert an Integer value to the octal text value:

Var i As Integer = 10
Var octal As Text = i.ToOctal(4) // octal = "0012"

Integer.ToString

ToString(Optional locale As Locale) As String

Converts the Integer to a String value using the specified locale and format.


Integer.ToString

ToString(locale As Locale, format As String) As String

Converts the Integer to a String value using the specified locale and format.

If no locale is specified, then Locale.Raw is used.

Refer to the Unicode Technical Standard #35, appendix G (Number Format Patterns) for information on how to specify a format.

Convert an Integer value to a String:

Var i As Integer = 42
Var t As String = "The number is " + i.ToString

Add to an Integer directly and convert the new value:

Var n As Integer = 5
Var t As String = Integer(n + 1).ToString // t = "6"

Formats the Integer value:

value = 1245
Var t As String = value.ToString // t = "1245"
t = value.ToString(Locale.Current, "#,###") // t = "1,245"

Notes

Integer values use 4 bytes for 32-bit apps and 8 bytes for 64-bit apps.

Integer values range from -2,147,483,648 to 2,147,483,647 (32-bit apps) or -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 (64-bit apps).

If you assign a value that is larger (or smaller) than what the specific Integer type can hold, then the value will “overflow”. This means the value will wrap around to the corresponding largest or smallest value and continue from there.

Sample code

Var value As Integer
value = 42
value = value * 2

Compatibility

All projects types on all supported operating systems.

See also

Var command; UInteger data type