-
Feb 17th, 2013, 04:17 PM
#1
Thread Starter
New Member
Operator '=' is not defined!
Hi! There is an error in the game im making.
If PictureBox5.Image = My.Resources.Resources.hm3 Then
Returns the error : Operator '=' is not defined for types 'System.Drawing.Image' and 'System.Drawing.Bitmap'.
What alternatives are there for =, and why does this happen?
Thanks!
-
Feb 18th, 2013, 11:51 AM
#2
Re: Operator '=' is not defined!
Moved From Classic ASP to ASP.NET
-
Feb 18th, 2013, 01:18 PM
#3
Hyperactive Member
Re: Operator '=' is not defined!
what are you trying to evaluate? The image object, the name, some property? Image maybe an object that doesn't support "=" but its name does I'm sure.
if i was able to help, rate my post!
-
Feb 19th, 2013, 05:34 PM
#4
Thread Starter
New Member
Re: Operator '=' is not defined!
I want it so that If the picturebox's image is (Whatever), do (whatever)
-
Feb 19th, 2013, 06:58 PM
#5
Re: Operator '=' is not defined!
Are we sure that this is an asp.net question?
There is no default picturebox that i know of in asp.net.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Feb 20th, 2013, 02:39 AM
#6
Re: Operator '=' is not defined!
Originally Posted by Programmer3001
I want it so that If the picturebox's image is (Whatever), do (whatever)
Can you explain exactly what you mean by this?
Are you talking about examining every pixel of each image to check whether they are the same? Or are you simply talking about comparing the file names of each image to see if they are the same.
The first is not something that you are going to get for free, and something that you would have to code yourself. The second is something that is quite simple to implement, and has already been discussed earlier in this thread.
Gary
-
Feb 21st, 2013, 08:58 PM
#7
Thread Starter
New Member
Re: Operator '=' is not defined!
-
Feb 21st, 2013, 10:41 PM
#8
Re: Operator '=' is not defined!
Originally Posted by Programmer3001
Its vb 2010!
The ASP forum is for questions on building web apps with VB6. A mod has moved this thread to the ASP.NET forum because you're obviously not using VB6, but it appears that you're not creating a web app either, so you couldn't have selected a more wrong forum. The PictureBox control is for Windows Forms, so this thread should have been posted in the VB.NET forum. I will ask the mods to move it.
As for the question, you have a couple of issues. As the error message says, there is no = operator defined for those types. The = operator is defined for almost no reference types, i.e. classes. = is defined for value types, i.e. structures, which includes numeric types, Boolean, DateTime and various others. It is also defined for the String class and a small number of other classes where it makes sense, but not many. Generally, if you want to determine whether two references refer to the same object then you need to use Is rather than =.
That said, this:
Code:
If PictureBox5.Image Is My.Resources.hm3 Then
is going to be False every time. That because using My.Resources creates a new object every time. Even this:
Code:
If My.Resources.hm3 Is My.Resources.hm3 Then
will be False because each use of the 'hm3' property will generate a different Bitmap object so to say that one is the other is not true. When using a resource multiple times the correct approach is to declare a member variable and assign the resource that, then use that variable everywhere else in your code. In this case, put this in your form:
Code:
Private hm3 As Image = My.Resources.hm3
and then use that 'hm3' variable everywhere else. This would then be a valid comparison:
Code:
If PictureBox5.Image Is hm3 Then
assuming that you may have assigned 'hm3' to the Image property of the PictureBox in the first place.
On an unrelated note, now would be a good time to learn to use meaningful names for things. 'hm3' is basically meaningless so you should provide a better name for that resource. PictureBox5 is also basically meaningless. Never accept the default names for controls. Always change the name to something that implies the purpose. Do the same for all variables, properties, etc.
-
Feb 21st, 2013, 11:19 PM
#9
Re: Operator '=' is not defined!
JMC, i think he must specify if he wants to use something like a picturebox in asp.net or just use a picturebox, so we can avoid moving this thread all around the forum
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Feb 21st, 2013, 11:24 PM
#10
Re: Operator '=' is not defined!
Originally Posted by sapator
JMC, i think he must specify if he wants to use something like a picturebox in asp.net or just use a picturebox, so we can avoid moving this thread all around the forum
There's no such thing as a PictureBox in ASP.NET, so if this was an ASP.NET app then the OP couldn't have a PictureBox5. I guess that there's a slim possibility that it's not a standard Framework control or that the OP has chosen that name for a different control but I reckon that we're safe to discount that.
-
Feb 21st, 2013, 11:31 PM
#11
Re: Operator '=' is not defined!
I've said on a previous reply that there is not such a thing as a Picturebox in asp.net but maybe the OP wants to create something similar.I really don't know.He must specify what he wants.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Feb 28th, 2013, 02:23 AM
#12
Re: Operator '=' is not defined!
Hello Programmer3001,
As you can see, there are a number of people in this thread who want to help you, but we also need some help from you.
Can you please explain exactly what you are doing, so that we can best help you.
Gary
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|