I have a class, "OB3Slide", which has a sub "addText(sText as String)".
The debugger stops with the entire last line highlighted in yellow, and the error:Dim x as new OB3Slide dim sTemp as string sTemp = extractText(oShape) x.addText sTemp
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.Runtime error '438' Object doesn't support this property or method
Has anybody else experienced anything like this?
Last edited by Moochoopork; 01-05-2012 at 02:48 AM.
It might be the code that is in the addText sub, can you post this? The debugger will not highlight errors in custom classes.
Click the * below to say thanks
Girls sleep with guys who use photoshop, but marry the ones who work with Excel
Corduroy pillows: They're making headlines!
Did you mean: recursion
http://www.google.com/search?hl=en&q=recursion
The addText sub just calls this space-saving array addition method:
which is able to be stepped through without any problems...Private Sub add(theArray, theValue) On Error GoTo err If (UBound(theArray) = 0) Then theArray(0) = theValue Else ReDim Preserve theArray(UBound(theArray) + 1) theArray(UBound(theArray)) = theValue End If Exit Sub err: ReDim theArray(0) theArray(0) = New OB3Slide Set theArray(0) = theValue End Sub
This doesn't look right:
shouldn't it be:err: ReDim theArray(0) theArray(0) = New OB3Slide Set theArray(0) = theValue End Sub
Though I don't know what you are doingerr: ReDim theArray(0) Set theArray(0) = New OB3Slide Set theArray(0) = theValue End Sub
Click the * below to say thanks
Girls sleep with guys who use photoshop, but marry the ones who work with Excel
Corduroy pillows: They're making headlines!
Did you mean: recursion
http://www.google.com/search?hl=en&q=recursion
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
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
Click the * below to say thanks
Girls sleep with guys who use photoshop, but marry the ones who work with Excel
Corduroy pillows: They're making headlines!
Did you mean: recursion
http://www.google.com/search?hl=en&q=recursion
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.
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)
Click the * below to say thanks
Girls sleep with guys who use photoshop, but marry the ones who work with Excel
Corduroy pillows: They're making headlines!
Did you mean: recursion
http://www.google.com/search?hl=en&q=recursion
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:
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.Dim oOB3Slides() as OB3Slide Dim oThisSlide as OB3Slide For each oSlide in ActivePresentation.Slides set oThisSlide = new OB3Slide For Each oShape in oSlide.Shapes ... set oThisSlide's properties ... next oShape ... add oThisSlide to oOB3Slides ... next oSlide
Kyle123: Thanks for pointing out the missing "set", but it didnt change a thingHowever, 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 05:59 PM.
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).
Good luck.
OnErrorGoto0: I'm not calling MyArray.add(value), I'm calling add(MyArray, value). "add" is a method I've written myself.
In the code you just posted
but oOB3Slides is an array.oOB3Slides.add(oThisSlide)
Good luck.
*doh* lol my bad.. line should have read:
Nice catchadd oOB3Slides, oThisSlide![]()
From what it looks like you're doing, you want something like:
The collection will then hold that instance of the class, leaving you to create a new instance in each iterationSub kyle() Dim oThisSlide As Slide Dim oShape As PowerPoint.Shape Dim oOB3Slides As Collection Dim oCustom As oOB3Slide Dim x As Integer Set oOB3Slides = New Collection For Each oThisSlide In ActivePresentation.Slides For Each oShape In oThisSlide.Shapes Set oCustom = New oOB3Slide With oShape oCustom.Something = .TextFrame.TextRange.Text 'assign other stuff to the class End With oOB3Slides.Add oCustom Next oShape Next oThisSlide For x = 1 To oOB3Slides.Count Debug.Print oOB3Slides(x).Something Next x End Sub
Last edited by Kyle123; 01-06-2012 at 04:24 AM.
Click the * below to say thanks
Girls sleep with guys who use photoshop, but marry the ones who work with Excel
Corduroy pillows: They're making headlines!
Did you mean: recursion
http://www.google.com/search?hl=en&q=recursion
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks