Visual Basic 2005 Guide
Story Maker Program


This is a simple program for you to copy and adapt. It is based on the game that is sometimes called Mad Libs. People contribute random words to a story. I started off by thinking of the story I wanted to make so I knew what pieces of information to get from the user.

My story was,

Peter Parker was bitten by a radioactive spider and turned into Spiderman.

The words that are shown in bold text will be chosen by the user.

Step 1 - Building The Form

Your form is going to look like this,

story form design

  • The smaller text boxes are called (from the top) txtName, txtAnimal, txtInjury, txtSuperName.
  • The labels on the right are called (from the top) lblName, lblAnimal, lblInjury, lblSuperName.
  • The button is called btnMakeStory.
  • The larger text box is called txtStory and has the multiline and wordwrap properties set to true.

Create a new project and save it to a new folder in your user area. Create the form as detailed above.

Step 2 - Programming The Button Click Event

Double click on the button and type the following code in to the button's click event handler.

Dim strStory As String
Dim strName As String
Dim strAnimal As String
Dim strInjury As String
Dim strSuperName As String
strName = txtName.Text
strAnimal = txtAnimal.Text
strInjury = txtInjury.Text
strSuperName = txtSuperName.Text
strStory = strName & " was " & strInjury & " by a radioactive " & strAnimal & " and turned into " & strSuperName & "."
txtStory.Text = strStory

Save your work and test that the program works.

Step 3 - Writing Your Own Story

Before you take on this challenge, make sure that you understand every line of code. Print out the code and annotate your printout to explain the purpose of each of these lines.

Start by writing your story. Remember, the point of this program is to produce a funny story because the user doesn't know what they are going to end up with. Try to make it so that there are at least 10 things that the user has to contribute.