CIS 380 Lab 1

Points: 10 Due Date: Monday November 11, 2002

This is a simple exercise to make sure you know how to start up and use the development tools you will be using all term. It also practices generating a lab report. About the only way to get this wrong is to not turn it in. The following is step by step how to create a small application in Visual BAsic. Chapter 2 in the book does something similar so it may help to look in there if you get stuck or can't follow what I wrote.

Step one.
From the Start button (or maybe there is an icon on the screen), start Visual Basic running. Select the 'Standard EXE' choice in the little window and press open. On the right is a window labeled 'Properties Form1'. We will change a couple of things there. The properties window is divided into two columns. The left one is the property name and the right one is its value. First change the '(Name)' property from 'Form1' to 'Lab1'. Then change the Caption to 'your name - lab 1'.

Now lets save the project. Under File, select Save As. Then pick a directory to save your project. If you plan to keep your project on a floppy, save it to the local hard drive for now and copy the folder to the floppy later. If you have network space, save the project there.

We will need two text boxes for out program. First, on the far right of the display is a set of controls. We want to click on the little box with the letters 'ab' in it. If you let the mouse hover over one of the controls you should see 'TextBox'. Move over to the gray area with the little dots. Somewhere near the center, close to the top, draw a box. Towards the bottom of these instructions is a picture of how the whole thing should look to give you an idea of where to put things. I don't care if everything is positioned just like mine, as long as all the same controls are there. We need two boxes so repeat what you did above and line the second one up and below the first.

When you click on one of the boxes, you will see its properties over on the right. For the upper box, change its name to 'Gallons' and put a 0 (zero) in the 'Text' field. The second box should also have a 0 in the 'Text' field and its name should be 'Cost'. Do a save again. A dialog box should pop up asking or a name. The default is 'Project1'. You can change it to 'Lab1'.

Labels are next. Under the controls list, this the the icon looking like a large letter A. Select it and in the form box, draw the label just to the left of the Gallons box. You can leave the name as 'Label1', but change the 'Caption' field to 'Volume'. Create a label for the other box and change its caption to 'Total Cost'. And save again.

Now we need buttons, three of them. The tool for this looks like a small button. Select this and draw one button just under the boxes. Make it kind of large. Change its Caption property to 'Press to Pump'. Its Name should be 'Pump'. Make two more smaller button below the pump button. One should have a Name and Caption of 'Reset' and the other should have a Name and Caption of Exit. And Save again.

All the form elements are in place now. So we start adding code. Simplest one first. Double click on the 'Exit' button. A window will open up and have text in it that looks like:

Private Sub Exit_Click()

End Sub
Between those two line, you add lines so it looks like this:
Private Sub Exit_Click()
    End
End Sub
Close this little window and Save. Double click on the 'Reset' button and change the code that looks like:
Private Sub Reset_Click()

End Sub
to be
Private Sub Reset_Click()
    Gallons.Text = 0
    Cost.Text = 0
End Sub
Now on to the Pump button. Double click again and change
Private Sub Pump_Click()
 
End Sub
to
Private Sub Pump_Click()
    Dim curGals As Single
    Dim curCost As Single
 
    curGals = Val(Gallons.Text)
    curCost = Val(Cost.Text)
    Gallons.Text = curGals + 1
    Cost.Text = Format((curCost + 1.52), "Fixed")
End Sub
And Save again.

If everything happened correctly, you should be able to run the program now. Under the 'Run' menu, select 'Start'. Or you could press the F5 function key. The window you made should show up and you can click on buttons to see what happens.

And that's it. Follow the deliverables instructions below and your done. Feel free to play with the controls and properties to see what happens. Best to do this on a copy though. Here is a picture of what the form should look like. Yours does not have to be exactly like this but it should be similar. lab 1 picture

Deliverables:

  1. Print, fill out and attach the cover sheet.
  2. Source Printout. There are two parts to this section of a project. The first is a printout of the form or forms that make up your program. The second is the printout of your code. Both can be generated by selecting File from the VB menu bar. The select Print. This displays a window, from which you should select to print all three kinds of information, the form image, the code and the 'form as text'.
    The caption on every form must contain your name. The source code must have your name in the comments as well as the lab name or number.
  3. Run time views. During execution, many of the results from your programs will be displayed on the screen, not printed. Most of the time the 'print form image' choice above will be fine. Sometimes you need a picture of the screen output.
    This can be done by first clicking somewhere in the window to make it the active one. Then press the <Alt><Prt Sc> keys at the same time. This will copy an image of the active window to the clipboard. Next you should open a paint application. Microsoft Paint is fine and can be run by clicking on the Start button, Select the Programs option, select the Accessories option and finally clicking on Paint. In the empty window, paste the window you copied earlier. You can now print the window. Do this separately for each window that the program opens.
  4. Any printed reports should also be handed in

Notes


ASK if you have any questions.