In this visual basic 6 app there is a field that repeats a lot, Time . For example:
hour = Hour(Time) *3600
That field isn't declared in the (Declarations) section, is that field incorporated by a dll or by vbp?
In the VB6 IDE you can ask the IDE to tell you where something is defined.
Right click on the variable, and select "Definition":
You can also press Shift-F2 to achieve the same result.
In the case of Time, doing this brings up the Object Browser window which shows the contents of all the library references in the project:
You can see that Time is a member of the VBA.DateTime class. The VBA library is a permanent part of any VB6 project. It is listed in Project > References:
You can see at the bottom of the window it is implemented in a particular 'system' DLL. Note that this reference cannot be removed, so Time and other items it contains are always available to any VB6 project.
Related
Is there a way to quickly "Auto qualify" a variable type declaration in Visual Studio 2013?
E.g. if I type:
Dim SomeExcel as New Application
is there a way to get the IDE to automatically fill in the namespace? like this:
Dim SomeExcel as New Microsoft.Office.Interop.Excel.Application
The IDE seems to be able to infer the namespace readily enough; if I hover over the type name it can tell me what namespace(s) contain the type.
It would be really useful to me to be able to change an old project from "short names" like Application to fully qualified names like Microsoft.Office.Interop.Excel.Application without having to find each one and type out the whole namespace.
Or, in the event of an ambiguous name, if it would give me the option to pick which namespace and it would fill it in. Similar to how if you use an undefined class it will warn you and give you the options to either automatically add the Imports statement or even create a class stub for you.
Since it will do all that for you automatically, and it will make suggestions and autocomplete methods/properties for an interface instance as you type, I would be surprised if there was not a quick way to have it convert "short names" to fully qualified names, but if there is - I can't seem to find it! I looked through the menu commands, and various right-click menus, and I looked on MSDN but couldn't find anything - but i'm not sure I'm using the right search terms.
Hoping someone with more experience might know how to do this or if this functionality doesn't exist.
No, nothing exists in Visual Studio to do that.
Doing so also confers no special advantages, as VS will tell you if you have an ambiguous reference automatically and give you the possibilities to resolve it.
When that happens, just click the icon that appears when you hover over it and select the correct namespace. VS will then qualify it with that namespace.
Here's an image of the icon:
And the resulting menu:
Granted, that is for C#, but VB usually works the same way.
I am in a c# project, in this project I reference (using a project reference) another class library written in vb.net.
Now, when I right click and view definition on the class. It doesn't take me to the exact source code in the vb.net project, instead it takes me to a dynamically generated c# representation of the vb.net class.
I've tried the experiment in reverse, starting with a vb.net project, and referencing a c# project, this time on a right click view definition, it takes me to the code explorer, so again, not the original code for editing.
If both projects are the same language, everything works like nicely.
Is there an explanation for this? And possibly a solution to allow easy code navigation between projects of different languages?
To reproduce:
Create a blank solution
Add a c# class library
Add a vb.net class library
In the vb.net class library, class1 - create any old method. (optional)
In the c# class, add a reference to the vb.net class, for example:
VBClassLibrary.VBClass myVBClass = new VBClassLibrary.VBClass();
Now, right click on VBCLass and select "Go To Definition".
Notice where you end up....
There is nothing you are doing wrong here. This is an unfortunte side effect of how Visual Studio is designed. When you have two projects in different languages a reference between them does not behave like a project reference but instead resembles a file reference.
Project to Project references of the same language share a single language service. Hence it is in control of all of it's code and can provide special live content benefits. The primary one being the goto definition and instant intellisense. There is just no facility in Visual Studio today to allow language services to communicate with each other across the reference boundary like you desire.
For "goto definiton" you can use instead "navigate to" (ctrl + commma)
Oftentimes I want to bring up a system class in a source view, so that I can browse the properties and methods exposed by the class. Below is the screenshot of what I mean:
Srting from metadata http://img443.imageshack.us/img443/940/stringfrommetadata.png
Usually I do this by selecting the class name and pressing F12 (or right click>Go To Definition). However, if I haven't got it anywhere ready, i have type it up and then do Go To Definition. Most of the time I have to delete what I typed later on.
Is there a way to bring up this view without having to type the class name? The VS2010 Navigate To dialog doesn't support this.
EDIT: When I posted the question I didn't use any Visual Studio plugins. Now that I realised that I have full CodeRush license (thanks to StackOverflow promotion for users with 10K rep) I will accept answers that use CodeRush or Refactor!.
EDIT: At this stage I haven't really got anywhere with trying to answer this question. I am going to leave it open and let the bounty auto-award itself to Rory as he explained what's happening the best. In the meantime(schedule allowing) I will investigate doing this with DXCore as I think it should be possible.
The view you're looking at appears to have been built by some sort of analysis of the IL of the framework. Without knowing the type you intend to look at, no deconstruction can be done. Therefore I feel that, you are unlikely to find exactly what you have said you are looking for.
Allow me to suggest a few alternatives though.
Disclaimer: I work for DevExpress as a CodeRush Community Evangelist.
The Object Browser (Ctrl+Alt+J) This screen will load without attempting to show you any particular type, it will therefore be down to you to find the type in question. However all types are available and full search functionality is provided. once the type you're looking or is found, all members are listed and available.
Update: If you use the (Ctrl+K, Ctrl+R) shortcut to launch the object browser, then it will launch focused on the Search box. This is invaluable.
There are a number of CodeRush features which can prove useful when trying to locate code.
TabToNextReference (Tab) Whilst the caret is positioned within a type, strike the tab key and the next reference to that type will be located. More Details
References ToolWindow (Shift+F12) When activated the References ToolWindow will show you any references to the current type or member. This toolwindow can also be used to navigate said references. The References Toolwindow can be used in both on demand and Live mode. this allows you to have the window update as you navigate your code (via mouse or keyboard) and locate all references of any symbol the caret lands upon.
QuickNav (Ctrl+Shift+Q): This feature is closest in style to VS2010's NavigateTo feature. QuickNav will locate symbols matching whatever you type into it's filter box. This facility also supports Camel Case search. More details
QuickNav is also much more configurable than it's VS counterpart
Finally
Please also keep in mind that CodeRush is build upon the DXCore, a framework which allows users to create their own plugins for use alongside each other and CodeRush.
This framework has been repeatedly been leveraged by the community to add additional functionality. So even if you don't see any thing quite to your needs, consider suggesting something to the community by way of the forums or even contact me directly RoryB at DevExpress dot Com
I'm sure there's something we can do to help you out :)
I was not aware of that new "Navigate To" feature, but I used to use Reflector for this sort of things. The pro version offers some integration with Visual Studio (Right clicking the method and selecting "Open In .NET Reflector"). It will open the reflector window and won't show the code in the VS itself. You can watch the demo that shows this feature and some others.
This is not the best answer that I'd expect but is a good option to know.
There is no way that I know of to do this in Visual Studio 2010. However, you can do this in ReSharper via the 'navigate to' menu. I suggest you try the 30 day trial from them, then if you really do need this then purchase it.
A number of add-ins allow you to browse objects (though usually in an object-browser treeview manner rather than in a "header" file form - I believe Resharper, CodeRush and Visual Assist X all have variations on this theme).
However, one add-in to consider (as it's free) is the VS Productivity Power Tools. It adds a Solution Navigator window that gives a view onto your solution just like Solution Explorer, but (among other enhancements):
can search & filter the files listed, e.g. show only those files that are named Test.
can "expand" any file entry to show the types and members within it.
I am looking for a Visual Studio add-in that would analyze the text around the cursor position and navigate to the corresponding class definition.
For example I have this XML file that is currently open:
<object id="abc" type="MyProject.Foo.Bar, MyProject"/>
If I put the cursor somewhere between the double quotes on the type attribute the add-in should obtain the string "MyProject.Foo.Bar, MyProject" and search for all projects and project references in the current solution for the given type and if it finds one, it should navigate to the class definition (or metadata if the source code is not available in the current solution).
If such add-in doesn't exist I would greatly appreciate some pointers that could help me writing one.
Well you could use the 'Code Definition Window' that comes with the VS2008 IDE. When you place your cursor, the Code Def window dynamically updates with the source code for that type. Works with regular source files.. don't have the IDE at hand to verify with XAML/XML
Also you could 'Jump to Symbol' key combo but you would need CodeRush Express add in for that. Shift+Ctrl+Q. More details here.
Use the Alt+G command in Visual Assist.
I'm building an "import from Excel" function. It has to be in a DLL, called from a non-MFC app. Has to provide an image of the spreadsheet that users can drag a select box around (to select cells), then click an IMPORT button, and have the right thing happen. Having trouble getting the spreadsheet up, having a button adjacent to it, and having it happen in a DLL.
I went the route of an MFC dialog inside a DLL, but was blocked in trying to bring up an OLE client for excel on a window on the dialog. Only support I found for showing Excel using OLE required an SDI. I was able to get the automation functions to work, and I could read the cells and paint a "fake image" of them on my dialog... but I'm afraid that's going to be in non-compliance with my requirements.
So I tried creating an SDI. I was able to create an SDI that brought up Excel as an OLE Client. I was able to handle the "selection change" event, and go the cell data I needed. I was foiled at this point by 2 items:
Could not make this SDI work in an MFC DLL. Crash in CWinApp constructor, asserting that the AfxGetThread wasn't null. Moved "theApp" to be locally scoped within the single exported DLL function, but still couldn't get it to work, but with different symptoms: crashed when added AFX_MANAGE_STATE(AfxGetStaticModuleState( )); to exported DLL function, if I didn't use that, the OnInitInstance never was entered. Tried adding a call to the app's Run() function, but that didn't help. I can post this code if someone thinks they have an idea what the problem is.
Could not present a toolbar while the Excel client item was active. I could put my "import" (and other options) on the menubar at the top, but that's not evident enough. Even a floating toolbar was closed. It makes sense that it would do this, since it would be confusing to have a toolbar present that couldn't take actions on the currently active item... but in my case, it's a problem.
So now I'm thinking I need to go back to the dialog approach, and embed an ActiveX control that brings up an excel spreadsheet file to import.
Must either allow me to handle the selection change event, or must allow me to find what cells are selected (or were most recently selected if clicking the "import" button on my dialog causes the selected cells to become unselected).
It must also come with reasonable licensing terms, as this will be used in a commercial application that is widely-available to the public.
If anyone knows of a "quick fix" to either of the approaches I had been trying, that would be useful too.
Hope someone can help me!
If you just want to embed Excel, you don't need anything.
Just embed it into a standard OCX host control.