Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Error "System.OutOfMemoryException" when using Array on Child Form

Status
Not open for further replies.

canary

Programmer
Mar 14, 2001
25
HK
In VB.NET I have a form that stores data into an array while it is loading. The form is a child form. When I click on the toolbar button to open it I keep getting the following error:

An unhandled exception of type 'System.OutOfMemoryException' occurred in system.windows.forms.dll

Additional information: Error creating window handle.

If I take out the call to the array the child form loads ok. The code for the array is as follows:

i = 0
While Conn.PipeReader.Read
Product(i) = Conn.PipeReader.GetString(0)
i = i + 1
End While
Conn.PipeReader.Close()

The variable product is set at Object.

Could someone please tell me if there is a work around for the memory exception?
 
Where are you declaring and instantiating your form?

Where are you declaring your array and what size do you set it to?

DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb

-----------------------------------

If you can't explain it simply, you don't understand it well enough.
- A. Einstein





 
DocNetDoc,
Thanks for the reply. However, I forgot to post the solution! I had originally declared the array as "Friend Product() as Object" and to set the size of the array I used the ReDim statement. Using this way always brought me the memory exception error. What I did was set the Product() as Product(1) as a starting point and from there is seemed to have worked, never got this problem again.

Do I presume when I create an array like this I must include a number in it?

Thanks

Canary
 
Or Even better to hold objects. You can use the new ArrayList.

Dim myArrayList as New ArrayList

myArrayList.Add(myObject)


After you are done with it call
myArrayList.TrimToSize

The ArrayList Dynamicly resizes itself. No more need to use the Redim statement and you will never get the index out of bounds error.

Here is a quick tutorial on it if you want to check it out.






DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb

-----------------------------------

If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
DotNetDoc,
Many thanks for the tip and link. Thats a new one for me. I'll give that one a shot too.

Thanks

Canary
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top