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:


  1. Create a new Visual Basic project.

  2. Change the caption of the form to "The Mood Bar".

  3. Create a label that says, "Enter your mood: 1-10".

  4. Choose a color and font for your label.

  5. Create a text box, remove the text and change the name of it to txtMood.

  6. Create a visual scroll bar.

  7. Name it vsbMood.

  8. Change the MAX property of the scroll bar to 1.

  9. Change the MIN property to 10.

  10. Note: normally you would do the reverse, set MIN to 0, but it will look better this way....

  11. Make a command button. Name it Presto!

  12. Place 10 pictures on your form. Use the default names: picture1, picture2, and so on.

  13. Change the visible property of each to false.

  14. Code the command button (presto!):
    vsbMood.value=val(txtMood)
    if vsbMood.value=1 then
    picture1.visible=true
    end if
  15. Repeat the if statements for each possiblity: 1=picture1, 2=picture2, and so on.

  16. Code the clear button (presto!):
    vsbMood.value=1
    txtMood = ""
    picture1.visible=false
    picture2.visible=false
    (repeat for each picture)
  17. Test and run your program!.



    << Back to Skyline