Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
How to use debugger
I have got my code for a user form working now. It has no technical code
errors but I think one of the conditions in an if statement may be selecting incorrect cells. How can I check the values of different variables whilst it is running. I realise I could set up the code so it puts variables in set cells for checking but is there an easier way. I noticed when it took me to debugger when i was getting code errors before if i held my mouse over the variable names it would give me the current value. This is what I would like to be able to get. Can I get this without deliberately putting in code errors. |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
How to use debugger
You can set break points and step through the code. You can add a watch to
variables. Set Break Point - click on line and press F9 step through code - Press F8 See value of variables Hover over the variable or add watch by highlighting a variable and right click. then select Add Watch It is easy todebug code by using intermediate variables. instead of function Myfunction(V1 as Integer,V2 as Integer,V3 as Integer) Myfunction = V1 + V2 / V3 end function Use function Myfunction(V1 as Integer,V2 as Integer,V3 as Integer) Myfunction = V1 + V2 Myfunction = Myfunction/ v3 end function Note the two functions give differnt results since multiplication is performed before addition Should be function Myfunction(V1 as Integer,V2 as Integer,V3 as Integer) Myfunction = V2/V3 Myfunction = V1 + V3 end function "NDBC" wrote: I have got my code for a user form working now. It has no technical code errors but I think one of the conditions in an if statement may be selecting incorrect cells. How can I check the values of different variables whilst it is running. I realise I could set up the code so it puts variables in set cells for checking but is there an easier way. I noticed when it took me to debugger when i was getting code errors before if i held my mouse over the variable names it would give me the current value. This is what I would like to be able to get. Can I get this without deliberately putting in code errors. |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
How to use debugger
Yes, you can either put a
STOP command just ahead of any line of code you would like to examine and the code will run to that point and then open up the debugger with the Stop highlighted. You can then press [F8] to continue line by line through your code - or press [F5] to continue running normally (until the next Stop command or breakpoint). Instead of the Stop command you may also insert a breakpoint, which serves the same purpose. To insert a breakpoint, click in the gray border to the left of the line of code you want to stop at. A red dot will appear indicating the breakpoint. You can do this from the Debug option of the menu also. In the debugger there is also an "Immediate" window available - if you don't see it, it can be made visible from the View menu item. You can use the immediate window to execute commands, show you values and things like that. Let's say you want to know the value of variable myNumber, as you noted, you could hover over it and see it, but in the Immediate window you could type: ? myNumber (? being old BASIC shorthand for Print) and the value of myNumber will appear in the Immediate window. Also, in your code, you can put a command like Debug.Print myNumber and at that point, the code will write the value of myNumber into the Immediate window for examination later thru use of a Stop command or breakpoint. Hope this helps. "NDBC" wrote: I have got my code for a user form working now. It has no technical code errors but I think one of the conditions in an if statement may be selecting incorrect cells. How can I check the values of different variables whilst it is running. I realise I could set up the code so it puts variables in set cells for checking but is there an easier way. I noticed when it took me to debugger when i was getting code errors before if i held my mouse over the variable names it would give me the current value. This is what I would like to be able to get. Can I get this without deliberately putting in code errors. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Can't turn off visual basic debugger in Excel 2003 | Excel Discussion (Misc queries) | |||
.show starts debugger upon window change | Excel Discussion (Misc queries) | |||
No Backspace key in VBA Debugger Help | Setting up and Configuration of Excel | |||
how do i turn off debugger and script editing | Excel Discussion (Misc queries) |