Solved

Loading images into imagelist in numerical order

Posted on 2006-06-12
4
229 Views
Last Modified: 2010-04-30
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
Comment
Question by:simononz
  • 2
4 Comments
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16892532

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
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16892564


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
 
LVL 26

Accepted Solution

by:
EDDYKT earned 250 total points
ID: 16893185
0
 

Author Comment

by:simononz
ID: 16900129
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question