Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Scrolling help

Posted on 2003-10-28
8
Medium Priority
?
164 Views
Last Modified: 2010-05-03
I have an application that displays a map, but the map is too big, so there is a scroll bar on the botton to scroll left and right.  Is there a way I can assign Left and Right buttons to perform the same function as clicking on the arrows?


Thanks
0
Comment
Question by:sewoo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
8 Comments
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9639916
Try this:

Before using this, be sure to set the form's keypreview property to true.

--------------------------------------------------------------------------------------
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
   
    If KeyCode = vbKeyLeft Then                                           'if left pressed
        If HScroll1.Value > 99 Then                                            'prevent the value to be negative
            HScroll1.Value = HScroll1.Value - 100                            'reduce the hscroll value
        End If
    End If
    If KeyCode = vbKeyRight Then                                         'if right pressed
        If HScroll1.Value < 10000 Then                                       'prevent the value to be to o big
            HScroll1.Value = HScroll1.Value + 100                           'enlarge the hscroll value
        End If
    End If
       
End Sub
-------------------------------------------------------------------------------------------------------

After that you should adjust the values in that code to fit your needs.


0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9639935
Maybe I misunderstood your question.
Maybe you were refering to mouse buttons.

if this is the case then use this

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   
    If Button = 1 Then
        If HScroll1.Value > 99 Then
            HScroll1.Value = HScroll1.Value - 100
        End If
    End If
    If Button = 2 Then
        If HScroll1.Value < 10000 Then
            HScroll1.Value = HScroll1.Value + 100
        End If
    End If

End Sub

Note that mouse doesnt have the repeat function when holding a button. so this code wil execute only once when clicked.
You can make it repeat by using timer(s). I'll try to do it also.
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9639964
This is the version with timers.

Create two timers, set their interval to 10 (or try what value gives the best bahaviour) and set their enabled property to false.   One timer is used to scroll left, and other to scroll right

Assign this code to timers and Forms mousedown and mouseup events accordingly.

Theory:
When mouse button is pressed, program checks which button is pressed, and according to the button number, activates the timer. Then the timer executes its code until the button is released.
When the button is released, program checks which it was, and deactivates the timer which was activated by that number

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then Timer1.Enabled = True
    If Button = 2 Then Timer2.Enabled = True
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then Timer1.Enabled = False
    If Button = 2 Then Timer2.Enabled = False
End Sub

Private Sub Timer1_Timer()                                     'scroll left
        If HScroll1.Value > 99 Then
            HScroll1.Value = HScroll1.Value - 100
        End If
End Sub

Private Sub Timer2_Timer()                                     'scroll right
        If HScroll1.Value < 10000 Then
            HScroll1.Value = HScroll1.Value + 100
        End If
End Sub
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:dbrckovi
ID: 9640016
Above code works but is still buggy.   When you press both buttons at the same time, picture shakes left and right.

Use this code to repair this:

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
        If Timer2.Enabled = True Then Timer2.Enabled = False: Exit Sub      'if another timer is already active then it means that another button is already pressed, and therefore deactivate it
        Timer1.Enabled = True
    End If
   
    If Button = 2 Then
        If Timer1.Enabled = True Then Timer1.Enabled = False: Exit Sub
        Timer2.Enabled = True
    End If
End Sub


Sorry that I used multiple comments to work throug this problem. It's becouse ideas came to me when I already posted a comment.
0
 

Author Comment

by:sewoo
ID: 9640052
Thanks for the ideas, I'll give it a try tomorrow, but what I mean was the application has a command button called left and one called right, so I wanted to make it so that if I click on the button called "left" the screen scrolls left and if I click on "right" the screen scrolls right.
0
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 10390451
PAQed, with points refunded (250)

PashaMod
Community Support Moderator
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

722 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