Library tutorials & articles
Leverage the .NET Framework with Visual Basic.NET
- Introduction
- DataTypes & Operators
- New Features
- More New Features
New Features
Inheritance
One of the biggest enhancements in the .Net platform is the ability to use Inheritance. VB5 introduced "interface inheritance" which allowed VB developers some ability to extend existing objects. Unfortunately it only provided access to the interface and not the underlying implementation.
In VB5 or VB6, for example, you could create an "Person" object that handled basic properties such as Name, Address,Age, etc. If you then wanted to create new objects, such as "Employee", "Student", "Customer" or whatever you could not simply extend the existing Person object. Instead, you had the choice of duplicating the code in the new objects or using delegation by having the new object create an instance of the "Person" object and calling it's methods and properties whenever your code called methods or properties of the extended object.
With VB.Net we now have full inheritance. Your "Employee" object, for example, can inherit the "Person" object along with all of the debugged code it contains to validate, save and retrieve the data it manages. You can then just add the new features that you need to support an "Employee". You can also override, overload or shadow methods and properties of the base class if you need to alter the standard behavior in some way.
Inheritance also applies to visual objects like controls and forms. It will be possible in VB.Net to create a base form that includes corporate logos, standard menus, help systems, etc and then inherit from them to create application-specific forms that have the identical look and feel as all other forms.
Console Applications
VB.Net can easily create true console applications making it possible to write components to be called from command lines, logon scripts or batch processes and have them interact with the standard input and output files.
Delegates
A "delegate" in VB.Net acts somewhat like function pointers in C; they allow you to pass procedure references around and to call those procedures. This can be a very powerful technique, allowing you to call custom sort or other processing routines without needing to hard-code IF or Select blocks.
Function Overloads
VB.Net offers developers the ability to overload functions to provide different functionality based on the number of type of arguments passed. In earlier versions of VB this was often done using optional parameters or ParamArrays but often required a fair amount of coding to determine what was passed and changes could be awkward to implement without breaking compatibility. With VB.Net it is possible to have multiple procedures with the same name but different argument "signatures" that allow the compiler to determine which routine is being called.
Related articles
Related discussion
-
How to write the category attribut in a class dynamically
by converter2009 (1 replies)
-
VB.NET: Hide and show table using radio buttons
by converter2009 (1 replies)
-
VB.Net Button Problem
by pysdex (0 replies)
-
Unable to access AxInterop.AcoPdflib.dll on 64 bit OS
by Shaila14041981 (0 replies)
-
Very Urgent regarding deleting the images from a folder
by Nanosteps (6 replies)
Related podcasts
-
xpert to Expert: Inside Concurrent Basic (CB)
"Concurrent Basic extends Visual Basic with stylish asynchronous concurrency constructs derived from the join calculus. Our design advances earlier MSRC work on Polyphonic C#, Comega and the Joins Library. Unlike its C# based predecessors, CB adopts a simple event-like syntax familiar to VB progr...
hello, I developed application in visual basic .net and when i tried to run this application in other computers then setup file prompt me message to first install the .net framework in the computer then installation will start so after installing the .net framework in other computer, my setup or application worked fine but .net framework file size is almost 23 MB that is very big to distribute with my application or to ask from the user to download this file. My application size is only 4MB. Well, i conclude that VB.net is not useful if some one want to distribute his small application to many hundred computers because it require .net framework (23 MB) that is very difficult to download. So i am moving back to VB6 for my application developemnt. If you have any idea that i should stick to VB.net then please let me know, I need help. It is very difficult for me to write code again for VB6. bye
You probably figured this out by now but for anyone else with the same or similar problem looking for the old VB6 control array then you need to delegate the Event to a helper method.
The helper method must have the same signature as the event being delegated
Usually along the lines of “Event Name”
(ByVal sender As Object, ByVal e As System.EventArgs)
to demonstrate create a new windows project and add 4 radio buttons to the form or another control if you prefer( Alter the code to suit )
and add the following code to the form
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler RadioButton1.Click, AddressOf RadioChanged
AddHandler RadioButton2.Click, AddressOf RadioChanged
AddHandler RadioButton3.Click, AddressOf RadioChanged
AddHandler RadioButton4.Click, AddressOf RadioChanged
End Sub
Private Sub RadioChanged(ByVal sender As Object, ByVal e As System.EventArgs)
MsgBox(CType(sender, RadioButton).Name)
End Sub
OK this a bit useless as most people would not use radiobuttons in this manor
Add a number of textboxes to the form about 10 would be ok
Then add this code to the form load event
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
AddHandler ctrl.Validating, AddressOf ValidateTextFields
End If
Next
ctrl.Dispose()
ctrl = Nothing
and add this method
Private Sub ValidateTextFields(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
e.Cancel = CType(sender, TextBox).Text = String.Empty
If e.Cancel = True Then
MessageBox.Show("TextField " & CType(sender, TextBox).Name & " Must Be Completed", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
You should now have a simple ( all be it poor for user input, but it is only a demo of a concept) validation on all textboxes
Why not add it to the handles clause of the first textboxes validation event
Like
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
Handles TextBox1.Validating, TextBox2.Validating
End Sub
This will work but you can not remove the handler at a later stage Add the following to the ValidateTextFields method after the previous if statement
If CType(sender, TextBox).Name = "TextBox1" Then
RemoveHandler TextBox1.Validating, AddressOf ValidateTextFields
End If
This should remove the handler and the validation
I Hope this helps
Cheers
James
if radState0.checked = true then sum += 1
....
....
if radSate99.checked = true then sum += 1
or can I do it in a loop e.g.
for i = 0 to 99
if radState(i).checked = true then sum += 1
next i
Please excuse the naivity of the question but I am starting from the ground up.
Regards
Bob
When I ran into this problem it was due to the fact that i was on a different machine and some of the files included in References for my VB6 app weren't installed and registered on the new machine. Is it possible that some of the files that your VB6 app needs were uninstalled or unregistered when you uninstalled VB6?
I have a project designed and implemented using VB6.0 and Oracle 8i.Recently I unistalled Visual studio 6.0 and installed .NET.Now when I try to open my project through the .NET IDE it invokes the update wizard.However the updation does not succeed as the process reports several missing file.Can anyone help me out in updating the above project to .NET platform.Why are the errors encountered?
Thanks
Shant
I don't understand the reason why the size of Bool type in VB.Net is of 4 bytes (as by article of G.Gnana Arun Ganesh). Can somebody explain?
This thread is for discussions of Leverage the .NET Framework with Visual Basic.NET.