PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
  • Variant type and NULL
  • Type of a variant
  • Class property on variants
  • Named sub-elements
  • Indexed sub-elements
  • Nesting named and indexed sub-elements
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
The Variant type is used to:
  • store any simple value: boolean, numeric (Currency, Real, Integer, etc.), characters and character string, date (Date, Time, DateTime and Duration), etc.
  • Versions 19 and later
    store named or indexed sub-elements.
    New in version 19
    store named or indexed sub-elements.
    store named or indexed sub-elements.
  • Versions 15 and later
    store any complex value: structures, classes, advanced types, arrays, associative arrays, queues, stacks and lists.
    New in version 15
    store any complex value: structures, classes, advanced types, arrays, associative arrays, queues, stacks and lists.
    store any complex value: structures, classes, advanced types, arrays, associative arrays, queues, stacks and lists.
  • handle the NULL value in WLanguage.
  • store interactions with ActiveX objects and Automation programming.
Versions 18 and later
Universal Windows 10 App This type of variable is now available in Windows Store apps mode.
New in version 18
Universal Windows 10 App This type of variable is now available in Windows Store apps mode.
Universal Windows 10 App This type of variable is now available in Windows Store apps mode.
Versions 21 and later
Universal Windows 10 App This type of variable is now available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This type of variable is now available in Universal Windows 10 App mode.
Universal Windows 10 App This type of variable is now available in Universal Windows 10 App mode.
Versions 22 and later
Java This type of variable is now available for Java applications.
New in version 22
Java This type of variable is now available for Java applications.
Java This type of variable is now available for Java applications.
Example
nValue is Variant = 10
nValue = EDT_Edit1
nValue = Customer.Name
Syntax

Declaring and assigning a Variant type Hide the details

<Variable name> is Variant = <Value>

OR


 <Variable Name> is Variant
 <Variable name> = <Value>
<Variable name>:
Name of the variable to declare.
<Value>:
Value that will be assigned to the variable. One of the following values can be assigned to a Variant variable:
  • any literal value,
  • the content of a variable,
  • the content of a simple control,
  • the content of an item.
Remarks

Variant type and NULL

To specify that a Variant variable contains no value, use the NULL constant.
Remarks:
  • for a Variant type, NULL means "Not assigned".
  • for a Numeric type, NULL means "equal to 0".
nVal is int
IF vVal = Null THEN ... // the test returns True because nVal=0
nVal = 5
IF vVal = Null THEN ... // the test returns False because nVal=5
vVal is Variant
IF vVal = Null THEN ... // returns True because the variant is not assigned
vVal = 0
IF vVal = Null THEN ... // returns False because the variant is assigned  
// with an integer whose value is 0
vVal = 5
IF vVal = Null THEN ... // returns False because the variant is assigned
// with an integer whose value is 5
vVal is Variant
vVal = Null
IF vVal = 0 THEN ... // returns True because a non-assigned variable
// and a value cannot be compared, True is returned by convention

Type of a variant

The type of a variant is returned by Type. Type is used to get the type of value stored in the variable.
Remarks:
  • VariantConvert is used to convert the type of value stored in a Variant variable.
  • TypeVar is used to find out the type of variable.
vVal is Variant
TypeVar(vVal)  // returns the number of the variant type
vVal.Type     // returns the type of the value stored in the variant

Class property on variants

Class is used to obtain the name of the class used if the variant corresponds to a class.
Versions 19 and later

Named sub-elements

You can directly use members without any declaration on a Variant variable.
When assigning a member, if the member does not exist, it is automatically created ; if the member already exits, it is modified.
Example:
Person is Variant
Person.LastName = "MOORE"
Person.FirstName = "Vince"
When reading a member, if the member does not exist, it is not created. To check if a member exists, use ..Exist.
Example:
Person is Variant
IF NOT Personn.Name..Exist THEN
Error("The name was not specified")
END
If the member does not exist, the returned value is Null. Several methods can be used to explicitly test the Null value:
  • use ..Value.
    Example:
    Element is Variant
    IF Element.MemberNotFound..Value = Null THEN
    ...
    END
  • Versions 23 and later
    test the Null value directly (available from version 230042). Example: test the Null value directly. Example:
    Element is Variant
    IF Element.MemberNotFound = Null THEN
    ...
    END
    New in version 23
    test the Null value directly (available from version 230042). Example: test the Null value directly. Example:
    Element is Variant
    IF Element.MemberNotFound = Null THEN
    ...
    END
    test the Null value directly (available from version 230042). Example: test the Null value directly. Example:
    Element is Variant
    IF Element.MemberNotFound = Null THEN
    ...
    END
The named sub-elements can be handled by the following properties:
ExistReturns:
  • True if the element exists,
  • False if the element does not exist. The element is not created.
NameElement name
TypeType of element (same values as TypeVar).
ValueElement value.

Using Member on Variant variables allows you to get the array of named elements. This array can be handled by FOR EACH, the Count property, the [ ] operator, ...
It is also possible to delete an element. Example:
o is JSON
o.m = 1
o.n = 2
Trace(o)
 
x is Variant = o
Delete(x.Member, 1)
Trace(x) // The member has been deleted.
New in version 19

Named sub-elements

You can directly use members without any declaration on a Variant variable.
When assigning a member, if the member does not exist, it is automatically created ; if the member already exits, it is modified.
Example:
Person is Variant
Person.LastName = "MOORE"
Person.FirstName = "Vince"
When reading a member, if the member does not exist, it is not created. To check if a member exists, use ..Exist.
Example:
Person is Variant
IF NOT Personn.Name..Exist THEN
Error("The name was not specified")
END
If the member does not exist, the returned value is Null. Several methods can be used to explicitly test the Null value:
  • use ..Value.
    Example:
    Element is Variant
    IF Element.MemberNotFound..Value = Null THEN
    ...
    END
  • Versions 23 and later
    test the Null value directly (available from version 230042). Example: test the Null value directly. Example:
    Element is Variant
    IF Element.MemberNotFound = Null THEN
    ...
    END
    New in version 23
    test the Null value directly (available from version 230042). Example: test the Null value directly. Example:
    Element is Variant
    IF Element.MemberNotFound = Null THEN
    ...
    END
    test the Null value directly (available from version 230042). Example: test the Null value directly. Example:
    Element is Variant
    IF Element.MemberNotFound = Null THEN
    ...
    END
The named sub-elements can be handled by the following properties:
ExistReturns:
  • True if the element exists,
  • False if the element does not exist. The element is not created.
NameElement name
TypeType of element (same values as TypeVar).
ValueElement value.

Using Member on Variant variables allows you to get the array of named elements. This array can be handled by FOR EACH, the Count property, the [ ] operator, ...
It is also possible to delete an element. Example:
o is JSON
o.m = 1
o.n = 2
Trace(o)
 
x is Variant = o
Delete(x.Member, 1)
Trace(x) // The member has been deleted.

Named sub-elements

You can directly use members without any declaration on a Variant variable.
When assigning a member, if the member does not exist, it is automatically created ; if the member already exits, it is modified.
Example:
Person is Variant
Person.LastName = "MOORE"
Person.FirstName = "Vince"
When reading a member, if the member does not exist, it is not created. To check if a member exists, use ..Exist.
Example:
Person is Variant
IF NOT Personn.Name..Exist THEN
Error("The name was not specified")
END
If the member does not exist, the returned value is Null. Several methods can be used to explicitly test the Null value:
  • use ..Value.
    Example:
    Element is Variant
    IF Element.MemberNotFound..Value = Null THEN
    ...
    END
  • Versions 23 and later
    test the Null value directly (available from version 230042). Example: test the Null value directly. Example:
    Element is Variant
    IF Element.MemberNotFound = Null THEN
    ...
    END
    New in version 23
    test the Null value directly (available from version 230042). Example: test the Null value directly. Example:
    Element is Variant
    IF Element.MemberNotFound = Null THEN
    ...
    END
    test the Null value directly (available from version 230042). Example: test the Null value directly. Example:
    Element is Variant
    IF Element.MemberNotFound = Null THEN
    ...
    END
The named sub-elements can be handled by the following properties:
ExistReturns:
  • True if the element exists,
  • False if the element does not exist. The element is not created.
NameElement name
TypeType of element (same values as TypeVar).
ValueElement value.

Using Member on Variant variables allows you to get the array of named elements. This array can be handled by FOR EACH, the Count property, the [ ] operator, ...
It is also possible to delete an element. Example:
o is JSON
o.m = 1
o.n = 2
Trace(o)
 
x is Variant = o
Delete(x.Member, 1)
Trace(x) // The member has been deleted.
Versions 19 and later

Indexed sub-elements

The Variant variable can be directly used as an array of variants. Using the [ ] operator automatically creates the array.
Example:
Days is Variant
Days[1] = "Monday"
Days[2] = "Tuesday"
Days[3] = "Wednesday"
Days[4] = "Thursday"
Days[5] = "Friday"
Days[6] = "Saturday"
Days[7] = "Sunday"
The array operations can be directly performed on the Variant variable: FOR EACH, Count, [ ] operator, ...
New in version 19

Indexed sub-elements

The Variant variable can be directly used as an array of variants. Using the [ ] operator automatically creates the array.
Example:
Days is Variant
Days[1] = "Monday"
Days[2] = "Tuesday"
Days[3] = "Wednesday"
Days[4] = "Thursday"
Days[5] = "Friday"
Days[6] = "Saturday"
Days[7] = "Sunday"
The array operations can be directly performed on the Variant variable: FOR EACH, Count, [ ] operator, ...

Indexed sub-elements

The Variant variable can be directly used as an array of variants. Using the [ ] operator automatically creates the array.
Example:
Days is Variant
Days[1] = "Monday"
Days[2] = "Tuesday"
Days[3] = "Wednesday"
Days[4] = "Thursday"
Days[5] = "Friday"
Days[6] = "Saturday"
Days[7] = "Sunday"
The array operations can be directly performed on the Variant variable: FOR EACH, Count, [ ] operator, ...
Versions 19 and later

Nesting named and indexed sub-elements

Since the named and indexed sub-elements are of type Variant, they can be nested recursively.
Example:
Library is Variant
Library.Book[1].Title = "Mrs Dalloway"
Library.Book[1].Author = "Virginia Woolf"
Library.Book[2].Title = "Oliver Twist"
Library.Book[2].Author = "Charles Dickens"
New in version 19

Nesting named and indexed sub-elements

Since the named and indexed sub-elements are of type Variant, they can be nested recursively.
Example:
Library is Variant
Library.Book[1].Title = "Mrs Dalloway"
Library.Book[1].Author = "Virginia Woolf"
Library.Book[2].Title = "Oliver Twist"
Library.Book[2].Author = "Charles Dickens"

Nesting named and indexed sub-elements

Since the named and indexed sub-elements are of type Variant, they can be nested recursively.
Example:
Library is Variant
Library.Book[1].Title = "Mrs Dalloway"
Library.Book[1].Author = "Virginia Woolf"
Library.Book[2].Title = "Oliver Twist"
Library.Book[2].Author = "Charles Dickens"
Minimum version required
  • Version 14
This page is also available for…
Comments
Click [Add] to post a comment