LegendEntries collection not visible from Locals pane - vba

When I examine a Legend object in the Locals pane, I don't see the LegendEntries collection.
I learned about LegendEntries only from Microsoft's online documentation.
Why isn't LegendEntries visible from the Locals pane?
What other options do I have to explore the object model besides the Locals pane?

Looking at the Object Browser, you can see that Legend.LegendEntries is a method (a Function or Sub); the Locals pane only displays properties (Property Get).
It's also presented this way in the documentation of the member (not the docs on the collection itself, but about the member needed to access the collection from Legend):
Legend.LegendEntries method (PowerPoint)
It's not that obvious in VBA, because VBA doesn't require parentheses when calling a method without parameters. But if you were accessing the PowerPoint object model from a language which does require parentheses for such method calls, you'd see the distinction right away.
Aside from the Microsoft documentation of the Office object models, the Object Browser (View -> Object Browser, or pressing F2) shows all the members of a given type, including the methods.
NB. By default the Object Browser doesn't show "hidden members", nor are they visible in completion list in the code editor window. In order to see such members, right-click anywhere in the Object Browser and choose the Show hidden members option. The hidden members will be displayed in a lighter gray, as in the above screenshot.
Note also that code which uses these hidden members will compile and run successfully, whether or not this option is selected.

Related

Application.ObjectChangeIcon method in MS Project

I read Edge MS documentation on the subject method and a couple of things are unclear or perhaps wrong. Supposedly the document was written or updated 01/18/22 so it should be applicable to Project 2019 Pro desktop.
1.The remarks section says, "The bitmap or drawing object must be displayed and selected" (Gantt Chart view). What exactly does that mean? I created a drawing object (polygon), placed it on the Gantt Chart and selected it. However, when I attempt to run Application.ObjectChangeIcon via the Immediate window, an error occurs saying, "The method is not available in this situation". What am I missing?
2.Further in the remarks section it talks about creating a new custom ribbon tab and group. Then it says to add the Object and Convert commands to the group. There is a Convert command but there is no "Object" command.
Project ribbon commands screen shot:
John

Can't access class members of Word class in immediate mode

I am writing a vb.net desktop application which automates ms-word. Defining variables of types taken from the word object model, I cannot access member elements of those classes in immediate mode, when debugging. I CAN access them from my code, when it is running.
Private Sub BlackOut(aRange As Word.Range, CharLimit As Integer)
MsgBox(aRange.Characters.Count) 'This works
End Sub
Running the Code and accessing aRange.Characters.Count works just fine. When setting a breakpoint and typing the line ? aRance.Characters.Count in the Immediate Window, however, I get the error message:
error BC30456: 'Characters' is not a member of 'Range'.
Strangely, typing ? aRange.Text works in the Immediate Window.
I haven't encountered that before. Can anyone help me out of this?
This is due to the "Embed Interop Types" setting on the Word Interop Assemblyreferences (Interop.Microsoft.Office.Core, Interop.Microsoft.Office.Interop.Word, and Interop.VBIDE) being set to True. When this setting is True, the compiler extracts only the type definitions used in your code and embeds it into your program. This is useful in that it eliminates the need to include these Dll's along with your program, but makes it difficult to "edit and continue" during debug as the full type information is no longer available to the debug session. The solution is to not embed the assemblies while you are in development.
From the Solution Explorer, click on the "Show All Files" button such that the "References" node is displayed. Click on the node to expand it. Hold down the Control Key and select the three files as show in the following image.
With those files selected, press the "F4" key to show their properties.
Change the "Embed Interop Types" to False (doing this should also change "Copy Local" to True.
When you are ready to publish your application, change those properties back.

How to implement advanced custom properties in VB6 usercontrols?

Sorry I don't know how to name it other than "advanced custom properties". If I know, I would search it first.
I am dealing with a legacy code using 3-rd party controls.
In VB6, When you drag that control onto the form, you can see all the properties supported by the control in the "Properties" window. Such as MarginLeft, MarginRight etc. etc.
That's no problem.
In the "Property" window, the top-most property is generally the "(Name)" field, which is the name of the control.
But the 3-rd party control I am using, has another two "fake properties" above "(Name)", which are "(About)" and "(Custom)".
When you click "(About)", there will be a dialog box showing the company info. When you click "(Custom)", there will be another dialog box showing more properties. These dialog boxes are shown in VB6.
In the "(Custom)" dialog box, you can modify normal properties (same as modifying directly in the Property window). You can do more. There are more properties that are not normal properties (at least you cannot find anything in the Property window).
When you save this form, for normal properties, everything are saved into .FRM file. E.g.,
Control1.MarginLeft = 5
Control1.Text = "I am a control"
However, for the "advanced properties" edited in the (Custom) dialog box, they are not saved in .FRM, they are saved in .FRX in binary format.
E.g., in (Custom) dialog box, you can edit a property called "Caption", which includes text of this caption, the font, the weight, the display style, and a lot of similar properties for Caption. In .FRM, it is something like,
Control1.Caption = "frmForm1.frx":013F
All the text and related properties of Caption are saved in binary format in .FRX file.
Note that, there's no Caption property in the normal Property window, you can only edit it in the "(Custom)" dialog box.
My question is as follows,
How to implement such a (Custom) dialog box that can be shown in VB6?
How to let VB6's Property window display (About) and (Custom)?
How to tell VB6 that Caption property shall not be displayed in Property window, but you can use directly in code as Control1.Caption = xxxx.frx:offset?
How to tell VB6 that this Caption property shall be saved in .FRX, and how to tell VB6 the size of the data, so that VB6 can manages the offset automatically?
How to load the data automatically via VB6 so that the correct values can be displayed in (Custom) dialog box?
As far as I know, .frx formats are secrets, there are a lot of ppl digging into various .frx for standard controls such as Binary(images), List, and Text. I am curious how can a 3-rd party control utilizing .frx, shall the 3-rd party control define its own .frx format? Including for example, how many bytes in front for Length (or no length field at all, it's fixed length), how many bytes for style1, how many bytes for style2, etc.
Thanks a lot. If you know what proper name it is for this "advanced properties", just tell me the name and I can search myself.
I tried to search for advanced properties but didn't really get anything I want to know.
The frx files are for binary or other non-basic data types. The frm will store the simple properties. What you need to do is to hook into the UserControl events WriteProperties and ReadProperties. You don't need to know where the backing storage is (frm vs frx)., you just need to access the PropBag to read and write your data.
Google is your friend to find the documentation:
https://msdn.microsoft.com/en-us/library/aa242140(v=vs.60).aspx
Or additional information on the topic:
http://www.vbforums.com/showthread.php?365735-Classic-VB-How-do-the-ReadProperties-and-WriteProperties-work-(PropertyBags)&s=3cfbd675928ad1eb94f68fbfb13ccd88&p=3672781&viewfull=1#post3672781
Good luck!

How Can I Comprehensively Manage my VBA UserForm's Properties?

I am writing my first VBA Add-In under Microsoft Office Word 2007 with Windows 7 Pro/64. Part of this Add-In is a UserForm. Using the Visual Basic editor that runs from Word, I find there are two ways of viewing, and two ways of modifying a UserForm's properties:
View all properties from Object Browser (F2)
View some properties and edit them from Properties Window (F4)
Manually enter and edit any property from the Code window (F7)
Here is a screenshot of my Properties and Code windows:
A problem I find is that the Properties Window contains only a subset of the UserForm's properties (notice that CanPaste, CanRedo, and CanUndo don't appear in Properties), and changes made in the Properties Window are overridden by changes made in the Code window (e.g., at runtime, Me.Caption from the Code window above overrides the Caption field in Properties).
I suppose I should avoid using Properties at all then, and enter all settings via UserForm_Initialize as shown above. But (a) for some settings, Properties makes several settings at once. For example, selecting Verdana Bold from Properties equals Font = Verdana and Font.Bold = True in Code. And (b) it seems Properties sets the subset of properties it controls to defaults of its choosing, and if I change them I can't see what they started out as.
I therefore desire unified and comprehensive access to all my UserForm's properties at once, including the aforementioned default settings. Does anyone know how to reveal a UserForm's default settings as code, or to automatically open all its current settings in the Code window? Is there an umbrella mechanism I'm not aware of?
I'm not a veteran VBA programmer, but I can't believe my experience is unique. I've searched the 'net in vain for a solution. How do you with more experience manage this dilemma?
You use the Properties window to set appearance-related properties at design time. Those property values will then always apply unless you explicitly change them at run-time with VBA code.
Properties that don't relate to appearance, such as CanPaste and CanRedo relate to the state of the form at run-time, so it doesn't make sense to have them configurable at design-time.
You can change nearly all of the properties at run-time, whether it is in the Initialize event or elsewhere. You can even add controls at run-time, but your changes won't be persisted once the instance of the form terminates.

VB2010: Viewing Object Structure for Learning/Visualization Purposes

I was wondering if there is a way to take an object in Visual Basic 2010 (Express, FWIW) and browse through its structure to visualize how the data inside is laid out.
For example, I have an object called "model" that is populated by a function that is a black box to me. Model is set by a "read" function that loads a DXF file from disk. The read function isn't very well-documented.
What I've discovered is that model.Entities ends up containing a list of different objects, all with different properties. I'd like to be able to simply browse this list of objects and view their associated properties and values at run-time, similar to how you can use Intellisense to view a list simply by typing "blah." and waiting for the pop-up to appear.
A tree view that you can pop open and closed would be excellent. Obviously this has to work during run-time rather than in the editor because the file hasn't been loaded if the program isn't running.
Is this something that's possible in Visual Basic 2010? Is it a built-in feature I can't find?
Thanks!
If a function returns an object, then that object has a class definition somewhere. Right-click the reference in VS and select "View in Object Browser" and you'll see the class layout with all properties and methods. You don't need to do this at run-time, either.
If you want to dig even deeper then you should check out Reflector.
EDIT
After reading your comments more, I usually do one of three things when I'm trying to do this:
Use the Autos and Locals window
Use the Immediate Window
Use "break-point and hover"
Use the Autos and Locals window
Set a breakpoint and check out the Autos and Locals windows. If you don't see them they're under the main menu at Debug, Windows. This allows you to walk a tree-view of your variables. Sometimes there can be a lot of stuff in here which I why I generally use one of the other two methods below.
Use the Immediate Window
The Immediate Window (IW) allows you to type in expressions and print out values. Its not a tree-view like you want but it allows you to hunt and peck at least. If you imagine the following short and simple code and you put a breakpoint on the second line:
Dim Names As New List(Of String)({"Alice", "Bob", "Chuck"})
Console.WriteLine(Names)
In the IW you could type:
?Names
And it would output:
Count = 3
(0): "Alice"
(1): "Bob"
(2): "Chuck"
The question mark symbol means "print". You can type almost any valid expression for print:
?Names(0)
"Alice"
?Names(0).Substring(0,1)
"A"
?Names(0).Contains("ice")
True
And as you're doing all of this you're getting IntelliSense about whatever is going on.
Use "break-point and hover"
I don't think this has a name beyond IntelliSense but once you've hit a breakpoint you can hover over any variable and inspect its current values. You'll get the occasionally warning that inspection will cause some processing but since you're debugging only this should be fine. Sometimes when I'm debugging a collection I'll create a variable specific to one item in the collection just to make this technique easier. I'll get rid of it once I'm done debugging but it really helps this process.
Is there another