[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

Loading images into imagelist in numerical order

Hi

I have a directory full of images:

1.bmp
2.bmp
3.bmp
...

What would be the easiest way to get them loaded into an imagelist in numerical order?

reading them in normally I get them in the following order:
1.bmp
11.bmp
12.bmp
...
2.bmp
20.bmp
..

etc

Should I just read in the file names into a list, sort them numerically then load them into the imagelist.

I also just cant use the lowest and highest as there could be breaks in the numbers, i.e. they wont be from just 1 - 100, they could be: 1 5 7 11 12 13 15 17 etc.

Working code would be nice,.

Cheers
Simon
0
simononz
Asked:
simononz
  • 2
1 Solution
 
Mark_FreeSoftwareCommented:

what you could do, is to point a filelist to the directory where they are stored.

then create a loop from the minimum value (i assume this is 1) to the max value

now look at every number if that one is available in the list
0
 
Mark_FreeSoftwareCommented:


and this is a working example:

you need one filelistbox (file1)
and two listboxes(list1 and list2)


Option Explicit

Private Sub Form_Load()
Dim n As Long
   File1.Path = App.Path          'change this to the bmp path!
   For n = 0 To File1.ListCount
      List1.AddItem LCase(File1.List(n))
   Next
   
   For n = 1 To 100               'change 100 to the max possible value!
      List1.Text = CStr(n) & ".bmp"
      If List1.Text <> "" Then   'this is not possible fith a filelist so i put it in a normal list
         List2.AddItem List1.Text
      End If
   Next
End Sub
0
 
simononzAuthor Commented:
Thanks for the pointers. Straight rip of the code from vbnet did the trick.

Now that you mention it I am sure I had seen it before.

Thanks for the input.

Simon
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now