• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 158
  • Last Modified:

Add a numeric value using a scrollbar

I would like to know if someone can help please.
I need to add a scroll bar to a application.  When the scroll bar is advanced or decreased it should add a value to a text box and after each increased click it will increase that number by 50 and for each decreased click it will decrease the value by 50.   This textbox.text  value will have a maximum of 5000 and a minimum of 0.

Thanks for your time with this question
Deborah
0
Webgrrl
Asked:
Webgrrl
  • 8
  • 6
  • 5
1 Solution
 
Erick37Commented:
When you say "clicked" do you mean clicked anywhere on the scrollbar?  And the value (50) that is added does not correspond with the scrollbar's value (or position) in any way?
0
 
orbitaltechCommented:
This is very generic and in no way does it attempt to move the position of the scroll bar, but it does show you just how to accomplish what you want. ( I like for people, as well as myself, to learn as much as possible)


On a form, insert a textbox control and a Vertical scroll bar.

Double click on the scroll bar or from the code select the VScroll1_Change() sub.

In VScroll1_Change() place this code:

Static theNumber

theNumber = theNumber + 50
Text1.Text = theNumber

Static will make your variable 'remember' what the value was after the execution of the sub.

If you need mroe help shoot out a comment and I will go into more detail

 - Much Luck
0
 
WebgrrlAuthor Commented:
orbitaltech

Thanks

One more question.  

Can this be customized so that the start position of the scroll is = to 0 and the max scroll length is = to 5000.   So when the scroll moves either way it may increase or decrease.

Thanks for such a quick response.

Deborah
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
WebgrrlAuthor Commented:
Edited text of question.
0
 
Erick37Commented:
Why not use:

Private Sub Form_Load()
    With VScroll1
    .Min = 0
    .Max = 5000
    .LargeChange = 50
    .SmallChange = 50
    End With
End Sub

Private Sub VScroll1_Change()
    Text1.Text = CStr(VScroll1.Value)
End Sub
0
 
orbitaltechCommented:
From Microsoft. This should help you discover the scrollbar controls.

This example changes the size of a Shape control to correspond to the value of a horizontal scroll bar (HScrollBar) as you drag the scroll box on the scroll bar. To try this example, paste the code into the Declarations section of a form that contains a Shape control, a Label control, and an HScrollBar control. Set the Index property for the Shape control to 0 to create a control array. Then press F5 and move the scroll bar.

Private Sub Form_Load ()
   ' Move and size the first Shape control.
   Shape1(0).Move HScroll1.Left, HScroll1.Top * 1.5, HScroll1.Width, HScroll1.Height
   Label1.Caption = ""   ' Set the Label caption.
   Load Shape1(1)   ' Create the second Shape.
   ' Move and size the second Shape control.
   Shape1(1).Move Shape1(0).Left, Shape1(0).Top, 1, Shape1(0).Height
   Shape1(1).BackStyle = 1   ' Set BackStyle to Opaque.
   Shape1(1).Visible = True   ' Display the second Shape.
   HScroll1.Min = 1   ' Set values of the scroll bar.
   HScroll1.Max = HScroll1.Width
End Sub

Private Sub HScroll1_Change ()
   Label1.Caption = "Changed"   ' Display message after change.
End Sub

Private Sub HScroll1_Scroll ()
   Shape1(1).BackColor = &HFF0000   ' Set Shape color to Blue.
   Label1.Caption = "Changing"   ' Display message while scrolling.
   Shape1(1).Width = HScroll1.Value ' Size Shape to Scroll Value.
End Sub

0
 
orbitaltechCommented:
Erick37's answer will work as well..
0
 
WebgrrlAuthor Commented:
Orbitaltech & Erik37

Thanks for making my first time here such a rewarding experience.  Your help has been greatly appreciated.  

I hope you are around for my future learnings. *smile*

Deborah
0
 
Erick37Commented:
If you need to keep the values in even multiples of 50 when dragging the scrolltab use:

Private Sub VScroll1_Change()
    VScroll1.Value = (VScroll1.Value \ 50) * 50
    Text1.Text = CStr(VScroll1.Value)
End Sub
0
 
WebgrrlAuthor Commented:
Thanks very much.
0
 
Erick37Commented:
You're welcome.
Thanks :-)
0
 
WebgrrlAuthor Commented:
This worked great except for one small thing.

When a number is manually entered into the text1.text and the scroll bar is used it removes that value and starts over.  How can I get it to add onto the entered value.   eg.   If the text1.text value has a manual entry of 25 and the scroll is then increased I require it to add to the previous value or decreases if the scroll bar is decreased.

Thanks

webgrrl
0
 
WebgrrlAuthor Commented:
This worked great except for one small thing.

When a number is manually entered into the text1.text and the scroll bar is used it removes that value and starts over.  How can I get it to add onto the entered value.   eg.   If the text1.text value has a manual entry of 25 and the scroll is then increased I require it to add to the previous value or decreases if the scroll bar is decreased.

Thanks

webgrrl
0
 
orbitaltechCommented:
Add this to your form. Type in a number under the Scrollbar min and Over the scroll bar max and watch.

Private Sub Text1_Change()
   
   If Val(Text1.Text) > VScroll1.Max Then
      MsgBox "Over the Scroll bar maximum"
      VScroll1.Value = VScroll1.Max
      Text1.Text = VScroll1.Max
      Exit Sub
   ElseIf Val(Text1.Text) < VScroll1.Min Then
      MsgBox "Under the Scroll bar minimum"
      VScroll1.Value = VScroll1.Min
      Text1.Text = VScroll1.Min
      Exit Sub
   Else
      VScroll1.Value = Val(Text1.Text)
   End If
     
End Sub
0
 
orbitaltechCommented:
Oops... The Exit sub's are not required
0
 
WebgrrlAuthor Commented:
Thanks a million  that did the trick.  
I owe you one : )
0
 
orbitaltechCommented:
You are very welcome...
0
 
Erick37Commented:
Private Sub Form_Load()
    With VScroll1
    .Min = 0
    .Max = 5000
    .LargeChange = 50
    .SmallChange = 50
    End With
    Text1.Text = "0"
End Sub

Private Sub Text1_Change()
    Dim lVal As Long
    With VScroll1
    lVal = Val(Text1.Text)
    If (lVal < .Min) Then
        .Value = .Min
        Exit Sub
    End If
    If (lVal > .Max) Then
        .Value = .Max
        Exit Sub
    End If
    .Value = lVal
    End With
End Sub

Private Sub VScroll1_Change()
    Text1.Text = CStr(VScroll1.Value)
End Sub
0
 
WebgrrlAuthor Commented:
Thanks Erik37

Thats great.  You have been a big help.

Regards

Webgrrl
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 8
  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now