What happens when you use the Variant data type in Business Central and assign different values?

Quiz

  1. What type is inferred into the Variant variable when assigned a value of 'Variant'?
var
  v: Variant;
begin
  v := 'Variant';
end;

a) IsText = true

b) IsChar = true

c) IsCode = true

  1. What type is inferred into the Variant variable when assigned a value of 'CODE'?
var
  v: Variant;
begin
  v := 'CODE';
end;

a) IsText = true

b) IsChar = true

c) IsCode = true

  1. What type is inferred into the Variant variable when assigned a value of '1'?
var
  v: Variant;
begin
  v := '1';
end;

a) IsText = true

b) IsChar = true

c) IsCode = true

Answers

  1. a)
  2. a)
  3. c)

It is good to understand that in text based types - Char, Code and Text - the only possible inference will be Char and Text, because Code follows a different rule set that cannot be ensured by just providing a string literal to a variable, unlike Char and Text which only differ in size.