J
Jim in Arizona
I'm learning form an ASP.NET 1.0 book and I tried out some code that returns
this error:
Compiler Error Message: BC30311: Value of type 'Integer' cannot be converted
to 'ASP.multiclasses_aspx.VehicleKey'.
Source Error:
Line 106:
Line 107: Response.Write("<br/>Attempting to start DodgeCar with
PlymouthKey: ")
Line 108: DodgeCar.Ignition(789)
Line 109: Response.Write(DodgeCar.IsRunning)
Line 110:
Source File: E:\hhsinternal\multiclasses.aspx Line: 108
I tried this on .NET 1.1 and 2.0 Beta. I don't have any .NET 1.0 machines to
see if this worked or not. I'm hoping one of you experts can show me the
errors of my coding ways.
Here's the full code if needed:
<script runat="server">
Public Class VehicleKey
Private _Shape As Integer
Public Sub New(ByVal newShape As Integer)
_Shape = newShape
End Sub
Public ReadOnly Property Shape() As Integer
Get
Return _Shape
End Get
End Property
End Class
Public Class Car
Private _Color As String
Private _Gear As Integer
Private _Ignition As Integer
Private _EngineRunning As Boolean
Private Shared _Count = 0
Public Shared ReadOnly Property Count() As Integer
Get
Return _Count
End Get
End Property
Public Property Color() As String
Get
Return _Count
End Get
Set(ByVal value As String)
_Color = value
End Set
End Property
Public ReadOnly Property Gear() As Integer
Get
Return _Gear
End Get
End Property
Public ReadOnly Property IsRunning() As String
Get
If _EngineRunning Then
Return "The engine is running."
Else
Return "The Engine Is Not Running!"
End If
End Get
End Property
Public Overloads Sub ChangeGear(ByVal direction As Integer)
If direction < 0 Then _Gear = Gear - 1
If direction > 0 Then _Gear = Gear + 1
If _Gear > 5 Then _Gear = 5
If _Gear < -1 Then _Gear = -1
End Sub
Public Overloads Sub ChangeGear(ByVal direction As String)
If direction = "down" Then ChangeGear(-1)
If direction = "up" Then ChangeGear(+1)
End Sub
Public Sub Ignition(ByVal IgnitionKey As VehicleKey)
If IgnitionKey.Shape = _Ignition Then _EngineRunning = True
End Sub
Public Sub EngineOff()
_EngineRunning = False
End Sub
Sub New(ByVal IgnitionShape As Integer)
_Color = "Sparkle Midnight Blue"
_Ignition = IgnitionShape
_Count = Count + 1
End Sub
End Class
Sub Page_Load()
Dim HondaKey As New VehicleKey(123)
Dim DodgeKey As New VehicleKey(456)
Dim PlymouthKey As New VehicleKey(789)
Dim DodgeCar As New Car(456)
Response.Write("<div style=""font-family: arial; font-size: 110%;"">New
Object DodgeCar Created.</div>")
Response.Write("<br />Color: " & DodgeCar.Color)
Response.Write("<br />Gear: " & DodgeCar.Gear)
DodgeCar.Color = "Silver"
DodgeCar.ChangeGear("up")
Response.Write("<br /><b>Properties Updated</b>")
Response.Write("<br/>New Color: " & DodgeCar.Color)
Response.Write("<br/>New Gear: " & DodgeCar.Gear)
DodgeCar.ChangeGear(+1)
Response.Write("<br/>Shfted the gear up one.")
Response.Write("<br/>New Gear: " & DodgeCar.Gear)
Response.Write("<br/>Attempting to start DodgeCar with PlymouthKey: ")
DodgeCar.Ignition(789)
Response.Write(DodgeCar.IsRunning)
Response.Write("<hr/>Attempting To Start DodgeCar with HondaKey: ")
DodgeCar.Ignition(123)
Response.Write(DodgeCar.IsRunning)
Response.Write("<hr/>Attempting To Start DodgeCar with DodgeKey: ")
DodgeCar.Ignition(456)
Response.Write(DodgeCar.IsRunning)
Response.Write("<br/>Attempting to stop DodgeCar: ")
DodgeCar.EngineOff()
Response.Write(DodgeCar.IsRunning)
End Sub
</script>
Thanks,
Jim
this error:
Compiler Error Message: BC30311: Value of type 'Integer' cannot be converted
to 'ASP.multiclasses_aspx.VehicleKey'.
Source Error:
Line 106:
Line 107: Response.Write("<br/>Attempting to start DodgeCar with
PlymouthKey: ")
Line 108: DodgeCar.Ignition(789)
Line 109: Response.Write(DodgeCar.IsRunning)
Line 110:
Source File: E:\hhsinternal\multiclasses.aspx Line: 108
I tried this on .NET 1.1 and 2.0 Beta. I don't have any .NET 1.0 machines to
see if this worked or not. I'm hoping one of you experts can show me the
errors of my coding ways.
Here's the full code if needed:
<script runat="server">
Public Class VehicleKey
Private _Shape As Integer
Public Sub New(ByVal newShape As Integer)
_Shape = newShape
End Sub
Public ReadOnly Property Shape() As Integer
Get
Return _Shape
End Get
End Property
End Class
Public Class Car
Private _Color As String
Private _Gear As Integer
Private _Ignition As Integer
Private _EngineRunning As Boolean
Private Shared _Count = 0
Public Shared ReadOnly Property Count() As Integer
Get
Return _Count
End Get
End Property
Public Property Color() As String
Get
Return _Count
End Get
Set(ByVal value As String)
_Color = value
End Set
End Property
Public ReadOnly Property Gear() As Integer
Get
Return _Gear
End Get
End Property
Public ReadOnly Property IsRunning() As String
Get
If _EngineRunning Then
Return "The engine is running."
Else
Return "The Engine Is Not Running!"
End If
End Get
End Property
Public Overloads Sub ChangeGear(ByVal direction As Integer)
If direction < 0 Then _Gear = Gear - 1
If direction > 0 Then _Gear = Gear + 1
If _Gear > 5 Then _Gear = 5
If _Gear < -1 Then _Gear = -1
End Sub
Public Overloads Sub ChangeGear(ByVal direction As String)
If direction = "down" Then ChangeGear(-1)
If direction = "up" Then ChangeGear(+1)
End Sub
Public Sub Ignition(ByVal IgnitionKey As VehicleKey)
If IgnitionKey.Shape = _Ignition Then _EngineRunning = True
End Sub
Public Sub EngineOff()
_EngineRunning = False
End Sub
Sub New(ByVal IgnitionShape As Integer)
_Color = "Sparkle Midnight Blue"
_Ignition = IgnitionShape
_Count = Count + 1
End Sub
End Class
Sub Page_Load()
Dim HondaKey As New VehicleKey(123)
Dim DodgeKey As New VehicleKey(456)
Dim PlymouthKey As New VehicleKey(789)
Dim DodgeCar As New Car(456)
Response.Write("<div style=""font-family: arial; font-size: 110%;"">New
Object DodgeCar Created.</div>")
Response.Write("<br />Color: " & DodgeCar.Color)
Response.Write("<br />Gear: " & DodgeCar.Gear)
DodgeCar.Color = "Silver"
DodgeCar.ChangeGear("up")
Response.Write("<br /><b>Properties Updated</b>")
Response.Write("<br/>New Color: " & DodgeCar.Color)
Response.Write("<br/>New Gear: " & DodgeCar.Gear)
DodgeCar.ChangeGear(+1)
Response.Write("<br/>Shfted the gear up one.")
Response.Write("<br/>New Gear: " & DodgeCar.Gear)
Response.Write("<br/>Attempting to start DodgeCar with PlymouthKey: ")
DodgeCar.Ignition(789)
Response.Write(DodgeCar.IsRunning)
Response.Write("<hr/>Attempting To Start DodgeCar with HondaKey: ")
DodgeCar.Ignition(123)
Response.Write(DodgeCar.IsRunning)
Response.Write("<hr/>Attempting To Start DodgeCar with DodgeKey: ")
DodgeCar.Ignition(456)
Response.Write(DodgeCar.IsRunning)
Response.Write("<br/>Attempting to stop DodgeCar: ")
DodgeCar.EngineOff()
Response.Write(DodgeCar.IsRunning)
End Sub
</script>
Thanks,
Jim