How to question

Hello to All:

How can I fix an error without using a try and excepiton block? Below is my code and the lstProduct line is causing an "argumentNullExceptionWasUnhandeled" error.

Is there a way to fix that. Any help welcome

Loop

Dim intCountAsInteger

For intCount = 0To products.Length - 1

lstProduct.Items.Add(products(intCount).strName)

Next

[664 byte] By [Recency] at [2007-12-26]
# 1
Maybe you could check that products.length is not zero before you start the for-next loop.
Also, what is the type of lstProduct and the products array?
MartinCowen at 2007-9-4 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 2
Thank you for the help. I have solved the error
Recency at 2007-9-4 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 3

I'd use something like the following


For Each s As String In products
If s IsNot Nothing Then
If products(intCount).strName.trim.length > 0 Then lstProduct.Items.Add(s.strName)
End If
Next

This way I'm simply iterating through the products collection, verifying its set to something and that the strname has something in it

Using For Each construct prevents a number of index problems with For Next loop using indexes.

spotty at 2007-9-4 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...