Array of a class???

kevinheeney

Newcomer
Joined
Jun 24, 2003
Messages
20
I have set up a class called - linestuff -
It is used for calculating the midpoint,slope ect. of a line.
I am also using it to save the X1,y1,x2,y2 of that line.

What I hope to do is have a user draw a line and then have it set up a new object and then save the coordinates

This is working for one line but Arrays cannot be declared with new.

Public newline() As New LineStuff 'LineStuff Being the Class

And then everytime they draw a line to have it make newline(n).x1 = e.x1 or something like that and then have n=n+1 for each new line. There has to be a way to dynamically call objects. What am I doing wrong?

I no that this is scrambled, but I had trouble describing my problem.


Kevin Heeney
VB.NET
 
You cant initialize the whole array as new, you have to do that for each member of the array, like this:
Visual Basic:
Public newline(0) As New LineStuff
In the example you initialize the first member of the array which is at zero.
 
It is still saying that arrays cannot be declared with 'New'. Though I tried Public newline(0) As New LineStuff




Kevin Heeney
 
Actually, that wouldn't work either. You need to set them to new separately.
Visual Basic:
Dim newline(25) As LineStuff 'don't create instance here
Dim i As Integer

'note: For Each..Next will not work here
For i = 0 To newline.GetUpperBound(0)
  newline(i) = New LineStuff()
Next
 
SOrry, I typed in the wrong thing

Visual Basic:
Dim lines(somenumber) as LineStuff
lines(0) = new linestuff

[edit]typos..:) [/edit]
 
Last edited:
Back
Top