B
BVH
Hi,
I'm currently having a problem with a vb6 project I once wrote that
needs to be converted to vb.NET.
The problem is as follows :
On a form I have a listbox and two commandbuttons. The 2 buttons act
as ‘up' and ‘down' buttons. The listbox contains some items that need
to be sorted "BY THE USER" (That's why I needed the 2 command buttons)
A little example :
Suppose the listbox contains the Items :
1
2
3
4
5
If a user selects the Item on position 3 and clicks the "Up"-button,
the item on position 3 is moved to position 2 and the item on position
2 is moved to position 3.
Exact the opposite is done when the user clicks the "down" button.
I hope I make myself clear and that my English is understandable.
Now, here comes the actual problem : this code worked fine for me in
VB6, but I'm unable to run the code properly with VB.NET.
I tried the upgrade wizard and rewrote the code, but apparently I must
be doing something wrong.
The VB6 code is posted below. If anyone can help me out, I'd really
appreciate it, cause I need this thing up and running very soon.
Thankz and Greetz,
BVH
Private Sub Up_Click()
On Error Resume Next
Dim lowId As Long, lowText As String
Dim upperId As Long, upperText As String
Dim i As Integer
For i = 0 To List1.ListCount - 1
If List1.Selected(i) Then
If i = 0 Then Exit For
lowId = List1.ItemData(i)
lowText = List1.List(i)
upperId = i - 1
List1.ListIndex = upperId
upperText = List1.Text
List1.List(upperId) = lowText
List1.ItemData(upperId) = lowId
List1.ItemData(i) = upperId
List1.List(i) = upperText
Exit For
End If
Next i
End Sub
Private Sub Down_Click()
On Error Resume Next
Dim lowId As Long, lowText As String
Dim upperId As Long, upperText As String
Dim i As Integer
For i = 0 To List1.ListCount + 1
If List1.Selected(i) Then
If i = List1.ListCount - 1 Then Exit For
lowId = List1.ItemData(i)
lowText = List1.List(i)
upperId = i + 1
List1.ListIndex = upperId
upperText = List1.Text
List1.List(upperId) = lowText
List1.ItemData(upperId) = lowId
List1.ItemData(i) = upperId
List1.List(i) = upperText
Exit For
End If
Next i
End Sub
I'm currently having a problem with a vb6 project I once wrote that
needs to be converted to vb.NET.
The problem is as follows :
On a form I have a listbox and two commandbuttons. The 2 buttons act
as ‘up' and ‘down' buttons. The listbox contains some items that need
to be sorted "BY THE USER" (That's why I needed the 2 command buttons)
A little example :
Suppose the listbox contains the Items :
1
2
3
4
5
If a user selects the Item on position 3 and clicks the "Up"-button,
the item on position 3 is moved to position 2 and the item on position
2 is moved to position 3.
Exact the opposite is done when the user clicks the "down" button.
I hope I make myself clear and that my English is understandable.
Now, here comes the actual problem : this code worked fine for me in
VB6, but I'm unable to run the code properly with VB.NET.
I tried the upgrade wizard and rewrote the code, but apparently I must
be doing something wrong.
The VB6 code is posted below. If anyone can help me out, I'd really
appreciate it, cause I need this thing up and running very soon.
Thankz and Greetz,
BVH
Private Sub Up_Click()
On Error Resume Next
Dim lowId As Long, lowText As String
Dim upperId As Long, upperText As String
Dim i As Integer
For i = 0 To List1.ListCount - 1
If List1.Selected(i) Then
If i = 0 Then Exit For
lowId = List1.ItemData(i)
lowText = List1.List(i)
upperId = i - 1
List1.ListIndex = upperId
upperText = List1.Text
List1.List(upperId) = lowText
List1.ItemData(upperId) = lowId
List1.ItemData(i) = upperId
List1.List(i) = upperText
Exit For
End If
Next i
End Sub
Private Sub Down_Click()
On Error Resume Next
Dim lowId As Long, lowText As String
Dim upperId As Long, upperText As String
Dim i As Integer
For i = 0 To List1.ListCount + 1
If List1.Selected(i) Then
If i = List1.ListCount - 1 Then Exit For
lowId = List1.ItemData(i)
lowText = List1.List(i)
upperId = i + 1
List1.ListIndex = upperId
upperText = List1.Text
List1.List(upperId) = lowText
List1.ItemData(upperId) = lowId
List1.ItemData(i) = upperId
List1.List(i) = upperText
Exit For
End If
Next i
End Sub