back
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 vbsMood
  • 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...
  • Change the visible property of each to false
  • Code the command button (presto!):
    vbsMood.value=val(txtMood)
    if vbsMood.value=1 then
    picure1.visible=true
    end if
  • Repeat the if statements for each possiblity: 1=picture1, 2=picture2, and so on.
  • Create a clear button that sets vbsMood.value=1 and turns the visible property of each picture to false
  • Test and run your program!