Sie sind auf Seite 1von 8

Introduction

Solution
Conclusion

VBA Programming Workshop - Tic Tac Toe

Mr. Chew Chun Yong, Ms. Choo Ley Ya

26 November 2016

Mr. Chew Chun Yong, Ms. Choo Ley Ya VBA Programming Workshop - Tic Tac Toe
Introduction
Solution
Conclusion

Table of contents

1 Introduction

2 Solution

3 Conclusion

Mr. Chew Chun Yong, Ms. Choo Ley Ya VBA Programming Workshop - Tic Tac Toe
Introduction
Solution
Conclusion

Know How To Play Tic Tac Toe?

A player will win if he has three in a row.


We want to build a Tic Tac Toe board in Excel.

Mr. Chew Chun Yong, Ms. Choo Ley Ya VBA Programming Workshop - Tic Tac Toe
Introduction
Solution
Conclusion

How to do it?

We want to automate the process of typing in ”X” or ”O”


into Excel.
Can we ask VBA to do it for us, depending on the location we
DOUBLE CLICK?
Yes, VBA Event.
Event is defined as action of the worksheet, it can be double
click, selection change and etc.

Mr. Chew Chun Yong, Ms. Choo Ley Ya VBA Programming Workshop - Tic Tac Toe
Introduction
Solution
Conclusion

Before Code It

We can simplify the problem and plan the steps by doing this:
Imagine that two of your friends are playing tic tac toe, and
you are helping them to draw on paper. So what do you need
to do/take note?
You need to identify whose turn now.
You need to help to identify is any of them win.
Similarly, we need to tell VBA how to recognize which player’s
turn now and the winning criteria (VBA is now taking over
your role).

Mr. Chew Chun Yong, Ms. Choo Ley Ya VBA Programming Workshop - Tic Tac Toe
Introduction
Solution
Conclusion

Before Code It

You can do these two things in Excel first, then VBA only
read the info from worksheet.
This would be easier to visualize what we are doing.
And lastly, VBA will be only doing putting ”O” or ”X” into
worksheet.
Try it out.

Mr. Chew Chun Yong, Ms. Choo Ley Ya VBA Programming Workshop - Tic Tac Toe
Introduction
Solution
Conclusion

Conclusion

No complicated/advance coding in this project.


But we know that we can make VBA code executed when we
have some action on worksheet. (This is could be useful when
we are automating some daily routine).
One of the best way of learning any programming language is:
Learn from solving problems.

Mr. Chew Chun Yong, Ms. Choo Ley Ya VBA Programming Workshop - Tic Tac Toe
Introduction
Solution
Conclusion

Conclusion

You can try doing tic tac toe that you can play against PC.
That means you need to have an algorithm to play as second
player.
Or, you can try to make ”Ultimate Tic Tac Toe”.
A good website that has collection of problems to practice
your math and programming:
https://projecteuler.net/

Mr. Chew Chun Yong, Ms. Choo Ley Ya VBA Programming Workshop - Tic Tac Toe

Das könnte Ihnen auch gefallen