How to select loaded pics in IDE

I have a lot of pics - png images loaded into the IDE. I have defined a PopUp inside a multi column Listbox that selects an image. When the Listbox row changes and provided the text of the cell is not blank I would like to use the value to get the image.

This value in the Listbox cell is text and an image well needs a picture.

Is there a way one can use this Listbox text which is actually the name of the pic resource to point to the actual pic loaded into the IDE?

Use a select case to translate the name to the corresponding picture object. Or you can load the images into a dictionary, keyed by name. But unfortunately, there is no direct method to get the pictures by name.

Actually there is… but only on OSX… All resources (images, xml, text files etc), are stored in the resource folder inside the application bundle. NEVER EVER (I repeat NEVER) write to this location (or any location inside the bundle for that matter), but at least until Apple changes something, there is nothing to stop you from reading from that location


you can also scan thru that folder item [f=App.ExecutableFile.Parent.parent.child(“Resources”)] to get the names of all items in your app.

Again… this works ONLY for OSX, and at the risk of repeating my self… READONLY.

Thank you both for your suggestions. I had already started on a Select case solution but was looking for another solution because there are many, many pics.

A dictionary sounds like a good way to go only because I need to use this on 3 platforms. I just found the Dictionary example. Never implemented a dictionary before and this may be a good time to check this out.

Here’s a bit of code that’ll autogenerate the dictionary build.

First save a copy of your project as XML. Then in an empty project add a pushbutton with this code, run it, select that XML file, then the autogenerated source is put on the clipboard. Finally go to your original project and paste into a new method. This is just a template to get all those picture names listed, it’ll need more code to finish a useful method.

[code]Sub Action()

dim f As FolderItem = GetOpenFolderItem("") //open a file and get all the picture name node
if f = nil then return
dim doc As new XmlDocument(f)
dim nl As XmlNodeList = doc.xql("//block[@type=‘Picture’]/ObjName")

dim names() As String //collect the names
for i As integer = 0 to nl.Length - 1
names.Append nl.Item(i).FirstChild.Value

dim r() As String //build source lines
r.Append “dim d As new Dictionary”
for i As integer = 0 to names.Ubound
r.Append “d.Value(”"" + names(i) + “”") = " + names(i)

dim cb As new Clipboard //store on clipboard
cb.SetText(Join(r, EndOfLine))

End Sub[/code]

resulting text looks like

dim d As new Dictionary d.Value("poodlesPic") = poodlesPic d.Value("lemonPic") = lemonPic

Will - thanks for the info - I see a place in my software development where I can use this.

I was in the process of creating a class of ‘Phone_Pics’ and assigned 2 properties Name = string and pic = picture and all had Public scope. Then inside a window I created a property of ‘myPhone_pics(2)’ type = ‘Phone_Pics’. The (2) was to enable 2 members Name and Public.

Then I attempted to make the following assignment

[code] ReDim myPhone_pics(3)

myPhone_pics(0).Name = “My Name of something”
myPhone_pics(0).pic = a_png_file

myPhone_pics(1).Name = “My Second Name of something”
myPhone_pics(3).pic = a_second_png_file

myPhone_pics(2).Name = “My Name of something”
myPhone_pics(2).pic = a_Third_png_file[/code]

Except the first attempt to assign a value errors. So the construct of the class or the assignment(s) or both are incorrect.

Any suggestions?

 ReDim myPhone_pics(-1)
dim temp as pic_class ' or what ever the class name is

temp=new pic_class
temp.Name =  "My Name of something"
temp..pic = a_png_file
myphone_pics.append temp 

// repeat as necessary

another way would be create a constructor for the class and use

myphone_pics.append new pic_class(“My name of something”,a_png_file)

You need to create a class instance before you access it.

ReDim myPhone_pics(3)

myPhone_pics(0) = new Phone_pics
myPhone_pics(0).Name =  "My Name of something"
 myPhone_pics(0).pic = a_png_file

myPhone_pics(1) = new Phone_pics
myPhone_pics(1).Name =  "My Second Name of something"
myPhone_pics(1).pic = a_second_png_file

myPhone_pics(2) = new Phone_pics
myPhone_pics(2).Name =  "My Name of something"
myPhone_pics(2).pic = a_Third_png_file

But a dictionary would be easier. Make your myPhone_pics property type Dictionary.

myPhone_pics = new dictionary
myPhone_pics.Value("My Name of something") = a_png_file
myPhone_pics.Value("My Second Name of something") = a_second_png_file
myPhone_pics.Value("My Third Name of something") = a_third_png_file