Check for uninitialised variants

mabl4367mabl4367 Member Posts: 143
Hello experts!

Is there a way to check if a variable of data type Variant is uninitialised?

At least there seams to be a value that is interpreted by navision as uninitialised. If I use an uninitialised variant as a sourcexpression for a textbox the textbox will display the text "<uninitialised>".

I want to be able to check this in code. For automation data type I can use ISCLEAR but that doesn't work for variants.

Any ideas?

Comments

  • kinekine Member Posts: 12,562
    Try to define variant variable and do not initialize it. Try to compare th variable with this one... ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • mabl4367mabl4367 Member Posts: 143
    I did that but the comparison operator "=" would not accept it. I got an error when the variant I tested was previously assigned a text.

    Perhaps there is a way of catching the error so it is not displayed and execution is not stoped.
  • kinekine Member Posts: 12,562
    What about using FORMAT(Variable)=''?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • mabl4367mabl4367 Member Posts: 143
    FORMAT erros out if the variant is uninitialised and you can't catch the error by using the returnvalue
  • klavinklavin Member Posts: 117
    You could build a function return type boolean. Give it a shot see if it works for you.

    var1 type variant
    var2 type variant
    ok type boolean
    var1 := FALSE;
    ok := variantactive(var1);
    MESSAGE(FORMAT(ok));
    ok := variantactive(var2);
    MESSAGE(FORMAT(ok));
    

    Function:
    VariantActive(pvariant : Variant) : boolean
    IF STRLEN(FORMAT(pvariant)) > 0 THEN
       EXIT(TRUE);
    


    EDIT:
    You could always check to see if the type of text, allow that to be zero length by checking the pvariant.ISTEXT beforehand since you may allow that blank... just an idea
    -Lavin
    "Profanity is the one language all programmers know best."
  • mabl4367mabl4367 Member Posts: 143
    You can not format the variant if it is not initalised
  • klavinklavin Member Posts: 117
    Did you try my example? It works because it seems the passed Variant is initialized no matter what.
    -Lavin
    "Profanity is the one language all programmers know best."
  • TiniusTinius Member Posts: 8
    looks like that when variant is passed to some function as a parameter it allways gets initialised, and the FORMAT(var) works fine..
    But determining if variant is empty by string length it contains is not quite acurate.. The variant might be initialised, and containing an empty string - but this function would treat that variant as being empty(uninitialised)...
Sign In or Register to comment.