Array Error

I

Ivan Weiss

Hey guys, I am getting this error:

An unhandled exception of type 'System.NullReferenceException' occurred
in microsoft.visualbasic.dll

Additional information: Object Variable or With block variable not set.

Here is my code

Private Sub butSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butSave.Click
Dim myDatabase As New Database(Me)
Dim myArray As Array

myArray(0) = txtCompany.Text
myArray(1) = txtFeeder.Text
myArray(2) = txtAddress1.Text
myArray(3) = txtAddress2.Text
myArray(4) = txtCity.Text
myArray(5) = txtState.Text
myArray(6) = txtZip.Text

myDatabase.insertData("Customers", myArray)
End Sub

Any ideas why I am getting this error?

-Ivan
 
C

Cor

Hi Ivan,

Two things,

put in top of your program "Option Strict On" then you see the errors
use the arraylist instead of the array,

I expect looking to the rest of your code that you than can find the rest
yourself
(I think it is not one error, the next will be if you solve just one).

I hope this helps a little bit?

Cor
 
A

Armin Zingler

Ivan Weiss said:
Hey guys, I am getting this error:

An unhandled exception of type 'System.NullReferenceException'
occurred in microsoft.visualbasic.dll

Additional information: Object Variable or With block variable not
set.

Here is my code

Private Sub butSave_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles butSave.Click
Dim myDatabase As New Database(Me)
Dim myArray As Array

myArray(0) = txtCompany.Text
myArray(1) = txtFeeder.Text
myArray(2) = txtAddress1.Text
myArray(3) = txtAddress2.Text
myArray(4) = txtCity.Text
myArray(5) = txtState.Text
myArray(6) = txtZip.Text

myDatabase.insertData("Customers", myArray)
End Sub

Any ideas why I am getting this error?

You did not create an array. I'd declare it this way:

Redim myArray(6) 'instead of myArray as Array


If you declare it myArray as Array, you have to
1. call Array.CreateInstance to create the array
2. Use myArray.Setvalue to change the content
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top