Im trying to create a listbox in which you can slide elements of the contents up and down the list with you mouse. The code works however if you click the mouse button quickly an error appears, caused on the line - llt1.AddItem Text2.Text, List1.ListIndex -
Err no 5 invalid procedure or argument – could some one explain what is happening, or arrive at some better code.
The code is a follows
Private Sub Form_Load()
For i = 0 To 5
List1.AddItem "number " & i
Next i
End Sub
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
a = List1.ListIndex
Text1.Text = List1.ListIndex
Text2.Text = List1.Text
End Sub
Private Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error GoTo Simple_Error
If List1.ListIndex = -1 Then
Exit Sub
End If
List1.RemoveItem Text1.Text
List1.AddItem Text2.Text, List1.ListIndex - 1
Text1.Text = vbNull
Text2.Text = vbNull
Exit Sub
Simple_Exit:
Exit Sub
Simple_Error:
MsgBox "You raised error: " & _
Err & ", " & Err.Description & _
vbCrLf & _
"At program location: " & _
Err.Source
Resume Simple_Exit
End Sub
Thanks for your time Todd
Err no 5 invalid procedure or argument – could some one explain what is happening, or arrive at some better code.
The code is a follows
Private Sub Form_Load()
For i = 0 To 5
List1.AddItem "number " & i
Next i
End Sub
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
a = List1.ListIndex
Text1.Text = List1.ListIndex
Text2.Text = List1.Text
End Sub
Private Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error GoTo Simple_Error
If List1.ListIndex = -1 Then
Exit Sub
End If
List1.RemoveItem Text1.Text
List1.AddItem Text2.Text, List1.ListIndex - 1
Text1.Text = vbNull
Text2.Text = vbNull
Exit Sub
Simple_Exit:
Exit Sub
Simple_Error:
MsgBox "You raised error: " & _
Err & ", " & Err.Description & _
vbCrLf & _
"At program location: " & _
Err.Source
Resume Simple_Exit
End Sub
Thanks for your time Todd