Open pict on resources

Probably is a silly question but, …
Why this code gets a nil picture? The picFile is ok

Sub Pressed() Handles Pressed
  var iconName as string = "my_icon"
  Var picFile As FolderItem = SpecialFolder.Resource(iconName)
  
  if picFile <> nil  Then
    Var pic As Picture
    pic = Picture.Open(picFile)
    ImageViewer1.Image=pic
  end if
End Sub


Should be SpecialFolder.Resources.Child(iconName)

You’re actually getting a nil folderitem for picFile, not a nil picture per se.

Sorry but no, I already have tried this but I get a nil picture in both cases.

What is the value of picFile.Exists?

1 Like

Well, let’s eliminate “one” of the cases–the original code you displayed was definitely incorrect. :slight_smile:

If you put a breakpoint inside the if/then, is the folderItem picFile <> nil? Is “my_icon” definitely the correct name for the picture file? It could be as simple as missing the extension.

Probably because the file extension is missing

Tim chimed in about the same time as me–in suggesting you test for ‘picFile.Exists’ he said the same thing much more concisely. :slight_smile:

I solved,

var iconName as string = "my_icon.png"
Var picFile As FolderItem 
picFile = SpecialFolder.Resource(iconName)
// picFile = SpecialFolder.Resources.Child(iconName)

Both worked if you add the extension name to the resource…… bizarre

The original code was definitely correct. SpecialFolder.Resource is different than SpecialFolder.Resources. One returns a file, the other a folder.

1 Like

I am enrolling in Medicare this year, and I’m not too old to learn something! :slight_smile: