Solved

Scrolling help

Posted on 2003-10-28
8
156 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA open file from excel cell 4 36
Prevent checkbox click event occur while editing it in vb6 8 33
How to Add / Edit Windows Menu 4 51
Problem to With line 4 41
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 …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

910 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

22 Experts available now in Live!

Get 1:1 Help Now