Skip to main content
Previous sectionNext section

Data Types and Values

This chapter gives a brief overview of the various data types in Basic.

Numbers

Numbers are a sequence of digits which may contain a decimal point. Basic also supports exponential notation to represent numbers.

Some examples of numbers:

PrintLn 1
PrintLn 1.1
PrintLn 1E10
Copy code to clipboard

Strings

Strings in Basic are surrounded by double quotes (") and represent a sequence of letters, digits, and punctuation. The minimum string length is zero. By default, the maximum string length is 32K characters. If you have long strings enabled in your installation, the maximum string length is 3,641,144 characters. For further details, see “Enabling Long String Operations” in the Caché Programming Orientation Guide.

Some examples of strings:

PrintLn "Hello"
PrintLn ""
PrintLn "Goodbye"
Copy code to clipboard

To include a double quote character as a literal within a string, use a pair of double quote characters, as shown in the following example:

PrintLn "Hello ""World"""
Copy code to clipboard

You can concatenate strings using the concatenation operator (&):

PrintLn "Hello" & " " & "Goodbye"
Copy code to clipboard

Caché Basic includes a number of specialized string operations. These are listed in the Caché Basic Reference.

Persistent Multidimensional Arrays (Globals)

A Global is a sparse multidimensional database array. Data can be stored in a global with any number of subscripts. Subscripts in Caché are typeless.

A global is not different from any other type of array, with the exception that the global variable name starts with a caret (^).

Some examples of globals. First, run this example to set the global ^x:

^x = 10
PrintLn "^x has been defined"
Copy code to clipboard

Now, run this example to examine the value of ^x:

PrintLn "The value of ^x is: " & ^x
Copy code to clipboard

Similarly, since globals are arrays, you can set the value of an array reference:

^y("string",1) = 2
^y("string","a") = "b"
PrintLn "Values in ^y are " & ^y("string",1) & " and " & ^y("string","a")
Copy code to clipboard

For more information on arrays, see the “Arrays” chapter in this document. For more information on globals, see the Using Caché Globals document.

Null

The Null keyword is not supported in this version of Basic.

Undefined

Variables in Caché Basic do not need to be declared or defined. By simply assigning a value to a variable it is defined, but until this first assignment all references to this variable are undefined. You can use the Exists function to determine if a variable is defined or undefined:

PrintLn "Does x exist? " & Exists(x)
x = 10

PrintLn "How about now? " & Exists(x)
Copy code to clipboard

Dates

A date value represents a valid date within the range 31 December, 1840 through 31 December, 9999.

You can use the Now function to get the current date and time:

today = Now()
PrintLn "Today is: " & today
Copy code to clipboard

Similarly, you can use the Date and Time functions to get the either the current date or time, respectively:

PrintLn "Date is: " & Date()
PrintLn "Time is: " & Time()
Copy code to clipboard

There are a number of functions for extracting component information from date values. These include Day, Hour, Minute, Month, Second, Weekday, and Year:

today = Now()
PrintLn "Today is: " & today
PrintLn "Year: " & Year(today)
PrintLn "Month: " & Month(today)
PrintLn "Day: " & Day(today)
PrintLn "Weekday: " & Weekday(today)
PrintLn "Hour: " & Hour(today)
PrintLn "Minute: " & Minute(today)
PrintLn "Second: " & Second(today)
Copy code to clipboard

Objects

An object value refers to a instance of an in-memory object. You can assign an object value to any local variable:

person = New Sample.Person()
PrintLn person
Copy code to clipboard

You can refer to the methods and properties of an object using dot syntax:

person.Name = "El Vez"
Copy code to clipboard

You can determine if a variable contains an object using the IsObject function:

str = "A string"
person = New Sample.Person()
tStatement = New %SQL.Statement()

PrintLn "Is string an object? " & IsObject(str)
PrintLn "Is person an object? " & IsObject(person)
PrintLn "Is tStatement an object? " & IsObject(tStatement)
Copy code to clipboard

You cannot assign an object value to a global. Doing so will result in a runtime error.

Assigning an object value to a variable (or object property) has the side effect of incrementing the object's internal reference count. When the number of references to an object reaches 0, Caché will automatically destroy the object (invoke its %OnClose method and remove it from memory).