+ Reply to Thread
Results 1 to 8 of 8

debug modes learning

  1. #1
    Forum Contributor
    Join Date
    02-12-2011
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    261

    debug modes learning

    Hi All

    I am trying to understand what these debug modes are all about, i Know its very essential in a coding which will help us.
    But some one can tel me where and how we should use this. I have a long list of queries out of which few are.

    Debug.print
    debut.assert
    Immediate window. (I know this is something which we use to see immediate results for your coding)

    My code is below. which is a very small programme. where it just shows left,right of a string in the cells. MY query is where i can use the above two to options(debut print and debug asser) and understand how it helps. what is that in the immediate window should i type / paste to see the immediate results. have read articles from cpearsons, but while it comes to my coding i am confused.

    Please Login or Register  to view this content.
    Last edited by grkchakri; 11-17-2013 at 01:19 AM.

  2. #2
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: debug modes learning

    Perhaps the link below will help

    http://www.cpearson.com/excel/DebuggingVBA.aspx
    If my solution worked (or not) please let me know. If your question is answered then please remember to mark it solved

    Computers are like air conditioners. They work fine until you start opening windows. ~Author Unknown

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: debug modes learning

    Debug.Print just displays the contents of a variable or a cell.

    Debug.Assert can be used to test a variable or cell and cause the code to stop. I must admit to never having used this ... And you certainly wouldn't want to leave it active in your code.

    You can see the output from Debug.Print in the Immediate Window. Press Ctrl-G to open the Immediate Window pane if it is not showing in the VBE.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: debug modes learning

    Quote Originally Posted by TMShucks View Post
    Debug.Assert .... I must admit to never having used this ... And you certainly wouldn't want to leave it active in your code.
    Snap!!!!!!!

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: debug modes learning

    @WasWodge: yes, and for a long time I didn't even know it was an option. But, even when I discovered it (I think, on Chip's web site), I have never found reason to use it. Other debug methods usually work well for me, like putting a Stop in the code, or adding a break point, and stepping through the code with F8.

    Regards, TMS

  6. #6
    Forum Contributor
    Join Date
    02-12-2011
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    261

    Re: debug modes learning

    on the First note thanks guys (TMShucks, WasWodge). Just few more clarifications.

    a) Debug.print does it work only to show values(in the immediate window) .
    b) Debug.assert just breaks the code / action at a specific point . is my understanding correct on a & b
    c) If i have some 10 lines of a code and i want to check from line 6 to 10. how to do this , Obviously if it is 10 lines it is not a problem b
    but if it is more i am sure there is a way out instead of running from line 1.

    Many thanx

  7. #7
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: debug modes learning

    a) It shows whatever you put after it (normally the result of a variable,a text string, result of a formula (see your adapted code below)).
    b) yes
    c) Can't think of a use for it but the easiest way would probably be to put in a counter to count the iterations. See x in your adapted code below.

    Please Login or Register  to view this content.

  8. #8
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: debug modes learning

    Debug.Assert is useful to break your code on a certain condition so that you may step through it. For example if your code is failing due to a condition that you don't believe must occur, or after a point in a loop, you can add a test for that:
    Please Login or Register  to view this content.
    Of course you may also achieve the same with watches or Stop statements.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Learning VBA - Suggestion for Beginners Learning Curve
    By sighlent1 in forum Excel General
    Replies: 1
    Last Post: 08-26-2010, 12:58 PM
  2. Excel 2007 : Excel 2007 Save Modes
    By ravichander in forum Excel General
    Replies: 4
    Last Post: 07-11-2008, 01:21 PM
  3. [SOLVED] switching between modes
    By Joe in forum Excel General
    Replies: 3
    Last Post: 02-09-2006, 10:00 AM
  4. switching between modes
    By Joe in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-08-2006, 12:00 PM
  5. Design/run modes for a button
    By Mike Reedich in forum Excel General
    Replies: 1
    Last Post: 04-02-2005, 11:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1