Try changing your for loop from a reverse count to a normal count:
Private Sub Form_Load()
File1.Path = "C:\Images"
File1.Refresh
If File1.ListCount > 0 Then
For i = 0 To File1.ListCount - 1
Combo1.AddItem File1.List(i)
Next
End If
End Sub
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
Technically, you could have "gone the other way", but when doing a for loop, it's default behavior is to count up. So, behind the scenes there is a test condition being applied to the for loop.... for example: for I = 0 to 9 is going to say "ok, is I less than 9" if the answer is yes, then do the stuff between for and next. Then, it's going to Add 1 to I, and say "ok, I is 1 [then 2 and 3, etc, etc], is it less than 9?" It will continue this process until I becomes 9. When you say: for I = 10 to 1 , the programming language isn't going to change it's behavior, just because you decided to change the numbers.... so, dutifully, it says: "ok, I is 10 right off the bat, is I (10) less than 1 (or -1 or whatever)". Naturally, 10 is not less than 1 or negative 1.... or even 9, so the for loop never actually even runs once. It just compares, sees that 10 is not less than -1, and says screw it, and moves on.
You can change the behavior of the for loop, however, to decrement instead of increment (to count down instead of up) but be advised, that this is not the standard way of doing things. Meaning, if you ever share your code with someone, or you end up working in a team setting, someone might have a more difficult time understanding your code, because you aren't doing things normally. However, you could modify your statement to run backward with something like this:
For i = File1.ListCount - 1 To 0 Step -1
Combo1.AddItem File1.List(i)
Next
The key here, is the "step" keyword. The step keyword tells the for loop what kind of behavior it should apply when dealing with the counter variable. You could do a for loop with a step 2, which would actually only execute code on every other iteration....
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215