#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 204
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't turn off visual basic debugger in Excel 2003 Kennard in Albuquerque Excel Discussion (Misc queries) 1 May 3rd 09 11:07 PM
.show starts debugger upon window change Tony Excel Discussion (Misc queries) 2 March 19th 09 07:37 PM
No Backspace key in VBA Debugger Help Mac Lingo Setting up and Configuration of Excel 1 September 30th 08 01:54 AM
how do i turn off debugger and script editing CAL-KID Excel Discussion (Misc queries) 3 January 11th 07 05:36 AM


All times are GMT +1. The time now is 06:09 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"