Objects in VB.NET

  • Thread starter Thread starter al
  • Start date Start date
A

al

Greetings,

I'm confused about obejects handling in vb.net. For example,

why when including NEW in some declaration cuases error, like

Dim FormBinding As New Binding 'This causes an error if NEW is included

whil NEW here doesn't causes an error

Dim i as new integer

Also, does early binding make better application????

MTIA,
Grawsha
 
Also, as a matter of good practice, In your preferences, turn OPTION STRICT
to ON, it will save you a lot of time wasting.

Regards - OHM

William said:
In addition to Jan's answer, YES, use Early binding wherever possible!

Regards - OHM# (e-mail address removed)
 
Al,
In addition to the others comments.
Dim FormBinding As New Binding 'This causes an error if NEW is included
Binding has a constructor (a Sub New) that requires parameters, you need to
supply these values in order to create a new Binding Object. Constructors
with parameters ensure that the object is properly initialized when it is
created, ensuring that you do not forget to set any required properties.

Jan gave a sample of how to do this.
Dim i as new integer
Integer has a default constructor (a Sub New with no parameters) so you can
create an Integer 'value' without giving any parameters. Note: Integer is a
value type (a Structure) so you are not really creating an object here, for
lack of a better term you are creating a value. Structures always have a
default constructor!
Also, does early binding make better application????
Yes, in most cases using Early Binding (Option Strict On) makes for a better
application! As:
- your program will generally perform faster
- you have a better chance of avoiding obscure runtime errors
- your code will better show what you are intending to do

I normally include Option Strict On at the top of every source file, as its
part of that source file then. As OHM pointed out you can set it under
Project Properties & Tools Options.

Hope this helps
Jay
 
Back
Top