8 Replies - 505 Views - Last Post: 29 August 2017 - 09:10 PM Rate Topic: -----

#1 Razgr1z  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-August 17

Help with tags using picturebox

Posted 29 August 2017 - 01:51 PM

Hi! I am practicing VB C# programming and I am following a tutorial I found online. I found an interest in VB and have been self-teaching at the moment. I have done my own edits from the tutorial but have been as close as the tutorial as possible. Everything seems fine except there is a part in the code that I just cant figure out no matter what I do or research. In the tutorial it made me create I think 30 pictureboxes. Each picturebox is tagged a word-name like blocks or bricks or however you choose. I presume it's to make it easier to do if/else statements with all the pictureboxes at once instead of one at a time. I understand It would be less time consuming to just say "if pictureboxes have the tag "bricks" then do XYZ.
Anyway, I followed the code to the T but visualbasic is saying

"Possible unintended reference comprarison; to get a value comparison, cast the left hand side to type 'string'

Here's the part of code that this giving me this

 foreach (Control x in this.Controls)
            {
                if (x is PictureBox && x.Tag == "blockies")
                {
                    if (pBall.Bounds.IntersectsWith(x.Bounds))
                    {
                        this.Controls.Remove(x);
                        pBally = -pBally;
                        score++;
                    }
                }
            }


It has a green squiggly line from x.Tag to blockies"
Thanks for any help.

Is This A Good Question/Topic? 0
  • +

Replies To: Help with tags using picturebox

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13400
  • View blog
  • Posts: 53,479
  • Joined: 12-June 08

Re: Help with tags using picturebox

Posted 29 August 2017 - 01:54 PM

Where is your VB.NET attempt?
Was This Post Helpful? 0
  • +
  • -

#3 Razgr1z  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-August 17

Re: Help with tags using picturebox

Posted 29 August 2017 - 01:58 PM

Hi thanks for the reply, but I am not sure what you mean? Sorry if it's a silly question.

This post has been edited by Skydiver: 29 August 2017 - 09:11 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13400
  • View blog
  • Posts: 53,479
  • Joined: 12-June 08

Re: Help with tags using picturebox

Posted 29 August 2017 - 01:59 PM

VB.NET is one language.
C# is another.

They both use .NET libraries.

You posted in the VB.NET section, but said "I am practicing VB C# programming".

What you have there is C# code. Where is your attempt with VB.NET?
Was This Post Helpful? 0
  • +
  • -

#5 Razgr1z  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-August 17

Re: Help with tags using picturebox

Posted 29 August 2017 - 02:02 PM

Oh sorry! I may possibly placed topic in wrong section. I am just doing a simple program using Windows Form in C# using Visual Studio 2017

This post has been edited by Skydiver: 29 August 2017 - 09:11 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13400
  • View blog
  • Posts: 53,479
  • Joined: 12-June 08

Re: Help with tags using picturebox

Posted 29 August 2017 - 02:04 PM

Mkay. I'll move it.

Quote

cast the left hand side to type 'string'

I would suggest following what it says.. the .TAG variable needs a ".tostring()" to convert its datatype to a string.
Was This Post Helpful? 0
  • +
  • -

#7 Razgr1z  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-August 17

Re: Help with tags using picturebox

Posted 29 August 2017 - 02:08 PM

Yes I tried to Google that and I actually have found some search results leading to this website with some people having similar issues but the people's coding weren't as simple as to what I am doing. I tried editing based on suggestions from those who answered in their cases but I just get a bunch of red lines. Any hint or example code that follows mine would be appreciated.

This post has been edited by Skydiver: 29 August 2017 - 09:11 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13400
  • View blog
  • Posts: 53,479
  • Joined: 12-June 08

Re: Help with tags using picturebox

Posted 29 August 2017 - 02:20 PM

I gave you the line of code.

What is the datatype of ".Tag" from a Control object?
https://msdn.microso...(v=vs.110).aspx

What's the normal way to convert one datatype to string? Usually the ".to string()".
Was This Post Helpful? 0
  • +
  • -

#9 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 5828
  • View blog
  • Posts: 19,868
  • Joined: 05-May 12

Re: Help with tags using picturebox

Posted 29 August 2017 - 09:10 PM

Razgr1z: There is no need to quote the post above yours. Just use the big Reply button or the Fast Reply area.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1