From Xojo Documentation

Revision as of 01:27, 24 February 2022 by Gperlman (talk | contribs) (Notes)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

Returns the numeric form of a string as an Int64.


result = CLong(string)

Part Type Description
result Int64 The numeric equivalent of the string passed.
string String Any valid string expression.
stringVariable String Any variable of type String.


The CLong function stops reading the string at the first character it doesn’t recognize as part of a number. All other characters are automatically stripped.

It does recognize prefixes &o (octal), &b (binary), and &h (hexadecimal). However, spaces are not allowed in front of the ampersand. That is, " &hFF" returns 0, but "&hFF" returns 255.

CLong returns zero if string contains no numbers.

Sample Code

This code use the CLong function to return the numbers contained in a string literal or a string variable

Dim n As Int64
Dim s As String
n = CLong("12345") // returns 12345
n = CLong(" 12345") // returns 0
n = CLong("123 45") // returns 123
n = CLong("&hFFF") // returns 4095
n = CLong("&b1111") // returns 15

s = "12345"
n = s.CLong // returns 12345

See Also

CDbl, CStr, Int64.FromText, Str, Val functions; &b, &h, &o literals; Int64 data type