Avatar of Miss leah
Miss leah
Flag 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?
Visual Basic.NET

Avatar of undefined
Last Comment
Fernando Soto

8/22/2022 - Mon
Peter Hutchison

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
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'
Peter Hutchison

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.
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
Fernando Soto

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Miss leah

ASKER
thank you !
Fernando Soto

Not a problem Miss leah, glad to help.