Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Mario Puzzle panel: errors "System.InvalidCastException"
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MercerA




PostPosted: Fri Jan 17, 2014 10:43 pm   Post subject: Mario Puzzle panel: errors "System.InvalidCastException"

Hi. I'm making a copy of puzzle panel, a mini game from mario 64 ds. (https://www.youtube.com/watch?v=eDL-1AjquRA)

I need help understanding why my code won't run properly. The program will run but when I try to click on one of the menu strip items that refer to the level, the program will stop and will highlight

Dim picTileClicked As PictureBox = sender and tell me :

"An unhandled exception of type 'System.InvalidCastException' occurred in puzzle panel.exe

Additional information: Unable to cast object of type 'System.Windows.Forms.ToolStripMenuItem' to type 'System.Windows.Forms.PictureBox'

Here I have displayed the procedures that use sender and e

The beginning of my main event:

VisualBASIC:

Private Sub PictureBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
        PictureBox1.Click, PictureBox2.Click, PictureBox3.Click, PictureBox4.Click, PictureBox6.Click, _
        PictureBox7.Click, PictureBox8.Click, PictureBox9.Click, PictureBox11.Click, PictureBox12.Click, _
        PictureBox13.Click, PictureBox14.Click, PictureBox16.Click, PictureBox17.Click, PictureBox18.Click, _
        PictureBox19.Click, PictureBox5.Click, PictureBox10.Click, PictureBox15.Click, PictureBox20.Click, _
        PictureBox21.Click, PictureBox22.Click, PictureBox23.Click, PictureBox24.Click, PictureBox25.Click

        Dim picTileClicked As PictureBox = sender                       'refering to the picturebox that is clicked
        Dim TileClicked As Integer = Val(picTileClicked.Tag)         'the tag of the picturebox that is clicked




And this is one of the four sub functions that refer to that event

VisualBASIC:

 Private Sub LevelOneToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles LevelOneToolStripMenuItem.Click, PictureBox1.Click, PictureBox2.Click, PictureBox3.Click, PictureBox4.Click, PictureBox6.Click, _
        PictureBox7.Click, PictureBox8.Click, PictureBox9.Click, PictureBox11.Click, PictureBox12.Click, _
        PictureBox13.Click, PictureBox14.Click, PictureBox16.Click, PictureBox17.Click, PictureBox18.Click, _
        PictureBox19.Click, PictureBox5.Click, PictureBox10.Click, PictureBox15.Click, PictureBox20.Click, _
        PictureBox21.Click, PictureBox22.Click, PictureBox23.Click, PictureBox24.Click, PictureBox25.Click

        Call lvlOneOriginal()

        Call PictureBox_Click(sender, e)

        If clicks = 0 Then
            Call noClicks(mistakes, score)
        End If

    End Sub

I don't know what's wrong with my code!?!!? Please help! I need this mark!!!
I have attached the full copy of the code in a linked document below in case it is needed.

https://docs.google.com/document/d/18ntWDHkYqa6hwjjXzyuCip5QD63-HCEllBhXSwxvdpg/edit?usp=sharing

HELP ME. plz.

thanks.



Mod Edit:
Please wrap you code in either of the following in order to preserve whitespace (indentation) and to highlight the syntax.
code:

[syntax="vb"] ... code ... [/syntax]

[code] ... code ... [/code ]
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sat Jan 18, 2014 12:02 am   Post subject: Re: Mario Puzzle panel: errors "System.InvalidCastException"

MercerA @ Fri Jan 17, 2014 10:43 pm wrote:
"An unhandled exception of type 'System.InvalidCastException' occurred in puzzle panel.exe

Additional information: Unable to cast object of type 'System.Windows.Forms.ToolStripMenuItem' to type 'System.Windows.Forms.PictureBox'

The error message seems very clear: a ToolStripMenuItem is not a PictureBox, so you can't make the variable assignment that you are trying to do.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: