PDA

View Full Version : Question for the file(s) in the listbox



Ann_BBO
07-26-2007, 08:00 PM
Actually, i am not sure that the explanation of the below VBA
For i = LBound(sFiles) To UBound(sFiles)
sFileShort = Right(sFiles(i), Len(sFiles(i)) - InStrRev(sFiles(i), "\"))
With Me.ListBox1
.AddItem sFileShort
.List(.ListCount - 1, 1) = sFiles(i)
End With
especially, i don;t know this command much
.List(.ListCount - 1, 1) = sFiles(i)


Is it redundancy for the above vba command since i had deleted the whole command. No effect for the basic operation. But i want to learn it this actual meanings

Thanks

Ann_BBO
07-26-2007, 09:42 PM
The next question is
With Me.ListBox1
For k = .ListCount - 1 To 0 Step -1
If .Selected(k) Then
.RemoveItem k
End If
Next k
End With
especially, this vba command
For k = .ListCount - 1 To 0 Step -1
I want to understand it

Bob Phillips
07-27-2007, 01:18 AM
Actually, i am not sure that the explanation of the below VBA
For i = LBound(sFiles) To UBound(sFiles)
sFileShort = Right(sFiles(i), Len(sFiles(i)) - InStrRev(sFiles(i), "\"))
With Me.ListBox1
.AddItem sFileShort
.List(.ListCount - 1, 1) = sFiles(i)
End With
especially, i don;t know this command much
.List(.ListCount - 1, 1) = sFiles(i)


Is it redundancy for the above vba command since i had deleted the whole command. No effect for the basic operation. But i want to learn it this actual meanings

Thanks

It is not redundant, you are just not seeing the effects because you have the columncount of the listbox set to 1.

This code is loading a value into column 2 (,1 because it is zero based) of the current row (.ListCount -1, it is also zero based) of the List in the listbox.

If you change the column count to 2 you will see it.



For i = LBound(sFiles) To UBound(sFiles)
sFileShort = Right(sFiles(i), Len(sFiles(i)) - InStrRev(sFiles(i), "\"))
With Me.ListBox1
.ColumnCount = 2
.AddItem sFileShort
.List(.ListCount - 1, 1) = sFiles(i)
End With

Bob Phillips
07-27-2007, 01:20 AM
The next question is
With Me.ListBox1
For k = .ListCount - 1 To 0 Step -1
If .Selected(k) Then
.RemoveItem k
End If
Next k
End With
especially, this vba command
For k = .ListCount - 1 To 0 Step -1
I want to understand it

It stepping through the list in the listbox backwards ( .ListCount - 1 To 0 Step -1), and if the item is selected (If .Selected(k) Then), it removes it ( .RemoveItem k).