Check for uninitialised variants

mabl4367
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?
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?
0
Comments
-
Try to define variant variable and do not initialize it. Try to compare th variable with this one... ;-)0
-
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.0 -
-
FORMAT erros out if the variant is uninitialised and you can't catch the error by using the returnvalue0
-
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 booleanvar1 := 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."0 -
You can not format the variant if it is not initalised0
-
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."0 -
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)...0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions