We help IT Professionals succeed at work.

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

Miss leah
Miss leah asked
on
159 Views
Last Modified: 2018-11-27
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?
Comment
Watch Question

Peter HutchisonSenior Network Systems Specialist
CERTIFIED EXPERT

Commented:
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 leahdeveloper & project manager

Author

Commented:
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 HutchisonSenior Network Systems Specialist
CERTIFIED EXPERT

Commented:
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.
Retired
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Miss leahdeveloper & project manager

Author

Commented:
thank you !
Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
Not a problem Miss leah, glad to help.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions