Solved

Add a numeric value using a scrollbar

Posted on 2000-03-05
19
141 Views
Last Modified: 2010-05-02
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
Comment
Question by:Webgrrl
  • 8
  • 6
  • 5
19 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 2585386
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
 
LVL 2

Expert Comment

by:orbitaltech
ID: 2585400
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
 

Author Comment

by:Webgrrl
ID: 2585414
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
 

Author Comment

by:Webgrrl
ID: 2585433
Edited text of question.
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 50 total points
ID: 2585436
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
 
LVL 2

Expert Comment

by:orbitaltech
ID: 2585438
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
 
LVL 2

Expert Comment

by:orbitaltech
ID: 2585441
Erick37's answer will work as well..
0
 

Author Comment

by:Webgrrl
ID: 2585461
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
 
LVL 32

Expert Comment

by:Erick37
ID: 2585464
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Webgrrl
ID: 2585465
Thanks very much.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2585471
You're welcome.
Thanks :-)
0
 

Author Comment

by:Webgrrl
ID: 2585532
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
 

Author Comment

by:Webgrrl
ID: 2585543
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
 
LVL 2

Expert Comment

by:orbitaltech
ID: 2585554
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
 
LVL 2

Expert Comment

by:orbitaltech
ID: 2585557
Oops... The Exit sub's are not required
0
 

Author Comment

by:Webgrrl
ID: 2585580
Thanks a million  that did the trick.  
I owe you one : )
0
 
LVL 2

Expert Comment

by:orbitaltech
ID: 2585595
You are very welcome...
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2585604
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
 

Author Comment

by:Webgrrl
ID: 2585859
Thanks Erik37

Thats great.  You have been a big help.

Regards

Webgrrl
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now