Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Experts*
Posted

You cant initialize the whole array as new, you have to do that for each member of the array, like this:

Public newline(0) As New LineStuff

In the example you initialize the first member of the array which is at zero.

  • *Experts*
Posted
Actually, that wouldn't work either. You need to set them to new separately.
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

  • *Experts*
Posted (edited)

SOrry, I typed in the wrong thing

 

Dim lines(somenumber) as LineStuff
lines(0) = new linestuff

 

[edit]typos..:) [/edit]

Edited by mutant

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...