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.
Related
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.
I have an ascx.vb file with a function that starts off like this:
Sub buildlist()
repcaldatelist.Visible = True
...
End Sub
I'm just trying to figure out what repcaldatelist is. When I use VS's "Go To Definition", it gives me a popup saying "The definition of the object is hidden." Using "Go To Implementation" does nothing.
I see the corresponding .ascx file with this line:
<asp:repeater ID="repcaldatelist" runat="server">
and I see how repcaldatelist is databound to it, so that page can display its data.
But what I'm trying to understand is, where does repcaldatelist come from? I want to see where it's initialized and what its type is.
I know this is probably really basic but I'm new to VB / Web User Controls and haven't had any luck searching for this online thus far. Please enlighten me.
ID="repcaldatelist" means that's the ID of the Repeater control. So in your .vb file, repcaldatelist is an object of type Repeater - the ID in the ascx/html translates into a variable name in the VB. If you hover over the variable in the .vb file in Visual Studio it should tell you the type as well.
Go To Definition / Implementation don't work because the Repeater class is part of the .NET framework, and it's closed-source - just a DLL on your machine. Therefore there's no source code or definition you can view. You just have access to its public API as defined by the docs (and should be available in intellisense as well).
I am working on a old project of vb6 which has hundreds if forms. I am able to run the application and have to fix a runtime error in a form which pop up. I don't know the name of the form and only have visual reference. I tried using debug but It has continues SQL statements running in a loop. Any advice is appreciated.
Thanks.
Search the code for the form caption, or the labels of controls on the form, using visual studio's "find in files" or simlar function of your favourite editor.
If the caption is set in the form design, this will take you to the .frm file the form is stored in. You can open this in Notepad or another editor to get the name of the class (which is usually the same as the filename).
If the caption is set in code, you can place a breakpoint on that line. Again, this will lead you to the code which instantiates the form.
This is an IDE question for Visual Basic 2008 Express Edition. It might be a bug in the IDE, or maybe it's my fault somehow?
My main form is named frmMain and in my application's properties I have set frmMain as my startup object. All of that seems like what a lot of software engineers do.
But while debugging I hit Ctrl + Break, as I have done for years, and I get an behavior in the IDE that I wasn't expecting. Upon doing so, I get the green background text and the green arrow indicating in a tooltip:
This is the next statement to execute when this thread returns from the current function.
Even if I didn't have the designer document open, it automatically opens frmMain.Designer.vb in the editor and hihglights line in green. The line is of course: Partial Class frmMain which is line 2 of the file. (Yes, it's highlighting the second line of the designer-generated code.)
frmMain seems to have fully loaded and it's my startup object. As far as I know, there shouldn't be a "next statement to execute" at all because code should be idle. I don't want to see the Designer.vb document... I want to edit my own code.
What's causing this? Even though my form is behaving just fine, could there somehow be an unfinished aspect of loading the form such that it is "not returning" from a function?
The Visual Basic compiler will add an entry point in your form. The entry point is the standard main function or "shared sub main", which in turn contains the code "application.run(new form)". Since this is compiler generated code there is no source location, so the Visual Basic editor highlights the class definition.
The clue to this is in the call stack. Notice the Main().
Shared Sub Main()
Application.Run(new frmMain)
End Sub
I found the answer on my own:
I checked the "Enable application framework" checkbox in the solution's properties, and all is well!
I believe this issue arose when I was working on experimental code in which I had desired to make Sub Main my startup object. I had cleared the checkbox because doing so is necessary to use Sub Main.
When the experiment didn't pan out I reset the startup object back to frmMain, and my app worked fine. However I had not re-checked the box. I hadn't noticed the change in the IDE behavior for several days (when I needed the more standard behavior) so I had not observed any correlation.
Although checking that box is definitely the solution, it's still not exactly clear to me is what the heck this box actually does, other than cause me to spend a lot of time on StackOverflow.com! ;-)
To others who encounter a similar situation, I'm now quite confident that my settings were not corrupt, and if you're using the Express edition, please don't be mislead by MS documentation which may lead you to believe it's the "Just My Code" option. This option cannot be changed in the Express versions. (But it's not because you can't turn it on -- It's because you can't turn it OFF in Express!)
Thanks to everyone for your efforts.
I'm going to guess that it is trying to show you the equivalent of:
Application.Run(new frmMain)
This is the code that gets generated to startup your form. But in VB.NET this code gets burried. Create a Main() function and change your startup type to that with this line in it and repeat the process. You'll see it highlight Application.Run. That is the method that contains your Windows message pump loop.
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