"Add a property to the window: mypic as picture" ???

Don’t hate me!
Feeling stupid.

I have done a lot of VB in yesteryear, but moved now to Xojo.

The pdf book gives this instruction

“Add a property to the window: mypic as picture”

Add it? Sure - where? How?

Currently I have a button with this code

dim f as folderitem
dim d as opendialog
dim mypic as picture
d = new opendialog
f = d.showmodal()
if f <> nil then
mypic = picture.open(f)
canvas1.invalidate
end if

I also have canvas1 with this code

if mypic <> nil then
g.drawpicture(mypic,10,10)
end if

But I get an error … for “mypic” as “This item does not exist”

I am presuming that my lack of “Add a property to the window: mypic as picture” is the problem. Where do I put that code? Talk me through it, please! :slight_smile:

I am making a game for some very young Chinese children … I will have many pictures and I’ll need the frame to size to the picture … all the pictures being different sizes. Is this the way to go?

Thanks!!!

Menu -> Insert -> Property

bear in mind you need to be aware of the SCOPE of things (this was required in VB as well)

you DIM “myPic” in your BUTTON… therefore the scope is that of “the button”
so Canvas1 has no clue what “myPic” is

therefore myPic needs to be Dim’d in a scope higher than either button or canvas… Window might be the correct place…
although if myPic is to be used on an even more global scope, then in a Module would be better

And it will give you a nil object exception if you dont initialise it with something

If you plan to display one of several pictures, drag the PNG files into the project

If they are called

Apple.png
Banana.png

etc
then the code to disply them will be

g.drawpicture(apple,10,10)

Ummm … I realize the scope - yeap

But this is the exact code in the xojo book for the button

dim f as folderitem
dim d as opendialog
d = new opendialog
f = d.showmodal()
if f <> nil then
mypic = picture.open(f)
canvas1.invalidate
end if

There’s no "dim there for mypic

And this is the exact code from the book for canvas …

if mypic <> nil then
g.drawpicture(mypic,10,10)
end if

Again, there’s no "dim there for mypic

So … I dim it in “the window”? So I just click on the form … and write there “dim mypic as picture” ??? Nope, that doesn’t work…

I need to write Dim mypic as picture somewhere so it is “public” … where do I put it ?

So sorry to trouble y’all with this newbie stuff :frowning:

You don’t DIM in this case.

You add a property, set its type (integer, string, structure, picture, etc.). It could be a window property, an app property, a session property (in a web app), a container control property… it all depends on where in your app you want to be able to use the property. (@Dave S gave you a way to add a property to a window, in a prior post in the thread.)

Once you have the property, you initialize it by assigning an appropriate value to it.

No it doesn’t, and nobody said it did or would

did you TRY this???

Yes …
I went to insert > property …

I tried
mypic as picture (as stated in the book)

and I tried

Dim mypic as picture

pushbutton1 says “item does not exist”

Hence my confusion :slight_smile:

Make sure you have the window selected.
Right click on it and choose “insert… property”
You get a window like this

Change the name to be mypic
change the type to be picture.

Dim mypic as picture is how you do it inside a method.

right click on the window?

I don’t get a menu that looks like that …

I see you have the answer I need … I just can’t get my way to that window.

wait! I see it!

Got it!

Ha!

That was killing me - thanks for the patience!!!

Hey! we all started one day. Soon, you will be answering questions too!

I would recommend highly that you read the tutorials in your Documentation folder (look under Xojo in your start menu). These documents and the Quickstart documents contain a lot of nice little tips that will make your life easier.