Objectives:
- Working with the Vertical Scroll Bar
|
The Visual Basic Mood Bar
Today you will learn how to use the vertical scroll bar and combine it with if statements! The idea is that the user will input his mood. Depending on what number he inputs, a different picture will show up alongside the scrollbar. This is how it works:
- Create a new Visual Basic project.
- Change the caption of the form to "The Mood Bar".
- Create a label that says, "Enter your mood: 1-10".
- Choose a color and font for your label.
- Create a text box, remove the text and change the name of it to txtMood.
- Create a visual scroll bar.
- Name it vsbMood.
- Change the MAX property of the scroll bar to 1.
- Change the MIN property to 10.
- Note: normally you would do the reverse, set MIN to 0, but it will look better this way....
- Make a command button. Name it Presto!
- Place 10 pictures on your form. Use the default names: picture1, picture2, and so on.
- Change the visible property of each to false.
- Code the command button (presto!):
vsbMood.value=val(txtMood)
if vsbMood.value=1 then
picture1.visible=true
end if
- Repeat the if statements for each possiblity: 1=picture1, 2=picture2, and so on.
- Code the clear button (presto!):
vsbMood.value=1
txtMood = ""
picture1.visible=false
picture2.visible=false
(repeat for each picture)
- Test and run your program!.
<< Back to Skyline
|