|Simple TicTacToe Program|
If you don’t have a Visual Basic Program (IDE) like VB6 or anything to build a program or software but you have only Microsoft Office (Excel) Application. Can we build such as this program the tic-tac-toe (as Bill Gates’ TicTacToe First Program)?
Well indeed, but here we have to learn coding of visual basic programming, of how we speak to computer using that language so that they can fully understand what’s our thought.
From this we just called the computer as a slave, because they always follow what our orders are
The exciting part here is you gonna build something that can be useful in our lives, in just easy way
So Let’s get started!
- Open up your Microsoft Excel
- Make sure the developer option is enabled. Please see the link
- You have to allow or enable the settings for macro to run the code
- (File –> Option –> Trust Center –>Trust Center Settings –> Macro Settings –> Check “Enable all macros”)
- In the Developer Tab, click View Code
- Here we start writing the code, I shall provide you a simple code, for you to grasp easily
- Now from Insert Tab click Insert Form
- Change the Properties of the Form
- Change the Name of the form to tttfrm
- Change the Caption of the form to Tic-Tac-Toe
- The Height and Width to 270, 300 respectively
- To view Properties press F4
- Insert a CommandButton from toolbox (to show the tool box, in View Tab click Tool Box) to your UserForm (tttfrm)
- Click your CommandButton and change its property
- Change the Caption to (blank) as in blank
- Change the Height and Width to 55, 55
- Change the Font Size to 22 (this is the size of our “O” and “X”)
- It should be like this.
- Copy this CommandButton to your UserForm (make 9 copies) form a tictactoe diagram.
Press F5 to test your work
Close it then click View Code, Double click the tttfrm
Now for the coding, Double Click the first box or CommandButton1
Insert this code within the sub:
If CommandButton1.Caption = “” ThenCommandButton1.Caption = “O”ElseIf CommandButton1.Caption = “O” ThenCommandButton1.Caption = “X”Else: CommandButton1.Caption = “O”
Do the rest, just copy the code and change it to CommandButton2.Caption for the right “Private Sub CommandButton2_Click()” then paste it within the sub
Check it out! Run it (F5)
Oh well, how can we restart the game, if there’s no restart button ( use instead the close button 🙂 )
Well it’s simple to handle this thing, just create another Command Button
Place the button inside your form
Double click the command and copy-paste this
CommandButton1.Caption = “”
CommandButton2.Caption = “”
CommandButton3.Caption = “”
CommandButton4.Caption = “”
CommandButton5.Caption = “”
CommandButton6.Caption = “”
CommandButton7.Caption = “”
CommandButton8.Caption = “”
CommandButton9.Caption = “”
Waaaiitt up! there’s more, well as you can see when you open your workbook, where is the button that direct you in your gameplay? Go in somewhere like View Code then find your UserForm and Run…….. It’s so hassle don’t you think?
Well Certainly, you can add up CommandButton within the sheet to navigate you faster to your gameplay, but how?
It’s easy , Go to the Developer Tab, Under the “Controls” Group, click Insert, Under Active X Controls, find the CommandButton
Right Click it ,click Property then change the Caption to TicTacToe
Double click your TicTacToe Button (note: the design mode must be enabled) to write down the code and copy-paste this
Close the coding window, and turn off the design mode
Click your TicTacToe Button!
Congratulations! You have created a simple TicTacToe Program in Microsoft Excel!
Next Stop, how will this program become like a True Executable Program using Microsoft Excel (tricky mimic)