Dictionary NilObjectException Problem

What is wrong with the following? I am trying to put a Picture (HeaderIcon) in a dictionary object and assign it a key (HeaderCaption).

I am calling the below code with a caption and picture passed in but keep getting a Nil object exception. I can see in the debugger that both the picture and string are not Nil so what is the issue?

dictIcons the dictionary is initialised in the open event of the control with Dim dictIcons as New Dictionary.

Sub AddHeader(HeaderCaption as String,HeaderIcon as Picture = Nil)

  if HeaderIcon <> Nil then
    dictIcons.Value(Uppercase(HeaderCaption)) = HeaderIcon
  end if
End Sub
Dim dictIcons as New Dictionary

… in the Open event declares a local variable (local to the open event).

I assume you call AddHeader() somewhere else. So you need a variable on the class level:

  1. create a property in your class (or module) called dictIcons and set its data type to Dictionary
  2. in the Open event change your code to
dictIcons = New Dictionary

Eli, thanks. I did have the property in the class already, my mistake was I was redeeming in the open event. As you said I needed to:

dictIcons = New Dictionary

rather than

Dim dictIcons as New Dictionary

All works now. Been away from Xojo for too long (8 months) and forgot so many basic things. I’ve been working in PHP and keep adding ; to the end of every line and forgetting to put THEN on the end of IF…END IF blocks