Using Visual Basic Macros for debugging application - skipping to next breakpoint - vb.net

I have a program running. To test this program, I need only one breakpoint. This breakpoint hits between 7 and 8 times consecutively, where I need to change a value each time it breaks.
To accomplish this I am trying to write a macros to make it easier and faster to (rather than hitting continue after changing each value), but have hit a wall. My goal is to enter all values at once and have the macros set the values in the code for each break. Is there a way to continue to the next stop within the macros code?
Any pointers would be helpful as I am not a VB expert.
Thanks

An expression is evaluated as part of the evaluation of a breakpoint condition. (Right-click the breakpoint in Visual Studio, and choose 'Condition'). This expression could call a function that you write (as part of your macro code), and within that function you could change and values that you need to change, and then return a Boolean that determines whether the breakpoint is actually hit.
Of course you could just incorporate such a function call directly into your code, and have a conditional expression with a breakpoint within the If.

Related

VBA for Access trouble picking routine to run

I’m working on a project in access with a series of existing modules. There’s amain module that runs the whole thing, but often there are errors and to troubleshoot sometimes i want to pick a specific subroutine and run that by itself. The problem is, sometimes when i click run>run sub/userform sometimes it gives me a list of subroutines to pick from and sometimes it just runs the whole thing and i can never tell which it’s going to do before i click it. Does anyone know why this could happen? Is it where I’m putting my cursor or something?
Ok, now this works?
well, any code in a code module? You can place your cursor in that code, or even in the debug window, just type in the name of the routine. So, F5 to run the code, or you can as noted even call the code in the routine from the debug window.
eg:
Call MyTestSub("John")
Or if the routine does not have any parameters, then just type into the debug window this:
MyTestSub
HOWEVER!!!
If you open code for a form? Then you can't use F5 to run that code, and if you do, then your get that prompt. The reason for this is rather complex, but a "form" represents what we call a "class object". And you can't just "run" such code, you a have to first create a instance of that class. And even more complex?
Well in theory, you can actually ahve the SAME form open 5 times!!! (and have 5 instances of the form running! So F5, or even just typing in the sub name DOES NOT work for a class module, and that includes code inside of the form.
So, how to debug such code? Well, in most cases, you have to launch the form, and then in code behind, set a break-point. Now go click the button, or whatever.
You can also in theory call + run the code in a form, and you would do it this way:
Call Forms("Test").Mytest
but, the form would have to be open. So, you can't just run code inside of a class module, or forms code module. They are "special" and work different from a standard code module. As a result, F5 to run such code does not work. In fact, the form has to be loaded first. But, even then, hitting F5 inside of forms code modules does not work. You can put in break points, and single step code (and often form events can make that debug process quite a challenge).

VBA pass UDF instantly like WorksheetFunctions during step-through

I was wondering if there was a way to pass UDF's instantly instead of "Entering" the function during step-through debugging. I commonly use functions that I know are fully working, and I often don't want to enter each one when I'm debugging. This is even more annoying when you pass multiple functions as arguments and have to enter each one before you get a return.
This question came from me frequently using things such as Application.WorksheetFunction.functionName and wanting to create a function that did the same exact thing and would also pass instantly, but with a shorter name.
Is there an option in VBA or perhaps an Application.Setting or Option Setting that I could use for this? The difficulty here would be that I only want this on some functions, not all..
Thank you
1) Put a breakpoint after your function as shown below:
2) Debug using F8 till the line with "myFunction".
3) Press F5 to jump to the breakpoint (by executing the current code).
You can put multiple breakpoints and jump multiple times to the next breakpoint using F5 in your code.

Debug function altough macros disabled

I was given a template for report (.dotm) with alot of vba code behind that gets data from a mssql database and writes the data at some bookmarks.
Unfortunately, the code has an error and I have to fix it.
Since I have never done vba before, I'm a bit lost.
There is a function with 2 parameters that does everything.
Can you tell me how I can debug this function?
I have set a breakpoint to the first line but how can I tell word(?) to execute the function?
My first approach was to add a button and set the onclick event to this function. But unfortunately macros are disabled by our policy and this doesn't work :(
Can you please help me out how I can get inside this function?
How can anyone expect the code in the template to work if macros are disabled?
Try ALT+F11 to get into the VBA environment and show the code. Put the cursor in the code you want to debug and press F8 to step into it or F5 to run it to any breakpoint.. If the code you want to debug has parameters, you have to write a dummy Sub to call the function with test-parameters.
Also, see sams comment about the trust center. Maybe you can change the settings yourself to allow macros.

VBA - Set Property in Subroutine to Automatically Step Over While Debugging

This question is specifically regarding the property get/let code in a class module but I think that the solution will be applicable to any subroutine.
There must be a property that tells vba to step over a function in break mode automatically (even when pressing the step into key/F8). Obviously such a thing exists for built in VB subs, classes and functions since the debugger doesn't step into them but I can't find a way to apply it to my code. What is it?!
It will make my life much easier when debugging.
Along with Shift+F8, there is also a button on the Debug toolbar.
Bonus Round:
If you forget to press Shift, and end up inside of the class anyway, you can Step Out by pressing Ctrl+Shift+F8
And go backwards by right clicking on the line you want to go back to and selecting "Set Next Statement".
One last note, the reason the debugger doesn't step into the "built in" classes is because that code is not written in VBA. It is hidden behind the COM Interop wall and written in an entirely different language all together.
If I understand correctly what you're asking, you need to step over instead of step into.
Try Shift+F8 instead of just F8.

VB.NET Editor - invoking View.ShowSmartTag on newly typed code without having to leave the current line and come back

In C#, I can invoke View.ShowSmartTag (which I have bound to a hotkey) on a line as I am typing it. For example, if I type
var x = new Regex
I can immediately hit my hotkey, add the missing 'using System.Text.RegularExpressions', and continue typing.
In VB.NET, if I do the same thing
Dim x = new Regex()
I can't invoke the smart tag unless I leave the line and come back to it. This is annoying not only because of the extra keystrokes and time it takes, but also because it means I don't get intellisense on the function I am using until I do it.
Is there a way to make the VB.NET editor behave more like the C# editor in this case, and allow the use of smart tags on the line that I am currently typing?
Edit:
Perhaps a macro that automatically moves the cursor down, then back up, and then displays the smart tag?