Click here to Skip to main content
15,881,172 members
Articles / Programming Languages / Javascript
Article

Template for VB.NET (C# Users).

Rate me:
Please Sign up or sign in to vote.
3.32/5 (12 votes)
26 Sep 20042 min read 55.1K   791   15  
Modified template for VB.NET which will make VB.NET similar to C#.

Introduction

Modified templates and JavaScript files will change the coding environment, such that it will make the VB.NET environment look like C# one. I hope, it will make C# people to work in VB.NET easily.

Adding Imports

This is not a difficult task. We can add whatever Imports to our template file, so that it will reflect in the projects. A modified Form is given with this article. For other projects also, you can easily modify the appropriate file and add a small piece of code to do it. All the template files can be found in %VS.Net Installation dir%\Vb7\VBWizards.

For example, you can add:

VB
Imports System

on top of the template file and get this in your project.

Adding Namespace

Here, I came up with a decision that the namespace will be as the assembly name. I came to this decision because of their Root Namespace concept. If we have the same thing in our class, then the namespace will be %RootNamespace%.RootNamespace%. This is surely not what we want to do. So, we must make a decision to define the namespace.

To make this happen to Windows Forms, we must do few changes. Here, I'll only change the Windows form template. Others you can follow the same way and do it easily.

First, we must change both Form.vb files. The modified files are given below. We must add a variable in the template files and define those in the JavaScript files so that they will be changed according to the name of the project/output name.

VB
Namespace [!output SAFE_NAMESPACE_NAME]

This variable is defined in the script file such that it will refer to the assembly name. You can change this as you want.

Check function AddFileToVSProject(strItemName, selProj, selObj, strTemplateFile, bValidate) in common.js.

Add File to VS.Net Project

Also, I must change default.js. Because of my change in the namespace now, the startup object is changed. So, I must change that file also.

Startup Object

Sample

Samples provided with this article are for Windows Application template. But you can easily modify your other templates and get these features.

Make backup of your:

  1. %VS.Net Installation dir%\Vb7\VBWizards\1033\common.js

    (E.g.: C:\Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBWizards\1033\common.js)

  2. %VS.Net Installation dir%\Vb7\VBWizards\WindowsApplication\Scripts\1033\default.js

    (E.g.: C:\Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBWizards\WindowsApplication\ Scripts\1033\default.js)

  3. %VS.Net Installation dir%\Vb7\VBWizards\WindowsApplication\Templates\1033\Form.vb

    (E.g.: C:\Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBWizards\WindowsApplication\ Templates\1033\Form.vb)

  4. %VS.Net Installation dir%\Vb7\VBWizards\WinForm\Templates\1033\Form.vb

    (E.g.: C:\Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBWizards\WinForm\ Templates\1033\Form.vb)

  5. %VS.Net Installation dir%\Vb7\VBWizards\Class\Templates\1033\Class.vb

    (E.g.: C:\Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBWizards\Class\ Templates\1033\Class.vb)

And replace those with the files which come with this article.

Now, new Vb.NET projects will have Imports and Namespace in their code, which is similar to C#.

Sample screenshot

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Singapore Singapore
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --