This example is a simple piece of code that writes strings to a text box. Similar to the traditional "hello world" application -- with a few more buttons. It was designed to make sure we all have a common starting point before going on to other examples. This example is a check to make sure that you are at least an intermediate programmer. If you can not create this entire program from scratch in only a couple of minutes then you should probably go back and do more general training on Visual Basic or C# before continuing.
For more training on VB.NET we recommend these books
For more training on C# we recommend these books
This program has three command buttons and one text box. When you click on a command button a predefined string is written to the text box. To run the ASP.NET version on-line click here.
The biggest changes from VB6 code to .NET are that (1) .NET does not allow control arrays and (2) "command buttons" are now simply called "buttons". Therefore we used the tabindex property of the buttons to indicate which button was pressed. Instead of using the prefix (object coding convention) of "cmd" for a command button we now use "btn".
.NET has an "Application" object which is used to run and quit your application (in VB6 we use to unload all the forms to stop running). However, the application object does not have a "PreviousInstance" property. So we went with what the VB.NET migration wizard gave us which is shown in the form "load" event handler.
In VB.NET one event handler (routine) handles events for multiple buttons by declaring the event handler and then at the end of the event handler declaration adding "Handles btnChangeMessage0.Click, btnChangeMessage1.Click, btnChangeMessage2.Click".
Note that in VB.NET we could have used "MsgBox" as in VB6 but we chose to use the "MessageBox.Show" instead. We wanted to be more explicit, use the .NET syntax which we hope is more intuitive to all programmers.
The last change from the VB6 code to VB.NET is that we used the "DirectCast" function to cast the general "eventSender" object into a Button object. This allows us to use the "Option Strict On". In C# this cast is done in a similar manner.
C# is very similar to VB.NET except with a lot more curly brackets ({}) and semicolons (;). You also have to spell and capitalize everything exactly correct (VB.Net some how figures out what you really want and corrects it for you -- C# does not correct things for you). In C# we had to go into the section of code hidden by
#Region Windows Form Designer generated code
and for each button change the following lines
this.btnChangeMessage0.Click += new System.EventHandler(this.btnChangeMessage_Click);
this.btnChangeMessage1.Click += new System.EventHandler(this.btnChangeMessage_Click);
this.btnChangeMessage2.Click += new System.EventHandler(this.btnChangeMessage_Click);
The "Select Case" in VB has to be converted to "switch" in C#.
Note that since we used "MessageBox.Show" in the VB.NET example instead of "MsgBox" (as we did in VB6) -- we did not have to change the command when converting from VB.NET to C#. In VB.NET we wanted to be more explicit, use the .NET syntax which we hope is more intuitive to all programmers.
To deploy the ASP.NET application to the web host:
The ASP.NET version is slightly different from the VB.NET and C#.
We try to offer a fair and balanced opinion on every page of our website. We would appreciate more information from other users to express their opinions which we will then incorporate. If you have questions or comments please post them on our message board (see button in left hand column) so that others can read and benefit.