+ Reply to Thread
Results 1 to 14 of 14

Is the debugger lying to me?

  1. #1
    Registered User
    Join Date
    01-26-2010
    Location
    Dunedin, New Zealand
    MS-Off Ver
    Excel 2007
    Posts
    7

    Is the debugger lying to me?

    I have a class, "OB3Slide", which has a sub "addText(sText as String)".

    Please Login or Register  to view this content.
    The debugger stops with the entire last line highlighted in yellow, and the error:

    Please Login or Register  to view this content.
    If I then press F8, it immediately steps into the 'addText' sub which works perfectly fine. But it interrupts the program to tell me what appears to be a non-error.

    Has anybody else experienced anything like this?
    Last edited by Moochoopork; 01-05-2012 at 03:48 AM.

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Is the debugger lying to me?

    It might be the code that is in the addText sub, can you post this? The debugger will not highlight errors in custom classes.

  3. #3
    Registered User
    Join Date
    01-26-2010
    Location
    Dunedin, New Zealand
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Is the debugger lying to me?

    The addText sub just calls this space-saving array addition method:

    Please Login or Register  to view this content.
    which is able to be stepped through without any problems...

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Is the debugger lying to me?

    This doesn't look right:

    Please Login or Register  to view this content.
    shouldn't it be:
    Please Login or Register  to view this content.
    Though I don't know what you are doing

  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,552

    Re: Is the debugger lying to me?

    I don't know anything about class modules but is it acceptable to have a subroutine which is the same as a VBA reserved word? The Add method is defined in the VBA Help as:

    Add Method (Visual Basic for Applications)

    Adds a member to a Collection object.

    Syntax

    object.Add item, key, before, after

    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


  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Is the debugger lying to me?

    It's generally not a good idea, though it raises the question of why you aren't using a collection anyway MoochooPork. Seems like it may be a better object for you as you don't need to redim preserve

  7. #7
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Is the debugger lying to me?

    I doubt it is related to the issue in hand, but it is not good practice to use Dim ... As New ... in my opinion. Declare in one line and initialise explicitly when you want to create the object.
    Just my 2c.

    PS As regards the class, you can call the routines whatever you like really (subject to naming rules): since you will need to call them as methods of the object in question, there is no confusion for the compiler. In many ways it is good practice to use the sort of syntax that people are familiar with - such as using Add if you have created your own collection class, as an example.
    Good luck.

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Is the debugger lying to me?

    Yep, you should initialise it separately as above you can then check where it is initialise, you can't if you create it at the beginning of the code (because it is created then)

  9. #9
    Registered User
    Join Date
    01-26-2010
    Location
    Dunedin, New Zealand
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Is the debugger lying to me?

    Wow thanks guys! I'm most experienced with C-family languages and while I spent a lot of time in VB6 back in the day, I've done bugger-all VBA and I find it the most different language I've come across (it's been about 13 years since I touched VB).

    I'm essentially trying to loop through all the Slides in a PPT presentation, then loop through all the Shapes on the Slide, and create an instance of my class using the information derived from the Shapes.

    I would have expected this to work:

    Please Login or Register  to view this content.
    but VBA doesnt seem to create a NEW OB3Slide each time, it keeps the old one. It doesn't matter if I put the "Dim oSlide as OB3Slide" line before the loop, or "Dim oSlide as new OB3Slide" inside the first loop. It's damn annoying, and goes against everything I've learnt about programming... guess that's what you get for using a non-OO language. I wish MS would give us something better than VB6 to use behind Office.

    Kyle123: Thanks for pointing out the missing "set", but it didnt change a thing However, I'll now go and change my array to a collection - I wasn't aware such a thing existed.

    TMShucks: Scope will determine when VBA will use the Collection.Add() method versus my Module1.add() method.

    Thank you all very much
    Last edited by Moochoopork; 01-05-2012 at 06:59 PM.

  10. #10
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Is the debugger lying to me?

    I cannot see how that code would run or compile since you are trying to use an array as a Collection (arrays do not have methods such as Add).

  11. #11
    Registered User
    Join Date
    01-26-2010
    Location
    Dunedin, New Zealand
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Is the debugger lying to me?

    OnErrorGoto0: I'm not calling MyArray.add(value), I'm calling add(MyArray, value). "add" is a method I've written myself.

  12. #12
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Is the debugger lying to me?

    In the code you just posted
    Please Login or Register  to view this content.
    but oOB3Slides is an array.

  13. #13
    Registered User
    Join Date
    01-26-2010
    Location
    Dunedin, New Zealand
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Is the debugger lying to me?

    *doh* lol my bad.. line should have read:
    Please Login or Register  to view this content.
    Nice catch

  14. #14
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Is the debugger lying to me?

    From what it looks like you're doing, you want something like:

    Please Login or Register  to view this content.
    The collection will then hold that instance of the class, leaving you to create a new instance in each iteration
    Last edited by Kyle123; 01-06-2012 at 05:24 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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