Naughts and Crosses- VB.NET

Started by
11 comments, last by AncientHunter 16 years, 8 months ago
hey, i have a coding problem for the results of winning that is to stubborn to work! at the moment i have picture boxes for this two player game that show whether you have won, lost or drawn. the thing is its always draw until someone wins. i know what i have to do to get it right but its not working. pleaze help me.

Private Sub ResultWinner()
        Dim count As Integer
        If DetermineWinner() = 1 Then
            pic_DisplayResult2.Image = Image.FromFile(Application.StartupPath & "\Visual basic\You Win!.bmp")
            pic_DisplayResult.Image = Image.FromFile(Application.StartupPath & "\Visual basic\You Lose!.bmp")
            score1 += 100
            P1DisplayScore()
        ElseIf DetermineWinner() = 2 Then
            pic_DisplayResult.Image = Image.FromFile(Application.StartupPath & "\Visual basic\You Win!.bmp")
            pic_DisplayResult2.Image = Image.FromFile(Application.StartupPath & "\Visual basic\You Lose!.bmp")
            score2 += 100
            P2DisplayScore()
        Else
            For count = 1 To 9
                'arrPic(count) = nothing works everywhere else.  Why doesnt it work here?
                If arrPic(count) = Nothing Then
                Else
                    pic_DisplayResult.Image = Image.FromFile(Application.StartupPath & "\Visual basic\Draw.bmp")
                    pic_DisplayResult2.Image = Image.FromFile(Application.StartupPath & "\Visual basic\Draw.bmp")
                End If
            Next count

        End If
    End Sub



the line it doesnt like in this code is "If arrPic(count) = Nothing Then". it comes up with an error message saying "Error 1 Operator '=' is not defined for types 'System.Windows.Forms.PictureBox' and 'System.Windows.Forms.PictureBox'."
The wheel is spinning, but the hampster is dead!
Advertisement
I don't code in VB.NET, so this may not really be the correct solution.

Try doing
If arrPic(count) Is Nothing Then


Also, can you show me where/how you declare arrPic ?

EDIT:

Why not just do this?

For count = 1 To 9                'arrPic(count) = nothing works everywhere else.  Why doesnt it work here?                If arrPic(count) IsNot Nothing Then                    pic_DisplayResult.Image = Image.FromFile(Application.StartupPath & "\Visual basic\Draw.bmp")                    pic_DisplayResult2.Image = Image.FromFile(Application.StartupPath & "\Visual basic\Draw.bmp")                End If            Next count
that takes away the squigly lines but it does the same thing when run. here is where i stated arrPic:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        SetControlArray()    End SubPrivate Sub SetControlArray()        arrPic(1) = PictureBox1        arrPic(2) = PictureBox2        arrPic(3) = PictureBox3        arrPic(4) = PictureBox4        arrPic(5) = PictureBox5        arrPic(6) = PictureBox6        arrPic(7) = PictureBox7        arrPic(8) = PictureBox8        arrPic(9) = PictureBox9    End Sub
The wheel is spinning, but the hampster is dead!
Quote:Original post by AncientHunter
that takes away the squigly lines


Which squiggly lines are you talking about?
that does the same as the others.
The wheel is spinning, but the hampster is dead!
in VB.Net when it finds errors (some) it puts blue squigly lines under it to say that you screwed up something. that line is gone now but it still refuses to work.
The wheel is spinning, but the hampster is dead!
So what happens instead?
when i run the program? well as soon as i make a move for either player the picturebox shows a picture saying "DRAW" until someone wins and it changes to "win" or "lose"
The wheel is spinning, but the hampster is dead!
so can anyone help me?
The wheel is spinning, but the hampster is dead!
I still don't understand.

Can you explain what is supposed to happen?

Can you explain what actually happens?

This topic is closed to new replies.

Advertisement