VBdotnet2005
asked on
Interface - 2
Why wouldn't this code work? I kind of modified it a bit from a sample at informit.com, one of the expert's suggestion
An unhandled exception of type 'System.NullReferenceExcep tion' occurred in Interface.exe
Additional information: Object reference not set to an instance of an object
...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xSingleEn As New InterfacePlane.SingleEngin eLand
Me.Label1.Text = xSingleEn.TailNumber(Me.Te xtBox1.Tex t).ToStrin g
End Sub
.......
Namespace InterfacePlane
Public Interface plane
Property TailNumber(ByVal x As String) As String
Property TailNumer2(ByVal y As String) As String
End Interface
Public Class SingleEngineLand
Implements plane
Private t1 As String
Private t2 As String
Public Property TailNumber(ByVal x As String) As String Implements plane.TailNumber
Get
Return t1
End Get
Set(ByVal Value As String)
t1 = Value
End Set
End Property
Public Property TailNumer2(ByVal y As String) As String Implements plane.TailNumer2
Get
Return t2
End Get
Set(ByVal Value As String)
t2 = Value
End Set
End Property
End Class
End Namespace
An unhandled exception of type 'System.NullReferenceExcep
Additional information: Object reference not set to an instance of an object
...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xSingleEn As New InterfacePlane.SingleEngin
Me.Label1.Text = xSingleEn.TailNumber(Me.Te
End Sub
.......
Namespace InterfacePlane
Public Interface plane
Property TailNumber(ByVal x As String) As String
Property TailNumer2(ByVal y As String) As String
End Interface
Public Class SingleEngineLand
Implements plane
Private t1 As String
Private t2 As String
Public Property TailNumber(ByVal x As String) As String Implements plane.TailNumber
Get
Return t1
End Get
Set(ByVal Value As String)
t1 = Value
End Set
End Property
Public Property TailNumer2(ByVal y As String) As String Implements plane.TailNumer2
Get
Return t2
End Get
Set(ByVal Value As String)
t2 = Value
End Set
End Property
End Class
End Namespace
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi Idle_Mind;
The two properties of that class takes 1 parameter so the following will give the error "Argument not specified for parameter 'x'.
xSingleEn.TailNumber = Me.TextBox1.Text
Me.Label1.Text = xSingleEn.TailNumber.ToStr ing
You will need to do something like this:
xSingleEn.TailNumber("Some Value") = Me.TextBox1.Text
Me.Label1.Text = xSingleEn.TailNumber("Some Value").To String
for it to compile and run.
Fernando
The two properties of that class takes 1 parameter so the following will give the error "Argument not specified for parameter 'x'.
xSingleEn.TailNumber = Me.TextBox1.Text
Me.Label1.Text = xSingleEn.TailNumber.ToStr
You will need to do something like this:
xSingleEn.TailNumber("Some
Me.Label1.Text = xSingleEn.TailNumber("Some
for it to compile and run.
Fernando
Hi Fernando...
I completely changed the definitions...take a closer look at my post. =)
I don't understand why "x" and "y" are being passed into a Property.
I completely changed the definitions...take a closer look at my post. =)
I don't understand why "x" and "y" are being passed into a Property.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The problem you are having is this. In the SingleEngineLand class you have no constructor that initializes the two variables t1 and t2. When you create the instance of SingleEngineLand the two variables are set to Nothing. This is why you are getting the error "System.NullReferenceExcep
Public Sub New()
t1 = ""
t2 = ""
End Sub
or initialize the values before using them. Somthing like this:
xSingleEn.TailNumber("") = ""
xSingleEn.TailNumber2("") = ""
Fernando