Matthew Leung THE UNIVERSITY OF BRITISH COLUMBIA Interdepartmental Memorandum TO: Randall Kerr FROM: Matthew Leung RE: Assignment - Set of Instructions DATE: November 10, 2004 HOW TO CREATE A SIMPLE GAME USING MICROSOFT VISUAL BASIC .NET 1.0 I NTRODUCTION Microsoft Visual Basic .NET is a popular programming language created for developers who want to develop their applications quickly . Visual Basic is categorized as a RAD (Rapid Application Development) langua ge because it offers a graphical approach to creating user interfaces and its coding syntax is easy to learn. As such, beginners often benefit from learning to program in VB first, then gradually moving on to more advanced languages.
The instructions prov ided below are created for people who are familiar with the Microsoft Windows operating system , but have little or no prior programming language experience. In this tutorial, you be introduced to the basic concepts of programming. Topics that will be co vered include designing forms and creating variables.
By following the step-by- step instructions provided below, you will learn how to create a word guessing game. If you have not programmed before, be prepared to spend half an hour on this tutorial. If you have prior programming experience, expect ... more. less.
to spend around twenty minutes.<br><br> You must have Visual Basic installed on your computer before starting. I recommend purchasing Visual Basic .NET if you expect to get deeper into programming, but alternatively you can download Visual Basic 2005 Express for free. The instructions below may not work if you use any version other than Visual Basic .NET.<br><br> 2.0 STEP - BY - STEP PROCEDURE In order to create the word guessing game, you must carefully follow the steps expl ained below. 2.1 Prepar ing Visual Basic .NET 2.1.1 First, open Visual Basic .NET by double - clicking on its icon in the Start menu. 2.1.2 Once Visual Basic has been opened, c lick File on the menu bar.<br><br> Now, click on the submenu New and press Project . Matthew Leung 2.1.3 When th e New Project dialog box pops up, you will be presented with different types of projects that can be created. Choose the Windows Application within the Visual Basic Projects folder.<br><br> Next, type in the new name for your project (name this project word Guess ) , and choose a location to save it. Click on the OK button . 2.1.4 Now, press Alt - Enter on your keyboard to bring up the Properties inspector .<br><br> Press Ctrl - Alt - X to bring up the Visual Basic Toolbox bar. Your screen shoul d now look similar to Figure 1 b elow. Figure 1 : Various parts of Visual Basic .NET's Interface 2.2 Setting up the User Interface 2.2.1 The goal now is to create a user interface for your users, so that they can easily interact with your program.<br><br> Click and drag TextBox from the Toolbox bar to your form. Refer to Figure 2 for the approximate location of where you should place the TextBox. Check to see that the name of this element is Textbox1 (look in the Properties i nspector) and the text is set to blank.<br><br> 2.2.2 Click and drag Label from the Toolbox to the form. Click on this Label, c opy it (Ctrl - C), and paste it (Ctrl - V) six times. Your labels now have text such as Label1 , Label2 , and so on.<br><br> The text in Label1 to Label5 should be deleted. Click on Label1 , delete the Text value in the Properties inspector, and change the Name value to box1 . Repeat this step for the other four labels, naming them box2 , box3 , and so on.<br><br> Change the Text Value of Label6 to Number of Incorrect Guesses= . Finally, change the Text value of Label7 to 0 and the Name value to guess. Refer to Figure 2 to see that you have changed the Text and Name values correctly.<br><br> Matthew Leung 2.2.3 Click and drag a Button from the Toolbox. Change its Text value to Guess . Figure 2 : The interface of nameGuess.<br><br> Note: The borders on the labels have been added for clarity only. 2.3 Coding and T esting your Application In this phase , you will begin to code your application. Copy and paste the code as directed bel ow.<br><br> The code is explained in Figure 4 and Figure 5 2.3.1. Double - click on the Guess button. You will now see the code window (refer to Figure 3 ) Figure 3 : The code window 2.3.2.<br><br> Type this first code snippet into the code window. Note tha t our secret word for users to guess is hello (in lowercase). If they guess correctly, a letter will show up.<br><br> Matthew Leung Figure 4 : Code part 1 2.3.3. Insert the new code in Figure 5 into your existing code. Figure 5 : Code part 2 Matthew Leung 2.3.4.<br><br> Finally, add the line of code shown in Figure 6. Figure 6 : Code part 3 2.4 Testing you final product 2.4.1 You are now ready to test your program. In the menu bar, click on Debug and then Start .<br><br> Alternatively you can hit F5 on your keyboard. If your program appears, you have succeeded in creating your first Visual Basic .NET game. If nothing appears, check that all the code has been copied correctly.<br><br> 3.0 CONCLUSION As you can tell, using Visual Basic to cre ate programs is not difficult. There are three main phases to application development in Visual Basic: creating the user interface, adding the code, and testing your program. Once your program in complete, it is ready to be used by you or anyone you choo se to give it to.<br><br> Of course, you can go always back to Visual Basic and make modifications as you see fi t.