kevinheeney Posted July 14, 2003 Posted July 14, 2003 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 Quote
*Experts* mutant Posted July 14, 2003 *Experts* Posted July 14, 2003 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. Quote
kevinheeney Posted July 14, 2003 Author Posted July 14, 2003 It is still saying that arrays cannot be declared with 'New'. Though I tried Public newline(0) As New LineStuff Kevin Heeney Quote
*Experts* Volte Posted July 14, 2003 *Experts* Posted July 14, 2003 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 Quote
*Experts* mutant Posted July 14, 2003 *Experts* Posted July 14, 2003 (edited) SOrry, I typed in the wrong thing Dim lines(somenumber) as LineStuff lines(0) = new linestuff [edit]typos..:) [/edit] Edited July 14, 2003 by mutant Quote
kevinheeney Posted July 14, 2003 Author Posted July 14, 2003 Thanks guys that worked. Kevin Heeney Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.