Link to home
Start Free TrialLog in
Avatar of Miss leah
Miss leahFlag for Israel

asked on

Operator '=' is not defined for type 'DBNull' and type 'Integer'

I am migrating vb6 project to vb.net. there are variant type arrays that I migrated as object types.
having this code line I get the error: Operator '=' is not defined for type 'DBNull' and type 'Integer'
                    If arrY(13, X) = gloT And (CBool(arrY(18, X)) = True Or (CBool(arrY(18, X)) = False And arr(65, X) = 100)) Then  
arr(65, X) has a null value . If I cannt initialize it to 0 how can I avoid the exception?
Avatar of Peter Hutchison
Peter Hutchison
Flag of United Kingdom of Great Britain and Northern Ireland image

To be honest, it would be best practise try to avoid using Object when migrating to VB.Net and you should always initialise arrays before using them, as you cannot guarantee what is in the values before using them.

e.g.
Dim arr(100,100) as Integer
Dim r as integer, c as integer

For r=1  to 100
For c=1 to 100
arr(r,c)=0
Next c
Next r

Alternatively, you could modify the values in the condition:

f arrY(13, X) = gloT And (CBool(arrY(18, X)) = True Or (CBool(arrY(18, X)) = False And (arr(65, X) + 0) = 100)) Then
Avatar of Miss leah

ASKER

Thank you,  I initialize the array but the vb6 code is using the null value after the initialize to 0. I assume there is a significance to that. I tried to use +0 method you mentioned but still getting the error: Operator '+' is not defined for type 'DBNull' and type 'Integer'
How do you set up the values from the array, do you read them from a database or a file.

I find that, you should read values as strings (add a empty string to covert from Null to a value) and then try to convert to a integer value (using VAL or CInt or whatever) before assigning to the array.
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank you !
Not a problem Miss leah, glad to help.