Avatar of bfuchs
bfuchs
Flag for United States of America asked on

Single key shortcut for stepping over

Hi Experts,
Is there a way to use a single keyboard key to perform the following?
Shift-F8      Step over the line by running the procedure on the current line without going into it and stepping through each line
Thanks
System ProgrammingSystem UtilitiesMicrosoft AccessVisual Basic Classic

Avatar of undefined
Last Comment
bfuchs

8/22/2022 - Mon
Martin Liss

Do you want to do this while debugging?
bfuchs

ASKER
hi,
yes.
Thanks,
Ben
Norie

As far as I know there is no single key shortcut for that but what you could is set a breakpoint on the next line of code and then press F5.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Martin Liss

In VB6 which is very similar to VBA the shortcut for stepping through was F8 (without Shift). If however you are using a Windows VM like Parallels on a Mac like i am, you may have to use Shift+F8.  You might however be able to set up a Windows shortcut for what you want to do. See my article on debugging for more information.
bfuchs

ASKER
Hi,
you could is set a breakpoint on the next line of code and then press F5.
I've constantly been debugging lot of code and not interested in stepping thru all the sub functions that are being called by the function I'm looking at, would either have to hold down the shift key all the time while pressing f8 key or perhaps find a way to have windows know that a certain key should be considered same as pressing shift+f8, that could be only while debugging or would not mind if this will be the behavior at all times...
You might however be able to set up a Windows shortcut for what you want to do
Where do you explain this in the article?

Thanks,
Ben
Martin Liss

I'm sorry that I gave the impression that my article talked about creating shortcuts; it doesn't. In any case I don't know what version of Windows you are using but maybe this article which describes how to do it Windows 10 will help you.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
bfuchs

ASKER
Hi,
I'm using Windows 7,
Saw this on google, no idea what is it talking about...
If you want take it even further, create keyboard shortcuts for quick access to Windows 7 settings. Step 1: Right-click on one of the shortcut icons you just created and select "Properties." Step 2: In the "Shortcut key:" field, type a key combination to use as a keyboard shortcut.
Thanks,
Ben
Norie

Ben

When you use F5 code execution will continue, without any stepping, until the next breakpoint.
bfuchs

ASKER
Hi Norie,

I do want be stepping thru all lines belonging to the function I am looking at, just want avoid entering sub functions, see foe example
    i = UnZip(sDownloadFolder & sLastFile, sDestinationFolder, False)
    
    If i = 0 Then
        sDestinationFolder = "C:\Application\"
        
        If Dir(sDestinationFolder & NewestFile(sDestinationFolder, "*." & sExt)) <> "" Then
            If Dir(sDestinationFolder & "Tables." & sExt) <> "" Then
                Kill sDestinationFolder & "Tables." & sExt
            End If
            Name sDestinationFolder & NewestFile(sDestinationFolder, "*." & sExt) As sDestinationFolder & "Tables." & sExt
        End If
    End If

Open in new window

I want step into all those lines, however Unzip and NewestFile which are other functions I dont step into, and prefer not having to use two keys all the time (Shift+F8).

Most of the times I end up entering unintentionally those functions, then have to use other key combinations for stepping out...

Thanks,
Ben
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Martin Liss

You can use conditional compilation as described in this article of mine to do what you want. The article is written for VB6 but using the technique for VBA is very similar. Basically you go to Visual Basic, right-click on the VBA Project in the 'Project - VBAProject' window, select 'Project Properties' and enter something like what is shown here in the 'Conditional Compilation Arguments:' box.
2018-12-04_12-20-47.pngAs long as Testing (or whatever you call it) is 1, then the following code will bypass the calling of SomeSub.
Sub test()
#If Testing Then
    ' Don't do anything
#Else
    SomeSub
#End If
End Sub
Sub SomeSub()
    MsgBox "hello"
End Sub

Open in new window


In your case that code could be simplified to this
Sub test()
#If Not Testing Then
    SomeSub
#End If
End Sub

Open in new window

I've attached a small sample project.
29128192.xlsm
bfuchs

ASKER
Hi Martin,
then the following code will bypass the calling of SomeSub.
Just to clarify, I'm not looking to bypass the executing those sub functions, just to bypass stepping thru the code line by line, exactly what shift+f8 does.
And this is from your first article above...
Step Over is similar to Step Into except that as its name implies it will step over or skip the current line. Note that it doesn't skip the execution of the line, only the stepping through. In other words if the current line is a call to a long Sub that you don't really care about, stepping over will execute the call and then pause at the line following the call.
Thanks,
Ben
Martin Liss

The only thing that I can suggest is that if you find yourself in one of the subs that you don't want to step through, click the Debug menu's 'Step Out' button.

2018-12-04_14-16-19.png
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Norie

Have you tried setting breakpoints and using F5?

For example in the code you posted you could put breakpoints on line 1 and line 3.

You could then step through the code until you reach line 1 and then press F5 to skip to line 3.
bfuchs

ASKER
Hi experts,

Have you tried setting breakpoints and using F5?
Yes, I use that occasionally when only want to start debugging from a certain point.
For example in the code you posted you could put breakpoints on line 1 and line 3.
Well normally I'm looking at much larger code, would not be practical to look thru the entire code to find where there is a function called and set there a breakpoint...
click the Debug menu's 'Step Out' button.
As mentioned, this is what I'm currently doing...

I would really prefer the creating shortcut approach that Martin mentioned above, wondering if its doable in windows 7.
 

Thanks,
Ben
Martin Liss

Assuming you can create a shortcut in Win7, what would it emulate? If it's Shit+F8 and you assign it to, say, F9, how would that prevent you from wandering into the subs you don't want to step through? I think you're asking for something to step through code line by line but intelligent enough to step over certain subs and that's not possible.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Norie

Ben

You only occasionally use breakpoints?

If you used breakpoints a bit more, along with F5, then you should be able to skip over code you don't want to step through easily.

As for searching through code for function calls, why not put a breakpoint on the function itself?
bfuchs

ASKER
If it's Shit+F8 and you assign it to, say, F9, how would that prevent you from wandering into the subs you don't want to step through?
No, I just need something to simulate the exact same behavior as shift+f8, F9 is fine.
Can you provide instructions for accomplishing that?
Thanks,
Ben
Martin Liss

So you want to F8, F8, F8,...F8 until you get to a certain sub and then press F9 and have it step over, right? If so that is exactly what you can do by pressing the Step Over item instead.

Anyhow here's a Win7 article that may help.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
bfuchs

ASKER
why not put a breakpoint on the function itself?
Not getting it.
If I have a function that is 100 lines long and have within a dozen of calls for other functions, do I have to look for them thru the entire function and place a dozen of breakpoints?
what exactly will that accomplish.
Thanks,
Ben
bfuchs

ASKER
So you want to F8, F8, F8,...F8 until you get to a certain sub and then press F9 and have it step over, right?
Not either, I just want to use f9 all the time...no switching keys and no using two keys, very simple...
Thanks,
Ben
bfuchs

ASKER
@Martin,
That link explains how to create a shortcut to particular application. see below
Right-click the desktop shortcut of the application, then click Properties > Shortcuts.
Thanks,
Ben
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Martin Liss

Not either, I just want to use f9 all the time...no switching keys and no using two keys
That's not possible.
bfuchs

ASKER
That's not possible.
So you're saying its not possible to have F9 behave like Shift+F8?
Thanks,
Ben
bfuchs

ASKER
Just to clarify, currently if I use Shift+F8 all the time while debugging, it does what I want.
My goal here is to avoid constantly having to use a combination of two keys.
Thanks,
Ben
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
bfuchs

ASKER
Actually I saw the following on the web
Step 2: Start the Keyboard wizard, and change the assignments
Open the Keyboard item in Control Panel. ...
On the Key Settings tab, select the key that you want to change.
To change the command or the program assignment, click Configure. ...
Select the appropriate options, and then follow the instructions
This looks like something we are trying to accomplish.
The problem is that there is no settings tab under my keyboard item...only tabs I see are speed and hardware-:(
Thanks,
Ben
ASKER CERTIFIED SOLUTION
Qlemo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
bfuchs

ASKER
@Qlemo,\
Caps Lock
might
apply to F8 too (making it Shift-F8)
That would have been a good idea, just a pity it does unfortunately not work-:(
Re the other options, would need some helping hands here...-:)
Thanks,
Ben
Qlemo

The latter two options need to be checked by yourself. If you use Logitech gear, look into its setup app.
Regarding AutoHotkey I can only tell it exists, but I do not use it myself.
Your help has saved me hundreds of hours of internet surfing.
fblack61
bfuchs

ASKER
@Qlemo,
I installed AutoHotKey, started looking into, but could not figure out how to do it.
It looks like you need to write a script in order to accomplish that, there is no GUI helping you.
Any idea how to write this command in a script?
See attached what I tried and error I'm getting.
Thanks,
Ben
Untitled.png
bfuchs

ASKER
Actually the following types F8 when I press F9.
F9::send +F8

Open in new window

How can I change it to refer to shift+f8?
Thanks,
Ben
bfuchs

ASKER
I got it
F9::send {shift}+{F8}

Open in new window

Thanks,
Ben
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
bfuchs

ASKER
Thanks to all participants!!