Change intellisense autocomplete for Try - vb.net

When you type try and hit enter, it automatically types out
Try
Catch excError As Exception
WriteLog(excError)
End Try
This is not a snippet, I've looked. The snippet version has ApplicationException instead of Exception. Does anyone know where this is stored so I can change it?

You did not identify what version of Visual Studio, however here is how to modify the default Try/catch code snippets in Visual Studio Community 2015:
Tools -> Code Snippets Manager -> Language [Choose desired language in drop down] -> Code Patterns -> Error Handling
Highlight the desired code snippet and take note of the value in the location textbox above the split panel. Close Visual Studio as the .snippet file is most likely in use with Visual Studio open. Navigate to the path listed in the location text box and open the .snippet file with your favorite text editor. The .snippet file is a xml file; the actual code that is inserted by Intellisense is contained in the <Code><!CDATA[[]]></Code> node at the end of the file. Modify the code in within the CDATA block to what you wish Intellisense to insert for that code snippet and save the file.
Here is what the default <Code><!CDATA[[]]></Code> node should look like in the default Visual Basic Try/Catch snippet:
<Code Language="VB" Kind="method body"><![CDATA[Try
Catch ex As $ExceptionType$
End Try]]></Code>

Related

Importing code from a text file into VB

I have a project in visual studio 2013, using vb.net and I'd like to know how to import code directly from a text file and run it as code in the program.
I know this seems odd but it needs to be this way. Also I can't use a string builder and as i'm using vs it has a compiler built in.
Any help is appreciated
thanks in advance.
Open the text file in notepad
Create a new solution or open a .vb file in Visual Studio
If you create a new forms solution, press F7 to switch to code
view
Copy and paste the code from Notepad into the code editor
Run it and the code is auto-saved.
Why don't you let us see your code?

"TryCF" in Visual Studio 2015 (VB.NET)

I just found the very handy "TRYCF" hotkey in VS2015 - for those unaware, you can type "trycf", hit tab and it lays the following out for you:
Try
Catch ex As ArgumentException
Finally
End Try
This would be amazing, and would save me a lot of time in my day to day coding, except the default exception type "ArgumentException" is no good for me, I just want to catch generic exceptions: "ex as exception"
Does anyone know how I can set VS2015 up so that the default exception is just an "exception"?
Cheers.
You are invoking a code snippet. You could edit the snippet file and change the <Default> tag.
For VS2015, the path to those snippets is: "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VB\Snippets\1033\common code patterns\exception handling".
A recommended alternative is to copy the subject snippet to your personal snippet folder.
C:\Users\UserName\Documents\Visual Studio 2015\Code Snippets\Visual Basic\My Code Snippets
Then edit it to change the <Default> tag. Also change the <ShortCut> tag so that it does not conflict with the pre-installed VS snippet.

How do I output code while debugging in Visual Basic 2010?

When I'm debugging my application something is not right, and I can't continue.
So is it possible to see the output code of my app while I'm testing it to see what is wrong?
I open the output window but nothing happens in there it's just stay blank.
In two words: I want to see what my app is actually doing while I'm testing it.
I'm using Visual Studio 2010.
So is it possible to see the output code of my app while im testing it to see what is wrong?
Yes, but you actually have to output something, otherwise nothing will show up. In VB.NET (which is the language you're using if you have Visual Studio 2010), this is accomplished with the following code:
Debug.Print("Here is some text that will be output.")
The documentation for the Debug.Print method is here. In order to call it like that, you will also have to have imported the System.Diagnostics namespace. You do so by placing the following line at the top of your code file (with all the other statements that look like it):
Imports System.Diagnostics
The output will automatically appear in the Output Window. If you still don't see anything, ensure that output is not being redirected to the Immediate Window instead: Tools -> Options -> Debugging -> General -> uncheck the option "Redirect all Output Window text to the Immediate Window".
Confusingly, you use the word "code" in your question, saying that you wish to "see the output code of [your] app while testing it". I'm not sure if by "code" you actually mean "output", in which case the solution above will work for you.
If you actually mean code, as in your program's source code, then you can use the Break toolbar button (or press Ctrl+Break) in the IDE to pause the execution of your program. This will automatically dump you back into the code editor with the currently-executing line of code highlighted.
Visual Studio has some very powerful debugging tools. If you don't already have a general idea of how to use them, I strongly recommend picking up a book on either it or VB 2010 that will teach these things to you. They can be very confusing to learn by trial and error, but are not all that difficult if you have a good guide. Spend that time debugging your code, not figuring out how to use the IDE.

Disabling Intellisense Auto Line Return [duplicate]

When editing C# code in Visual Studio 2010, the ENTER key makes IntelliSense complete the current suggestion, without adding a new line.
In VB.NET, the default IntelliSense behavior for the ENTER key is to add a new line after completing the current suggestion.
How can I configure IntelliSense to change the VB.NET behavior to the C# one?
I already know that I could press TAB or SPACE, but out of habit I always end up hitting ENTER (and changing line).
UPDATE VISUAL STUDIO 2017:
Now with Visual Studio 2017 you can change it. Tools -> Options -> Text Editor -> Basic -> IntelliSense.
In Enter key behavior select Never add new line on enter
ANSWER FOR VISUAL STUDIO 2015 AND PREVIOUS:
If you want to avoid inserting new line on enter with autocomplete suggestion, just don't press enter. Instead of Enter press Space bar which completes your autofill and just inserts a space.
Or you may use this third party app:
Resharper makes it possible overriding Visual Studio intellisense and using its own intellisense. It is the only way I've found.
It has a 30 days free trial if you want to test it.
Unfortunately the set of trigger keys for intellisense completion is not a configurable item for VB.Net. There is no way in the default Visual Studio environment to change this behavior.
It would be possible to develop a plugin of sorts to accomplish this. However that's a pretty extreme measure.
EDIT
As of Visual Studio 2017, it is now possible to change this. See the answer below

Stop showing SQL errors in Visual Studio 2010

How can I stop VS2010 showing errors in .sql files, attached to a project? I don't want to check them at all, just C# code. The files are used as resources, Build Action set to Content. I'd like to keep .sql extension for syntax coloring purpose.
Regards,
Looks like your question was answered here: https://stackoverflow.com/a/8593877/2798869:
Visual Studio 2010
Tools -> Options -> Text Editor -> Transact-SQL -> IntelliSense
Uncheck "Enable IntelliSense".
Visual Studio 2012 & 2013
Tools -> Options -> Text Editor -> SQL Server Tools -> IntelliSense
Uncheck "Underline errors"
Note that you have to close then re-open any .sql files you may have open.
In VS 2012.
Go to the sql file properties in VS.
Under "Advanced", change the "Build Action" option to "None".
Unfortunately you have to do this for each sql file in the project.
This is what gave me the behavior that I wanted. It not only compiles without errors but shows no sql related build errors.
Update
It is possible to select multiple files in Solution Explorer by using Shift + Click (select the file at the top of the list -> hold down shift -> click the file at the bottom of the list). Once you have selected the group of files, you can then change the Build action to None for all of them at once. (This worked for me in VS2013.)
While you still have to select files per folder you don't have to select each file to set the property.
VS2015
right click in editor of the sql file > Intellisense Enabled
May be a sledge hammer to the problem but I manually deploy my SQL changes and only use them to house the scripts for my builds, so I do not need the functionality provided by SQL Projects.
Open the VS Solution File properties (right-click the solution in VS Solution Explorer and select Properties) and in the left pane select "Configuration Properties" -> "Configuration". In the right-pane you will see the projects in the solution. Un-check these projects to prevent them from building, this will prevent them from showing errors.
Is it possible you have a .cs extension on those files but it's not shown? I added some .sql files to my project and the compiler is not complaining.
Change the type of files to content and then the intellisense will never try and parse the contents of the files.
I just built a test project with one class file .cs and added one .sql file. It automatically set the build type to content. It built fine like John Fraser said in VS2010, so I changed it to compile, and obviously it failed.
This isn't the answer yet but perhaps the next step is to try and create a new solution, and import a few of the files from the original project to try to narrow down the source of the problem. If it builds then it would tell you it is something about the settings in your project/solution. Otherwise it could also be a VS setting.
Steps to stop showing SQL errors in bulk:
Open the SQL project file which has the .sqlproj extension in a text editor.
Find and replace <Build Include= with <None Include=. (This one has the same effect as right-clicking and changing Build Action to None in the solution explorer.)
The SQL errors should disappear in Visual Studio.