Question

I am working on a program for my Visual Basic class and am supposed to create a game of Tic Tac Toe with two views a GUI view (which I know how to do) and a text view using the console which i have no idea what to do.

I know this would use

Console.WriteLine()

But I've tried something like this:

  Module Module1

Sub Main()
    Console.WriteLine("Welcome to Tic Tac Toe! Would you like to play a game?")
    Console.ReadKey(True)

    Console.WriteLine(" 1 | 2 | 3 ")
    Console.WriteLine("--- --- ---")
    Console.WriteLine(" 4 | 5 | 6 ")
    Console.WriteLine("--- --- ---")
    Console.WriteLine(" 7 | 8 | 9 ")
End Sub

End Module

But when I run the program, nothing happens. I'm sure this is a really stupid question (and is actually just one of many that I have for this program, but need to at least get the design worked out before I can start getting it to work in other areas) but we've never worked with the console before, everything we've done up until this point was all GUI based.

Don't know that it helps any, but here is what I have in my module that holds the 2D array

Module Module1
Const intMAX_ROWS As Integer = 2
Const intMAX_COL As Integer = 2
Public gameArray(intMAX_ROWS, intMAX_COL) As String

Button1.Text = gameArray(0,0) 
Button2.Text = gameArray(0,1)
Button3.Text = gameArray(0,2)
Button4.Text = gameArray(1,0)
Button5.Text = gameArray(1,1)
Button6.Text = gameArray(1,2)
Button7.Text = gameArray(2,0)
Button8.Text = gameArray(2,1)
Button9.Text = gameArray(2,2)

End Module

On the module, I'm getting errors located at each of the Button.Text lines that states

Declaration expected

Any help would be greatly appreciated.

Was it helpful?

Solution

What are the steps you are taking to run your program? Are you, by chance, seeing a black or white window appear and immediately disappear? We'll need more information to help you.

If my suspicions are correct, you may simply be running your program from Visual Studio by pressing the run button, and the console program is ending before you're able to see the feedback. If so, one trick may be to add a line of code to cause your program to wait for a key to be pressed before ending:

Console.WriteLine("Press any key to continue...")
Console.ReadKey(true)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top