|
-
Jul 12th, 2005, 12:46 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Deleteing vb lines that have an array.
Hello,
I am using the code below to add vb.Lines to my form.
My question is how do I delete the lines?
I tried me.Controls.Remove q_lines but that doesn't delete anymore then one line.
So if the user created 2 or even 10 lines how would I delete them?
Thank you and have a great!
Stilekid007
VB Code:
Private q_InDrawMode As Boolean
Private q_ActivateDrawmode As Boolean
Private q_Lines As Line
Private Sub Command1_Click()
q_ActivateDrawmode = True
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static LineNumber As Long
LineNumber = LineNumber + 1
If q_ActivateDrawmode = True Then
'create a new line and initialise it at the current mouse pointer
Set q_Lines = Me.Controls.Add("VB.Line", "Line" & CStr(LineNumber), Form1)
q_Lines.X1 = X
q_Lines.X2 = X
q_Lines.Y1 = Y
q_Lines.Y2 = Y
q_Lines.Visible = True
q_InDrawMode = True
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If q_InDrawMode Then
'move the end point of the line
q_Lines.X2 = X
q_Lines.Y2 = Y
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
q_InDrawMode = False
q_ActivateDrawmode = False
End Sub
 Originally Posted by stilekid007
-
Jul 12th, 2005, 01:15 PM
#2
Re: Deleteing vb lines that have an array.
You need to enumerate the Controls collection and find the instances of the Line control you want to remove, i.e.
VB Code:
Private Sub Command2_Click()
Dim oControl As Control
Dim colLines As New Collection
' Create a collection of the Line controls to delete
For Each oControl In Me.Controls
If TypeOf oControl Is Line And Left(oControl.Name, 4) = "Line" Then
colLines.Add oControl
End If
Next
' Enumerate the collection of lines and remove them
For Each oControl In colLines
Me.Controls.Remove oControl
Next
End Sub
Regards,
- Aaron.
-
Jul 12th, 2005, 01:26 PM
#3
Re: Deleteing vb lines that have an array.
another way is to put the variable Linenumber and the top of your code instead of using a static so you could do this
VB Code:
Dim i As Integer
For i = 1 To LineNumber
Me.Controls.Remove "Line" & i
Next i
LineNumber = 0
casey.
-
Jul 12th, 2005, 01:56 PM
#4
Thread Starter
Hyperactive Member
Re: Deleteing vb lines that have an array.
HMMMMMM! For some wierd reason niether of those suggestion codes worked! Did you both try your codes?
I appreciate your time and help!
Stilekid007
 Originally Posted by stilekid007
-
Jul 12th, 2005, 02:03 PM
#5
Re: Deleteing vb lines that have an array.
Yes, my code worked fine when I used it against the example code you posted.
Regards,
- Aaron.
-
Jul 12th, 2005, 02:04 PM
#6
Re: Deleteing vb lines that have an array.
i did test it but i forgot to say you would also need to move the line
LineNumber = LineNumber + 1
it needs to be within the if statement
If q_ActivateDrawmode = True Then
LineNumber = LineNumber + 1
casey.
-
Jul 12th, 2005, 02:35 PM
#7
Thread Starter
Hyperactive Member
Re: Deleteing vb lines that have an array.
Hello,
Thank you for your responses!
Aaron - Your code worked great! But with your code, if I change the name of my Line from "Line" to "ParLine" then how would I delete it?
Example:
Instead of creating the Line with this code:
VB Code:
Set q_Lines = Me.Controls.Add("VB.Line", "Line" & CStr(LineNumber), Form1)
It would be:
VB Code:
Set q_Lines = Me.Controls.Add("VB.Line", "ParLine" & CStr(ParLineNumber), Form1)
How would this change the code you provded?
Thank you so much and have a great day!
Stilekid007
 Originally Posted by stilekid007
-
Jul 12th, 2005, 03:09 PM
#8
Re: Deleteing vb lines that have an array.
Just change the line that checks the name of the control to be whatever you want to use.
You could even remove the check altogether if you don't intend to use Lines for anything else.
VB Code:
...
If TypeOf oControl Is Line And Left(oControl.Name, 7) = "ParLine" Then
...
Regards,
- Aaron.
-
Jul 12th, 2005, 03:20 PM
#9
Thread Starter
Hyperactive Member
Re: Deleteing vb lines that have an array.
Ahh Yes! Thank you sir! I appreciate all your help!
Have a great day! 
Stilekid007
 Originally Posted by stilekid007
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|