How to step into VB.NET class code - vb.net

I am debugging a VB.NET forms program which calls into properties and methods of a class which is part of the same project.
I put a break point in the form code but when I step through, it does not step into the class code.
Am I missing a setting?

Pressing F11 will take you into the method definition. F10 will step over. F5 will jump to the next break point. Or simply continue with the execution of your application until the application meets another break point on it's execution path.
This can can also be achieved by using actions located on the toolbar and in the context menu when using right click.

Make sure that you are pressing Step Into, not Step Over.

Related

How to step through VBA code behind a form? VBA error 2186: This property isn't available in Design view

I can run a macro under forms, but when I look at the code behind the form, I am not able to step through it all.
I hit the line
Dat = [Forms]![frmMenu]![dtmDate]
and get the error:
Is there a way to resolve this so I can continue to test each step of the macro?
I opened the code with ALT + F11.
I am trying to pinpoint the queries which cause the macro to take so long to run.
You can't hit f5 to run + debug code in a form. You can do this for a standard code module, but not for what we call a class module.
If you wish to debug/step code in a form? Launch the form (normal view). Then go to the code behind, say a button click, and now you can set a break-point.
So, single step, or debug of forms code requires you FIRST load the form as normal. (you can't thus use f5 to run such code). But, you CAN debug as per above.

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).

Stop button in LabVIEW cannot be pressed during while loop execution inside an event structure

I am currently working on a LabVIEW project and have found myself stuck on how to make a while loop exit when I press the abort (stop) button. For a simple while loop I understand how to do this - but the problem is that this while loop is nested inside of an event structure and I'm guessing that the button cannot be pressed while the loop is executing. Attached here is a picture of part of my code (that contains this specific event case which is causing me problems): To spend a little more time explaining what the problem is - I think the code is doing what I want it to do (namely output a set of commands in a repeated cycle with a wait timer) but I cannot stop the code mid cycle (pressing the abort button with my mouse does nothing - as in the button doesn't show it being pressed and the indicator shows no change, I also can't use any other functionality of my program during the cycle which I'm assuming is related). And I do not want to stop the LabVIEW program from running entirely - just the code inside the while loop pictured above. This is what the front panel is configured too for completeness:
Essentially what I want to happen is the while loop to execute when I press DWG and in the middle of the cycle be able to abort it. Sorry if my code seems a little messy. Additionally, I've tried the same code with a for loop originally (via a conditional terminal so it could stop early) and that didn't work either. Thanks for any help I appreciate it!
Your problem is that inside the event structure, by default the UI is frozen so no UI actions (keyboard/mouse/etc) are processed until you exit that frame.
Option 1. You can right click the Event Structure and select "Edit events handled by this case" dialog and then uncheck the "Lock panel" checkbox -- that will allow the UI to be live while you are in that frame. I do not recommend this solution generally unless you have an extremely simple user interface because it leads to the user being able to change controls without the events behind those controls being processed (not a good UI experience for users). But if the UI is simple enough, that works.
Option 2. You can create a user event that is the code you want inside your While Loop. When the Deg Wait Go button is pressed, use the "Generate User Event" node to trigger that event. Do the same thing in the user event case so that the event re-triggers itself if and only if the Abort button has not been pressed.
Option 3. Create a separate loop OUTSIDE your UI loop that does your processing with some sort of command queue running between the UI loop and that other loop. The other loop moves into various states at the request of the UI loop... it's the one that does nothing until it receives a "go" message and then keeps looping until it receives a "stop" message. You can Google "queued message handler" for extensive details of this solution. This is the most common solution for complex UI requirements, especially useful for separating concerns of the UI code from the execution code.

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.

cannot step into code access

Using Access 2010 I cannot step into the code I have written for a form in Access.
Shouldn't I be able to step through it using the F8 key?
Does this indicate a damaged install of Access?
There are several conditions required for F8 to work.
You cannot be in a forms code module and hit F8 – it will not work since forms code is a class module.
If the code module is a class module, then again you cannot hit F8 when looking at code in that module (so a forms code module, and a code module that is a class object will not work.
Eg these:
Also if you hit F8 inside of a SUB or function that requires “parameters” then again F8 will not work. (since parameters are required).
So code in a class module will not work with F8 since you need to create an “instance” of that class object in code. Of course any routine (function/sub) that creates an instance of the class object will THEN allow F8 to step though such class object code.
And for a form, if you introduce a break line, or place a stop command in the code, then when the code runs, and encounters the breakpoint (or stop command), then at THAT point in time since a “instance” of the object exists, then F8 to single step will work.
So the difference between code/objects that must be instantiated before F8 works needs to be keep in mind.
Thus again, you can use F8 inside of forms code modules (they are class objects), but ONLY when an instance of the object (in this case a form) ahs been created and is running. So F8 can step though such code, but F8 cannot be used to start+run+debug such code until such time an instance of the object has been created.
So function/sub cannot have parameters, and cannot be in a form since such modules are class modules, and as noted you cannot use f8 inside of a class module either.
Try ALT+F11, then F8. Not my normal procedure. I found it by experimentation - pressing keys to see what happens.
You could force and error, like "mxgbox whatever" at the beginning of your class module. When VBA shows you the error message box you can click on "debug" and then continue with F8.
Bring up the VB Editor by hitting Alt+F11 then you can enter a break into any code on a code line - that way the code will stop there, and you can use F8 to step through or F5 to resume and run.
Oh, and if you don't know, you can enter a break by clicking the side panel or by pressing F9 on a particular line.