Results 1 to 12 of 12

Thread: Operator '=' is not defined!

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2013
    Posts
    10

    Exclamation 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!

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Operator '=' is not defined!

    Moved From Classic ASP to ASP.NET

  3. #3
    Hyperactive Member jasonwucinski's Avatar
    Join Date
    Mar 2010
    Location
    Pittsburgh
    Posts
    452

    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!

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2013
    Posts
    10

    Re: Operator '=' is not defined!

    I want it so that If the picturebox's image is (Whatever), do (whatever)

  5. #5
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    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.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  6. #6
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Operator '=' is not defined!

    Quote Originally Posted by Programmer3001 View Post
    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

  7. #7

    Thread Starter
    New Member
    Join Date
    Jan 2013
    Posts
    10

    Re: Operator '=' is not defined!

    Its vb 2010!

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: Operator '=' is not defined!

    Quote Originally Posted by Programmer3001 View Post
    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.

  9. #9
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    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
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: Operator '=' is not defined!

    Quote Originally Posted by sapator View Post
    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.

  11. #11
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    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.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  12. #12
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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
  •  



Click Here to Expand Forum to Full Width