Line Problems

MushMann
03-17-2003, 07:06 AM
I'm attempting to make a very simplistic cad-like program to aid me in designing lighting interfaces for my school's auditorium. I'm sure that I'll be posting more later on with more problems I run into, but for now I have just this one - I attempt to create a new line after a used clicks on a command button, by using the coordinates of two MouseDowns. The only problem I'm running into is that I get an Error 91 - Object Variable or With Variable Not Set - whenever I go to create the line. Here's what I have:



Dim XX1 As Integer
Dim XX2 As Integer
Dim YY1 As Integer
Dim YY2 As Integer
Dim LineX(100) As Line
Dim U As Integer 'line count

Option Explicit

Private Sub Command1_Click()

MsgBox "Click on Two Coordinates"

End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

If (XX1 = 0) And (YY1 = 0) Then
XX1 = X
YY1 = Y
ElseIf (XX2 = 0) And (YY2 = 0) Then
XX2 = X
YY2 = Y
Call DrawLine
End If

End Sub

Public Sub DrawLine()

If ((XX1 = 0) And (YY1 = 0)) Or ((XX2 = 0) And (YY2 = 0)) Then
Exit Sub
Else
LineX(U).X1 = XX1
LineX(U).Y1 = YY1
LineX(U).X2 = XX2
LineX(U).Y2 = YY2
U = U + 1

End If

End Sub


Also, can anyone give me a simple tip how to dim an array to be sizeless? That is, to have it change each time to accomodate the growing number of lines? I have it set to have a max of 100 lines, and then to have it redim each time, but that seems a little... inefficient? I don't know. Any helps is welcome.
:confused:
Thanks

SnakeChomp
03-17-2003, 08:24 AM
Also, can anyone give me a simple tip how to dim an array to be sizeless? That is, to have it change each time to accomodate the growing number of lines? I have it set to have a max of 100 lines, and then to have it redim each time, but that seems a little... inefficient? I don't know. Any helps is welcome.
:confused:
Thanks

Dim Array() as Long
Redim Preserve Array(100) as long
Redim Preserve Array(Ubound(array)+1)
Redim Preserve Array(AVariable)

What line of your code produces the error?

Squirm
03-17-2003, 08:28 AM
Remove your declaration of LineX from the top of your form code, add one line control to your form, name it LineX and give it an Index property of 0.

You then just Load new lines as needed:


If ((XX1 = 0) And (YY1 = 0)) Or ((XX2 = 0) And (YY2 = 0)) Then
Exit Sub
Else
If U Then Load LineX(U) '<-- new line
LineX(U).X1 = XX1
LineX(U).Y1 = YY1
LineX(U).X2 = XX2
LineX(U).Y2 = YY2
U = U + 1

End If

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum