Prompts supplied while writing code don't always work?

noboffinme

Registered User.
Local time
Today, 15:48
Joined
Nov 28, 2007
Messages
288
Hi

While I write a Sub Routine, I often use some of the possible methods/properties that pop up after you add the Period (or Full Stop). This seems fine until I go to run the code & find I sometimes get errors.

What is the point of these options popping up if they’re incorrect??

I also don’t follow how the object Browser works for the same reason, & if this means I can't use the Object Browser or the pop up options to assist with writing code, what other more reliable sources are there?

I thought if the suggestion that came up as suggested by the Object Browser it should work when run, what am I missing here?

Example;

I start to write some lines of code to open a new blank Powerpoint Presentation as follows;

Option Explicit

Sub ppt_open()

‘Declare application & presentation
Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation


Set PPApp = New PowerPoint.Application
‘Open the Powerpoint application
PPApp.Visible = True

‘The next action I want is to open a new blank Powerpoint Presentation, so I use 'the inbuilt options I’m provided each time I add a period after I select an option & 'I can write the below;

Set PPPres = PPApp.Presentations.Open

When I go to run this line, I get a compile error “Argument not Optional”

So firstly, I thought the error may be that I also get prompted for more options if I add a period, so I should select options until no more options appear.

So, adding to the “Set PPPres = PPApp.Presentations.Open” line until I don’t get prompted anymore, I ended up with the below ‘best assumption’ of the options supplied to open a new blank presentation.

Set PPPres = Presentations.Open.SlideShowWindow.Activate

Predictably, it errors for the same reason.

Is the lesson here that I should know after the “Set PPPres = PPApp.Presentations.Open” causes an error that I’m going down the wrong path & should choose another option after “Set PPPres = PPApp.Presentations…….”?

Any tips or links on how to use the inbuilt functions of the Visual Basic editor or the Object Browser would be appreciated, Thanks
 
I'm not sure how that particular object works but you might want to put an open parenthesis "(" after the "Open" command to see what the parameters are supposed to be for the Open method. That error tells you that at least one of the parameters is required and you didn't include any parameters.

You also need to be certain that the Open() function returns a Presentation object before you use it. My assumption is that the Presentation must exist before you "Open()" it and that you must tell the Open function "where" the existing presentation is located.
 
Thanks georgedwilkinson

I tried the "(" after the 'Presentations' part of the "Set PPPres = Presentations.Open" code & got the prompt asking for an index number (slide number I assume).

I eventually discovered that the correct code is "Set PPPres = Presentations.Add" but my point is that I didn't know why the code would give me options to select code that produces errors.

I appreciate your tips & advice & note that I can't supply a 'where' as this is a brand new presentation & doesn't actually exist anywhere yet.

Cheers
 
The editor gives you all options available at that point. Therefore your code .open would have worked if you were infact opening a presentation. As you were not giving it all the parameters required for .open you got the error.

The editor gives you a shortcut for typing - you cant really blame it for using the wrong code.... Remember it is not running or compiling your code as you type so it has no way to check that your code will work
 
Thanks DCB

I mainly wanted to know if I was using it properly & wasn't missing anything that would make life easier, although It does help with writing code of course.

Is there a reference book/library/help file that has ALL the possible codes that I could use?

It seems that all programmers had to go through a lot of 'trial & error' to get their procedures to work until they were familiar with what goes with what.

Thanks again.
.
 
Thanks DCB

I mainly wanted to know if I was using it properly & wasn't missing anything that would make life easier, although It does help with writing code of course.

Is there a reference book/library/help file that has ALL the possible codes that I could use?

It seems that all programmers had to go through a lot of 'trial & error' to get their procedures to work until they were familiar with what goes with what.

.
I find that Trial and Error helps you learn more than you could read....
As i have the attention span of a gnat, books are somewhat lost on me!

Sure there are some people on the forum who would recomend some books... Why not start another thread and see what comes back?

Make life easier in the Editor: MZTools
 
The properties and methods that pop up in the IDE are an AID. You still need to be familiar with the object model that you are using. The popups aren't equivalent to "Programming for Dummies". If the methods you are trying to run require parameters, you need to be familiar with what parameters that are being asked for and what they mean. Read some books and don't count on the interface providing you with fail safe code.
 
I always though the help file would get you most of the way there. Failing that, I've always done a google search to see if somebody has already done what I want to do.
 
Thanks to All for your comments

Hi c_smithwick, do you have a reference book or do you use the Object Browser etc to help you along?

Also, what do you do when you're absolutely stuck?

I've managed to get what I wanted eventually but it has been a lot of reading, trial & error, begging favours from more experienced people & of course, this forum.

Now that I'm clear that I am using the Aids as best I can, I want to see what other programmers find is the best way.

& georgedwilkinson, appreciate your tips Cheers !!
 

Users who are viewing this thread

Back
Top Bottom