473,320 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Value of type 'Integer' cannot be converted

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
Nov 21 '05 #1
2 7177

"Compiler Error Message: BC30311: Value of type 'Integer' cannot be
converted to 'ASP.multiclasses_aspx.VehicleKey'."

It is expecting a VehicleKey type of object. You can not send in an
Interger when it expects a VehicleKey type.

From what your code looks like you could do something like:
Line 108: DodgeCar.Ignition(new VehicleKey(789))

Or since you defined did: "Dim PlymouthKey As New VehicleKey(789)" you could
just pass in PlymouthKey
Line 108: DodgeCar.Ignition(PlymouthKey)
Make sure you turn "Option Strict On" This will help you figure these
errors out at design time.

Hope this helps
Chris
"Jim in Arizona" <ti*******@hotmail.com> wrote in message
news:eU******************@TK2MSFTNGP11.phx.gbl...
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

Nov 21 '05 #2
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:eE***************@TK2MSFTNGP10.phx.gbl...

"Compiler Error Message: BC30311: Value of type 'Integer' cannot be
converted to 'ASP.multiclasses_aspx.VehicleKey'."

It is expecting a VehicleKey type of object. You can not send in an
Interger when it expects a VehicleKey type.

From what your code looks like you could do something like:
Line 108: DodgeCar.Ignition(new VehicleKey(789))

Or since you defined did: "Dim PlymouthKey As New VehicleKey(789)" you
could just pass in PlymouthKey
Line 108: DodgeCar.Ignition(PlymouthKey)
Make sure you turn "Option Strict On" This will help you figure these
errors out at design time.

Hope this helps
Chris


--------SNIP-----------
That was exactly what I needed to know. Actually, it was similar in the book
and somehow along the way I must of stopped paying attention to what I was
doing.

Thanks Chris.
Jim
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Supra | last post by:
: error BC30311: Value of type 'System.Drawing.Color' cannot be converted to 'Integer'. Function doColor(ByVal rtb As RichTextBox, ByVal a As String, Optional ByVal f As Integer = 0, Optional...
9
by: ckerns | last post by:
I want to loop thru an array of controls,(39 of them...defaults = 0). If value is null or non-numeric I want to assign the value of "0". rowString = "L411" //conrol name if (isNaN(eval...
12
by: Francois Grieu | last post by:
The values of ((int)0.7) and ((int)-0.7) seem to be 0 Is this independent of implementation ? TIA, François Grieu
16
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. ...
23
by: Tomás | last post by:
Anything wrong with the following code?: #include <cstdlib> int main() { for (unsigned i = 0; i != 1000; ++i) { int *p = reinterpret_cast<int*>( std::rand() );
40
by: Zach | last post by:
Can someone please explain what this means and illustrate the difference with some code. Thanks, Zach
3
by: cmdolcet69 | last post by:
I can the following error message "value of type byte cannot be converted to 1-dimentional array of byte" when i execute this line of code: moRS232.Write(Packet(i)) it underline the packet(i)...
69
by: Horacius ReX | last post by:
Hi, I have the following program structure: main ..... int A=5; int* ptr= A; (so at this point ptr stores address of A) ..... .....
14
by: KK | last post by:
Dear All I have a small problem with using as operator on value type array. Here is an example what I am trying to do. using System; using System.Collections.Generic; using System.Text;
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.