Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem using graph objects in an array of windows forms

I'm developing a data display application in VB.Net, and my goal is to give users the option to display up to 8 different graphs simultaneously. I have created a simple form containing a WaveformGraph control and a button to close and delete the form. I am using an array as a container for the forms. I've had no problems displaying multiple forms and plotting data on the graphs; however, if I delete a form, the graphs on all forms with a higher index in the container array stop plotting. For instance, if there are 5 forms on the screen, and I remove the form with index 2, the graphs on forms with array index 3 and 4 no longer get updated while those with index 0 and 1 continue to function.

When a form is removed, its index in the array is set to Nothing. The method to update the graphs then checks each element in the array for a valid object and calls a method to update the graph on each object found:

For i = 1 to MAXPLOTS - 1
If Not plots(i).GetType is Nothing
plots(i).plotData(dataArray)
End If
Next

I have also tried using the CWGraph control, and the results are the same.

Has anyone encountered a similar problem? I'd appreciate any suggestions.

Thanks-
Dave Zeppettella
AFRL
0 Kudos
Message 1 of 3
(3,439 Views)
Is there an error or do the graphs just not work? If you are setting the index in the array to nothing, I would expect this line of code to throw a NullReferenceException since you're calling GetType on a null reference:


For i = 1 to MAXPLOTS - 1
If Not plots(i).GetType is Nothing
plots(i).plotData(dataArray)
End If
Next


If this is the case, I suggest using an ArrayList instead of an array, and call ArrayList.RemoveAt to remove the item from the list instead of setting the reference to null. This way you always have valid references, you don't have to worry about the comparison to Nothing, and you can use a For Each loop. If you still want to use an array, you should take the call to GetType out and just compare the value at the specified array index to Nothing.

If this is not the case, could you please post a small test project that reproduces this behavior? Thanks.

- Elton
0 Kudos
Message 2 of 3
(3,427 Views)
Elton -

Thanks for catching the GetType() bug.

The problem I was seeing is that the graphs would just stop updating. There was no error - they just stopped working. I ended up resolving this problem by changing my scheme a little to disallow a null reference in the middle of the array. Anytime an object was removed, the objects beyond the deleted element were moved down to fill the gap.

Even though this solved my plotting problem, it created others in the process. The ArrayList, as you suggested, would probably result in a cleaner solution and more maintainable code.

Thanks for your help -

Dave Z.
0 Kudos
Message 3 of 3
(3,419 Views)