2 Replies - 391 Views - Last Post: 08 May 2013 - 01:38 PM Rate Topic: -----

#1 danmir123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-May 13

An error message saying Conversion from string "" to type '

Posted 08 May 2013 - 01:09 PM

PROGRAM DESCRIPTION:
Create a program that allows two users to play Tic Tac Toe against each other. The program stores the players’ moves and checks for wins but does not actually play against the user.If a winner is found, make visible a label on the form and display a message declaring who won. Enable a button to play again. Clear the contents of the array



MY ISSUE: After the statement, "" If (array(0, 0) = "X" And array(0, 1) = "X" And array(0, 2)) = "X" Then
Return True ""

An error message saying Conversion from string "" to type 'Boolean' is not valid appears. I need help with that and using the function to display the victory message.



HERE's THE CODE:

Public Class Form1
    Dim turn As Integer
    Dim array(3, 3) As String
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        turn = 1
    End Sub
    Private Function win() As Boolean
        'Horizontal win
        If (array(0, 0) = "X" And array(0, 1) = "X" And array(0, 2)) = "X" Then
            Return True
        ElseIf (array(1, 0) = "X" And array(1, 1) = "X" And array(1, 2)) = "X" Then
            Return True
        ElseIf (array(2, 0) = "X" And array(2, 1) = "X" And array(2, 2)) = "X" Then
            Return True
        ElseIf (array(0, 0) = "O" And array(0, 1) = "O" And array(0, 2)) = "O" Then
            Return True
        ElseIf (array(1, 0) = "O" And array(1, 1) = "O" And array(1, 2)) = "O" Then
            Return True
        ElseIf (array(2, 0) = "O" And array(2, 1) = "O" And array(2, 2)) = "O" Then
            Return True


            'Vertical Win
        ElseIf (array(0, 0) = "X" And array(1, 0) = "X" And array(2, 0)) = "X" Then
            Return True
        ElseIf (array(0, 1) = "X" And array(1, 1) = "X" And array(2, 1)) = "X" Then
            Return True
        ElseIf (array(0, 2) = "X" And array(1, 2) = "X" And array(2, 2)) = "X" Then
            Return True
        ElseIf (array(0, 0) = "O" And array(1, 0) = "O" And array(2, 0)) = "O" Then
            Return True
        ElseIf (array(0, 1) = "O" And array(1, 1) = "O" And array(2, 1)) = "O" Then
            Return True
        ElseIf (array(0, 2) = "O" And array(1, 2) = "O" And array(2, 2)) = "O" Then
            Return True

            'Diagonal Win
        ElseIf (array(0, 0) = "X" And array(1, 1) = "X" And array(2, 2)) = "X" Then
            Return True
        ElseIf (array(0, 2) = "X" And array(1, 1) = "X" And array(2, 0)) = "X" Then
            Return True
        ElseIf (array(0, 0) = "O" And array(1, 1) = "O" And array(2, 2)) = "O" Then
            Return True
        ElseIf (array(0, 2) = "O" And array(1, 1) = "O" And array(2, 0)) = "O" Then
            Return True
        End If

        Return False

    End Function
    Private Sub cmdSquare1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSquare1.Click
        If turn = 1 Then
            array(0, 0) = "O"
            cmdSquare1.Text = "O"
            lblPlayerTurn.Text = "X"
            turn = 2
            If win() = True Then
                MessageBox.Show(" Player O wins")
            End If


        Else
            turn = 1
            array(0, 0) = "X"
            cmdSquare1.Text = "X"
            lblPlayerTurn.Text = "O"
            If True = win() Then
                MessageBox.Show(" Player X wins")
            End If

        End If


        cmdSquare1.Enabled = False
    End Sub
    Private Sub cmdSquare2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSquare2.Click
        If turn = 1 Then
            array(0, 1) = "O"
            cmdSquare2.Text = "O"
            lblPlayerTurn.Text = "X"
            turn = 2

            If True = win() Then
                MessageBox.Show(" Player O wins")
            End If
        Else
            turn = 1
            array(0, 1) = "X"
            cmdSquare2.Text = "X"
            lblPlayerTurn.Text = "O"

            If True = win() Then
                MessageBox.Show(" Player X wins")

            End If
        End If

        cmdSquare2.Enabled = False
    End Sub
    Private Sub cmdSquare3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSquare3.Click
        If turn = 1 Then
            array(0, 2) = "O"
            cmdSquare3.Text = "O"
            lblPlayerTurn.Text = "X"
            turn = 2
            If True = win() Then
                MessageBox.Show(" Player O wins")
            End If
        Else
            turn = 1
            array(0, 2) = "X"
            cmdSquare3.Text = "X"
            lblPlayerTurn.Text = "O"
            If True = win() Then
                MessageBox.Show(" Player X wins")
            End If
        End If

        cmdSquare3.Enabled = False
    End Sub
    Private Sub cmdSquare4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSquare4.Click
        If turn = 1 Then
            array(1, 0) = "O"
            cmdSquare4.Text = "O"
            lblPlayerTurn.Text = "X"
            turn = 2
            If win() Then
                MessageBox.Show(" Player O wins")
            End If
        Else
            turn = 1
            array(1, 0) = "X"
            cmdSquare4.Text = "X"
            lblPlayerTurn.Text = "O"
            If win() Then
                MessageBox.Show(" Player X wins")
            End If
        End If

        cmdSquare4.Enabled = False
    End Sub
    Private Sub cmdSquare5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSquare5.Click
        If turn = 1 Then
            array(1, 1) = "O"
            cmdSquare5.Text = "O"
            lblPlayerTurn.Text = "X"
            turn = 2
            If win() Then
                MessageBox.Show(" Player O wins")
            End If
        Else
            turn = 1
            array(1, 1) = "X"
            cmdSquare5.Text = "X"
            lblPlayerTurn.Text = "O"
            If win() Then
                MessageBox.Show(" Player O wins")
            End If
        End If

        cmdSquare5.Enabled = False
    End Sub
    Private Sub cmdSquare6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSquare6.Click
        If turn = 1 Then
            array(1, 2) = "O"
            cmdSquare6.Text = "O"
            lblPlayerTurn.Text = "X"
            turn = 2
            If True = win() Then
                MessageBox.Show(" Player O wins")
            End If
        Else
            turn = 1
            array(1, 2) = "X"
            cmdSquare6.Text = "X"
            lblPlayerTurn.Text = "O"
            If True = win() Then
                MessageBox.Show(" Player X wins")
            End If
        End If

        cmdSquare6.Enabled = False
    End Sub
    Private Sub cmdSquare7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSquare7.Click
        If turn = 1 Then
            array(2, 0) = "O"
            cmdSquare7.Text = "O"
            lblPlayerTurn.Text = "X"
            turn = 2
            If True = win() Then
                MessageBox.Show(" Player O wins")
            End If
        Else
            turn = 1
            array(2, 0) = "X"
            cmdSquare7.Text = "X"
            lblPlayerTurn.Text = "O"
            If True = win() Then
                MessageBox.Show(" Player X wins")
            End If
        End If

        cmdSquare7.Enabled = False
    End Sub
    Private Sub cmdSquare8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSquare8.Click
        If turn = 1 Then
            array(2, 1) = "O"
            cmdSquare8.Text = "O"
            lblPlayerTurn.Text = "X"
            turn = 2
            If True = win() Then
                MessageBox.Show(" Player O wins")
            End If
        Else
            turn = 1
            array(2, 1) = "X"
            cmdSquare8.Text = "X"
            lblPlayerTurn.Text = "O"
            If True = win() Then
                MessageBox.Show(" Player X wins")
            End If
        End If

        cmdSquare8.Enabled = False
    End Sub
    Private Sub cmdSquare9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSquare9.Click
        If turn = 1 Then
            array(2, 2) = "O"
            cmdSquare9.Text = "O"
            lblPlayerTurn.Text = "X"
            turn = 2
            If True = win() Then
                MessageBox.Show(" Player O wins")
            End If
        Else
            turn = 1
            array(2, 2) = "X"
            cmdSquare9.Text = "X"
            lblPlayerTurn.Text = "O"
            If True = win() Then
                MessageBox.Show(" Player X wins")
            End If
        End If

        cmdSquare9.Enabled = False
    End Sub
    Private Sub cmdReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdReset.Click

        cmdSquare1.Enabled = True
        cmdSquare1.Text = " "
        cmdSquare2.Text = " "
        cmdSquare2.Enabled = True
        cmdSquare3.Text = " "
        cmdSquare3.Enabled = True
        cmdSquare4.Text = " "
        cmdSquare4.Enabled = True
        cmdSquare5.Text = " "
        cmdSquare5.Enabled = True
        cmdSquare6.Text = " "
        cmdSquare6.Enabled = True
        cmdSquare7.Text = " "
        cmdSquare7.Enabled = True
        cmdSquare8.Text = " "
        cmdSquare8.Enabled = True
        cmdSquare9.Text = " "
        cmdSquare9.Enabled = True
        
ReDim array(3, 3)
    End Sub
End Class

This post has been edited by AdamSpeight2008: 08 May 2013 - 05:10 PM


Is This A Good Question/Topic? 0
  • +

Replies To: An error message saying Conversion from string "" to type '

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3522
  • View blog
  • Posts: 12,023
  • Joined: 12-December 12

Re: An error message saying Conversion from string "" to type '

Posted 08 May 2013 - 01:18 PM

Your bracket is in the wrong place:

If (array(0, 0) = "X" And array(0, 1) = "X" And array(0, 2) = "X") Then 


But why post the entire code if you know which line the error is on, and at least attempt to use code-tags :dontgetit:

Quote

..and using the function to display the victory message.

You need to ask a more specific question.
Was This Post Helpful? 0
  • +
  • -

#3 danmir123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-May 13

Re: An error message saying Conversion from string "" to type '

Posted 08 May 2013 - 01:38 PM

Its fine I don't need help any more my teacher emailed me . He was more helpful and more understanding.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1