Introduction
I will try to explain to you what VB.NET Express 2005 Beta can offer in this article. Hopefully, you will learn something from it.
I first created a new Windows form project. It is very easy to do so. File->New Project and Choose Windows Application. VB.NET Express asks you project name but do not ask where it should be saved. Interesting thing is that VB.NET Express allows me to run my solution without saving it first. VS 2003 forces you to save your application first, as I remember. I think it uses temporary folder for this. Later when you save your project it asks you where to save it. You can change project name here too.
As in the VS.NET 2003, this action creates a Form1.vb. You can see solution explorer when you first create project below.
As my habit, I change this Form1.vb to something more meaningful. Since I decided to try "My
" functionality and I knew from blog postings that My
functionality makes file tasks easier, I decided to rename this to frmWriteTextToFile.vb. Then as my habit I looked at the code to rename class declarations too.
Surprise! Surprise!
When you rename your class file, automatically your class is renamed in the text file. I created a new class to test this functionality. I called this class from windows form object and renamed class. What I saw is that, all the caller's are renamed too. What can I say, very good. I was always annoyed to about deciding proper names for my classes since I knew that renaming them will be problematic later. If your source control will be able to deal with renamed files ( source safe 6.0d cannot ), it is very nice to have such functionality.
I added this simple method and wrote code as below:
Public Shared Sub WriteToFile(ByVal fileToBeWritten As String, _
ByVal TextToBeWritten As String)
If (My.Computer.FileSystem.FileExists(fileToBeWritten)) Then
My.Computer.FileSystem.WriteAllText(fileToBeWritten, _
TextToBeWritten, True)
Else
My.Computer.FileSystem.WriteAllText(fileToBeWritten, _
TextToBeWritten, False)
End If
End Sub
This code writes a string to text file. If file exists, it simply appends your string to end of file otherwise it creates a new file and write your string to that file. Writing to a file is as simple as this. Compare this to C# version or 1.1 VB.NET version.
After writing this class, I added one TextBox for filetobeWritten
and one multiline TextBox for textToBeWritten
and one button for actually calling WriteToFile
method. When I was changing names for this object, I saw one more improvement in the IDE. VB.NET now have events tab as C#.NET 2003. If you are coming from VB6 to VB.NET, you may not need them. But I first learned C#, then I started using VB.NET. As I am using both VB and C#, I look for such things in IDE. In my opinion apart from language changes, IDE should support same things in the editor. References are one more thing which C#.NET 2003 have but VB.NET 2003 does not. It is better implemented too.
You can see references in Find Symbol Results window.
In C#, you can go to caller but here you see all callers.
In the same menu, Insert Comment is same as C# comment ability or VBCommenter. It works with pressing three times ( ' ),''' also with this menu. Rename is the Refactoring Rename. Rename this method to something else and all of the callers will be changed as I have mentioned before. What is good is that, when you rename in the caller code, it works too. I read that rename refactoring is implemented and they are working in other refactorings in one of the Visual Basic TechED presentations. Rename certainly works. I hope to see other refactoring in Whidbey VB.NET 2005.
They have made bookmark usable thing also. In VS.NET 2003 bookmarks worked in only in one file. Here they works across files. Very Good.
There are Next Bookmark in Document and Previous Bookmark in Document. But I think they will not be used much unless you have very large files with 1K or more lines. And with that files you should think about splitting it to more smaller files.
When I tried to call my sample method from Windows Form, I saw another new thing. VB.NET Express have a very good intelligent trick as you can see in the image below.
Common tab shows only methods I have written. All Tabs shows methods, my class inherit from object.
In the Solution Explorer, come to MyProject and open it. You see better designed menu for your project.
Choose Assembly Information.
In this dialog box, you will be better able to change your Assembly Information. All of these things are only changeable via assembly.info file in VS 2003. Choose View Code here. You see the below code in MyProject\MyEvents.vb file.
Namespace My
Partial Friend Class MyApplication
End Class
End Namespace
You can add application wide events here using normal event adding.
Private Sub MyApplication_Startup(ByVal sender As Object, _
ByVal e As System.Windows.Forms.StartupEventArgs) Handles Me.Startup
MessageBox.Show("Hello World")
End Sub
A simple code, but it demonstrates a feature only.
After this, VB.NET Express demonstrated to me that it is Beta Product.
Well, I am taking my word back about renaming. It seems that even though I renamed my Form1
as frmWriteTextToFile
, some references exists in VB.NET Express to Form1
.This exception is generated since I have tried to set my splash screen to frmWriteTextToFile
. I am sure that these problems will be solved in normal product. I solved this problem in this way. In the solution explorer Show All Files.
Open MyApplication.myapp. This is XML file. MyApplication.vb is auto generated VB file from this XML file. I first tried to change this line in MyApplication.vb.
<System.Diagnostics.DebuggerStepThrough()> _
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = My.Forms.Form1
End Sub
But since this file is autogenerated, it kept coming back when you change the line
<MainForm>VB.Net ExpressArticle.VB.Net
ExpressArticle.WindowsApplication1.Form1</MainForm>
in the
MyApplication.myapp. Annoying
Form1
errors will go away. If you have two forms and want to change which one of them starts first. This is the way to that too.
When you set show all files, you will see that for every windows form object you have three classes. For example for frmWriteTextToFile.vb, you also have frmWriteTextToFile.Designer.vb and frmWriteTextToFile.resx. Open the frmWriteTextToFile.Designer.vb you will see this declaration in class file.
Public Partial Class frmPerson
Inherits System.Windows.Forms.Form
This file is partial class. In Whidbey and VB.NET Express, you can have a class which is split to more than one file. VB.NET Express stores automatically generated code in this partial file instead of
#region "Visual Studio Generated Code"-#endregion
Again in the My Project menu, there is Compiler tab. In this tab you can change Option Strict Option to ON/OFF/Custom.
It is good to be able to change some of Option Strict Options. I am fan of option strict. But sometimes I had to close option strict because of legacy code. Correcting hundreds of errors in working code seems excessive. This way I will be able to reduce error area a bit at least.
A little addition.
These additions are self explaining but very convenient to have in my opinion.
Second Click in the editor in a code line.
Choose Insert Snippet.
Choose Visual Basic Language.
Choose Initialize an Array. This Code appears.
Dim oneDimArray() As Char = {"X"c, "Y"c, "Z"c}
Dim twoDimArray(,) As Double = {{5.8, 6.6}, {7.4, 8.2}}
Dim jaggedArray()() As Integer = {New Integer() {1, 2}, New Integer() {3, 4}}
Interesting thing about snippets is that, selections vary with where you choose to insert them. What I mean is that, Code snippets which are shown in context menu changes according to where you are. When you are inside sub or function, different snippets appear than when you are inside the class body. These snippets are very good to have. Most of the time, I forgot implementation of something and I had to search help for something trivial. These will be a very good productivity enhancers. I will give you a link for how to add code snippets in the end of article
In the code snippets I have found an example, which I think is a generic sample ( I know C# generics and C++ templates only at this time. I will remedy this situation) I modified it to some degree.
Public Class GenTry(Of entryType)
Protected aList As ArrayList = New ArrayList(1)
Public Sub Add(ByVal e As entryType)
aList.Add(e)
End Sub
Public Function GetF() As entryType
Return CType(aList.Item(0), entryType)
End Function
End Class
Client function.
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Clic
Dim strA As GenTry(Of String) = New GenTry(Of String)
strA.Add("alo")
MessageBox.Show(strA.GetF)
Dim IntB As GenTry(Of Integer) = New GenTry(Of Integer)
IntB.Add(21)
MessageBox.Show(IntB.GetF().ToString)
End Sub
As you can see I can add string and integers to the same collection code. And compiler complains if I try to add things other than Integer to IntB
and string to strA
.
Edit and Continue works in VB.NET Express too. Though some quirks exists.
Things I missed.
- There is no Format Text Method in the Text menu. I use it a lot.
- Help is not very good right now. I have not installed MSDN Help which comes with Express as I am writing this since it was broken in my flash disk. I wanted to explore VB generics but I have not found any single code example in the VB Help. I hope that when I install help.
- Even though SQLExpress is installed in my PC, I was not able to connect to it. I think this is because I have both SQL Server 2000 and SQLExpress.
Of course, I was not able to explore all of what VB.NET Express can offer. But from what I have seen, it is very good for a FREE tool. Microsoft announced that Express products will be free to use.
Links