I need to use at least one array in the tic tac toe code shown below and I am not sure how to do it. I am new at this which explains my question. Any help would be greatly appreciated.

Public Class MainForm
Dim p As Integer
Dim pic As PictureBox

Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
p = 1
End Sub

Private Sub Pic_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.Click, PictureBox2.Click, PictureBox3.Click, PictureBox4.Click, PictureBox5.Click, PictureBox6.Click, PictureBox7.Click, PictureBox8.Click, PictureBox9.Click
pic = sender
Select Case p
Case 1
If pic.Image Is blankPictureBox.Image Then
p = 2
playerLabel.Text = "Player O"
pic.Image = xPictureBox.Image
End If
Case 2
If pic.Image Is blankPictureBox.Image Then
p = 1
playerLabel.Text = "Player X"
pic.Image = oPictureBox.Image
End If
End Select
Call win1()
Call tie()
Call win3()
End Sub

Private Sub startButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles startButton.Click
PictureBox1.Image = blankPictureBox.Image
PictureBox2.Image = blankPictureBox.Image
PictureBox3.Image = blankPictureBox.Image
PictureBox4.Image = blankPictureBox.Image
PictureBox5.Image = blankPictureBox.Image
PictureBox6.Image = blankPictureBox.Image
PictureBox7.Image = blankPictureBox.Image
PictureBox8.Image = blankPictureBox.Image
PictureBox9.Image = blankPictureBox.Image
PictureBox1.Enabled = True
PictureBox2.Enabled = True
PictureBox3.Enabled = True
PictureBox4.Enabled = True
PictureBox5.Enabled = True
PictureBox6.Enabled = True
PictureBox7.Enabled = True
PictureBox8.Enabled = True
PictureBox9.Enabled = True
playerLabel.Text = "Player X"
p = 1
End Sub
Public Function win1()
If PictureBox1.Image Is PictureBox2.Image And PictureBox2.Image Is PictureBox3.Image And PictureBox3.Image Is xPictureBox.Image Then
Call win2()
End If
If PictureBox4.Image Is PictureBox5.Image And PictureBox5.Image Is PictureBox6.Image And PictureBox6.Image Is xPictureBox.Image Then
Call win2()
End If
If PictureBox7.Image Is PictureBox8.Image And PictureBox8.Image Is PictureBox9.Image And PictureBox9.Image Is xPictureBox.Image Then
Call win2()
End If
If PictureBox1.Image Is PictureBox4.Image And PictureBox4.Image Is PictureBox7.Image And PictureBox7.Image Is xPictureBox.Image Then
Call win2()
End If
If PictureBox2.Image Is PictureBox5.Image And PictureBox5.Image Is PictureBox8.Image And PictureBox8.Image Is xPictureBox.Image Then
Call win2()
End If
If PictureBox3.Image Is PictureBox6.Image And PictureBox6.Image Is PictureBox9.Image And PictureBox9.Image Is xPictureBox.Image Then
Call win2()
End If
If PictureBox3.Image Is PictureBox5.Image And PictureBox5.Image Is PictureBox7.Image And PictureBox7.Image Is xPictureBox.Image Then
Call win2()
End If
If PictureBox1.Image Is PictureBox5.Image And PictureBox5.Image Is PictureBox9.Image And PictureBox9.Image Is xPictureBox.Image Then
Call win2()
End If
End Function
Public Function win2()
PictureBox1.Enabled = False
PictureBox2.Enabled = False
PictureBox3.Enabled = False
PictureBox4.Enabled = False
PictureBox5.Enabled = False
PictureBox6.Enabled = False
PictureBox7.Enabled = False
PictureBox8.Enabled = False
PictureBox9.Enabled = False
If p = 1 Then
playerLabel.Text = "Player O Wins!"
Else
playerLabel.Text = "Player X Wins!"
End If
End Function
Public Function tie()
If PictureBox1.Image Is blankPictureBox.Image Then
ElseIf PictureBox2.Image Is blankPictureBox.Image Then
ElseIf PictureBox3.Image Is blankPictureBox.Image Then
ElseIf PictureBox4.Image Is blankPictureBox.Image Then
ElseIf PictureBox5.Image Is blankPictureBox.Image Then
ElseIf PictureBox6.Image Is blankPictureBox.Image Then
ElseIf PictureBox7.Image Is blankPictureBox.Image Then
ElseIf PictureBox8.Image Is blankPictureBox.Image Then
ElseIf PictureBox9.Image Is blankPictureBox.Image Then
Else
PictureBox1.Enabled = False
PictureBox2.Enabled = False
PictureBox3.Enabled = False
PictureBox4.Enabled = False
PictureBox5.Enabled = False
PictureBox6.Enabled = False
PictureBox7.Enabled = False
PictureBox8.Enabled = False
PictureBox9.Enabled = False
playerLabel.Text = "TIE!"
End If
End Function
Public Function win3()
If PictureBox1.Image Is PictureBox2.Image And PictureBox2.Image Is PictureBox3.Image And PictureBox3.Image Is oPictureBox.Image Then
Call win2()
End If
If PictureBox4.Image Is PictureBox5.Image And PictureBox5.Image Is PictureBox6.Image And PictureBox6.Image Is oPictureBox.Image Then
Call win2()
End If
If PictureBox7.Image Is PictureBox8.Image And PictureBox8.Image Is PictureBox9.Image And PictureBox9.Image Is oPictureBox.Image Then
Call win2()
End If
If PictureBox1.Image Is PictureBox4.Image And PictureBox4.Image Is PictureBox7.Image And PictureBox7.Image Is oPictureBox.Image Then
Call win2()
End If
If PictureBox2.Image Is PictureBox5.Image And PictureBox5.Image Is PictureBox8.Image And PictureBox8.Image Is oPictureBox.Image Then
Call win2()
End If
If PictureBox3.Image Is PictureBox6.Image And PictureBox6.Image Is PictureBox9.Image And PictureBox9.Image Is oPictureBox.Image Then
Call win2()
End If
If PictureBox3.Image Is PictureBox5.Image And PictureBox5.Image Is PictureBox7.Image And PictureBox7.Image Is oPictureBox.Image Then
Call win2()
End If
If PictureBox1.Image Is PictureBox5.Image And PictureBox5.Image Is PictureBox9.Image And PictureBox9.Image Is oPictureBox.Image Then
Call win2()
End If
End Function

Private Sub ExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ExitButton.Click
Me.Close()
End Sub
End Class

I'd be glad to help, but I'd like to know of any ideas you have concerning using an array in the code. Where do you think it would be most appropriate for one. This sounds like a homework assignment, and we try to avoid giving answers without being shown some effort.

This article has been dead for over six months. Start a new discussion instead.