ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage syntax / 
  • Variant type and NULL
  • Type of a variant
  • Class property on variants
  • Named subelements
  • Indexed subelements
  • Nesting named and indexed subelements
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
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.
  • store named or indexed subelements.
  • 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.
Example
nValeur is Variant = 10 
nValeur = SAI_Saisie1 
nValeur = Client.Nom
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 nVal = Null THEN ... // le test renvoie Vrai car nVal=0
nVal = 5
IF nVal = Null THEN ... // le test renvoie Faux car nVal=5
vVal is Variant
IF vVal = Null THEN ... // renvoie Vrai car le variant n'est pas affecté
vVal = 0
IF vVal = Null THEN ... // renvoie Faux car le variant est affecté
// avec un entier de valeur 0
vVal = 5
IF vVal = Null THEN ... // renvoie Faux car le variant est affecté
// avec un entier de valeur 5
vVal is Variant
vVal = Null
IF vVal = 0 THEN ... // renvoie Vrai car une variable non affectée
// et une valeur ne sont pas comparables, Vrai est retourné par convention

Type of a variant

The type of a variant is returned by the Type property. The Type property gets 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 determine the type of variable (Variant type for a Variant variable).
vVal is Variant
TypeVar(vVal)  // renvoie le numéro du type variant
vVal..Type     // renvoie le type de la valeur stockée dans le variant

Class property on variants

Class is used to obtain the name of the class used if the variant corresponds to a class.

Named subelements

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:
Personne is Variant
Personne.Nom = "DUPONT"
Personne.Prénom = "Michel"
When reading a member, if the member does not exist, it is not created. You can check if a member exists using the Exist property.
Example:
Personne is Variant
IF NOT Personne.Nom..Exist THEN
Error("Le nom n'a pas été renseigné")
END
If the member does not exist, the returned value is Null. Multiple methods can be used to test the Null value:
  • use the Value property.
    Example:
    Elément is Variant
    IF Elément.MembreInexistant..Value = Null THEN
    ...
    END
  • test the Null value directly. Example:
    Elément is Variant
    IF Elément.MembreInexistant = 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 the Member property on Variant variables allows you to get the array of named elements. This array can be handled by FOR EACH, the Occurrence 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) // Le membre m a été supprimé.

Indexed subelements

The Variant variable can be directly used as an array of variants. Using the [ ] operator automatically creates the array.
Example:
Jours is Variant
Jours[1] = "lundi"
Jours[2] = "mardi"
Jours[3] = "mercredi"
Jours[4] = "jeudi"
Jours[5] = "vendredi"
Jours[6] = "samedi"
Jours[7] = "dimanche"
The array operations can be directly performed on the Variant variable: FOR EACH, Occurrence, [ ] operator, etc.

Nesting named and indexed subelements

Since the named and indexed sub-elements are of type Variant, they can be nested recursively.
Example:
Bibliotheque is Variant
Bibliotheque.Livre[1].Titre = "Les trois mousquetaires"
Bibliotheque.Livre[1].Auteur = "Alexandre Dumas"
Bibliotheque.Livre[2].Titre = "Les misérables"
Bibliotheque.Livre[2].Auteur = "Victor Hugo"
Minimum version required
  • Version 14
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 03/06/2024

Send a report | Local help