Board index » Visual Studio » Option strict disallows late binding - newbie

Option strict disallows late binding - newbie

Visual Studio72
I'm a newbie and this is for a school assignment. I've

created a class and assigned a property in the class, but

when I try to access the property, it says that option

strict disallows late binding. Please help!



Here is the code



Public Class PayTotal

Public Shared mdecCommission As Decimal



Sub New()

'Constructor with empty arguments



End Sub



Sub New(ByVal WeeklySales As Decimal)

'Assign property values



Me.WeeklySales = WeeklySales

End Sub



#Region "Properties"



Protected mdecWeeklySales As Decimal



Property WeeklySales() As Decimal

Get

WeeklySales = mdecWeeklySales

End Get

Set(ByVal Value As Decimal)

mdecWeeklySales = Value

End Set

End Property



Overridable ReadOnly Property Commission() As Decimal

Get

Commission = mdecCommission

End Get

End Property



#End Region



#Region "Methods"



Public Overridable Function TotalPay() As Decimal

'Calculate the pay for salesperson



Dim decTotalPay As Decimal

Const decBASE_PAY As Decimal = 250D

Const decCOMMISSION_RATE As Decimal = 0.15D

Const decSALES_QUOTA As Decimal = 1000D



If mdecWeeklySales>decSALES_QUOTA Then

mdecCommission = mdecWeeklySales *

decCOMMISSION_RATE

Else

mdecCommission = 0

End If



decTotalPay = decBASE_PAY + mdecCommission

End Function

#End Region

End Class





Here is where I call for the data:

mSupervisorPay = New SupervisorPayTotal(CInt

(txtWeeklySales.Text))



If mSupervisorPay.commission>0 Then

lblCommission.Text = FormatCurrency

(mSupervisorPay.commission)

lblTotalPay.Text = FormatCurrency

(mSupervisorPay.totalpay)

Else

lblTotalPay.Text = FormatCurrency(mSupervisorPay.totalpay)

End If





Any help would be greatly appreciated.


-
 

Re:Option strict disallows late binding - newbie

At which line does the exception happen? I assume the SupervisorPayTotal

inherits from the PayTotal class.



Keep in mind that when you want to access a member of an inherited class,

you need to cast to that class (when option stricit is on):

Dim a As PayTotal = New SupervisorPayTotal()

Textbox1.Text = a.PayTotal.PropertyOfSupervisorPayTotal

->Will fail



Textbox1.Text = CType(a,

GetType(SupervisorPayTotal)).PropertyOfSupervisorPayTotal



--

Greetz



Jan Tielens

________________________________

Read my weblog: weblogs.asp.net/jan">weblogs.asp.net/jan





"John Perkins" <johnperkins21@yahoo.com>wrote in message

Quote
I'm a newbie and this is for a school assignment. I've

created a class and assigned a property in the class, but

when I try to access the property, it says that option

strict disallows late binding. Please help!



Here is the code



Public Class PayTotal

Public Shared mdecCommission As Decimal



Sub New()

'Constructor with empty arguments



End Sub



Sub New(ByVal WeeklySales As Decimal)

'Assign property values



Me.WeeklySales = WeeklySales

End Sub



#Region "Properties"



Protected mdecWeeklySales As Decimal



Property WeeklySales() As Decimal

Get

WeeklySales = mdecWeeklySales

End Get

Set(ByVal Value As Decimal)

mdecWeeklySales = Value

End Set

End Property



Overridable ReadOnly Property Commission() As Decimal

Get

Commission = mdecCommission

End Get

End Property



#End Region



#Region "Methods"



Public Overridable Function TotalPay() As Decimal

'Calculate the pay for salesperson



Dim decTotalPay As Decimal

Const decBASE_PAY As Decimal = 250D

Const decCOMMISSION_RATE As Decimal = 0.15D

Const decSALES_QUOTA As Decimal = 1000D



If mdecWeeklySales>decSALES_QUOTA Then

mdecCommission = mdecWeeklySales *

decCOMMISSION_RATE

Else

mdecCommission = 0

End If



decTotalPay = decBASE_PAY + mdecCommission

End Function

#End Region

End Class





Here is where I call for the data:

mSupervisorPay = New SupervisorPayTotal(CInt

(txtWeeklySales.Text))



If mSupervisorPay.commission>0 Then

lblCommission.Text = FormatCurrency

(mSupervisorPay.commission)

lblTotalPay.Text = FormatCurrency

(mSupervisorPay.totalpay)

Else

lblTotalPay.Text = FormatCurrency(mSupervisorPay.totalpay)

End If





Any help would be greatly appreciated.





-

Re:Option strict disallows late binding - newbie

"John Perkins" <johnperkins21@yahoo.com>schrieb

Quote
I'm a newbie and this is for a school assignment. I've

created a class and assigned a property in the class, but

when I try to access the property, it says that option

strict disallows late binding. Please help!



[code]



Here is where I call for the data:

mSupervisorPay = New SupervisorPayTotal(CInt

(txtWeeklySales.Text))



If mSupervisorPay.commission>0 Then

lblCommission.Text = FormatCurrency

(mSupervisorPay.commission)

lblTotalPay.Text = FormatCurrency

(mSupervisorPay.totalpay)

Else

lblTotalPay.Text = FormatCurrency(mSupervisorPay.totalpay)

End If



It tried the code, but the declerations for mSupervisorPay and

SupervisorPayTotal are missing. (also the 3 controls but they could be

declared as what they obviously are).





--

Armin



www.plig.net/nnq/nquote.html">www.plig.net/nnq/nquote.html

www.netmeister.org/news/learn2quote.html">www.netmeister.org/news/learn2quote.html



-

Re:Option strict disallows late binding - newbie

* "John Perkins" <johnperkins21@yahoo.com>scripsit:

Quote
I'm a newbie and this is for a school assignment. I've

created a class and assigned a property in the class, but

when I try to access the property, it says that option

strict disallows late binding. Please help!



Add an 'Option Strict Off' on top of your source file.



SCNR



--

Herfried K. Wagner [MVP]

<www.mvps.org/dotnet>">www.mvps.org/dotnet>

-

Re:Option strict disallows late binding - newbie

Solved - Kind of!



I'm still not sure why the late binding thing happens, but I turned strict off and it works. My other problem was that there was no return statement in my base PayTotal class for the values I was looking for.



Thanks for the very quick and helpful respones, it is greatly appreciated.



John

-

Re:Option strict disallows late binding - newbie

* =?Utf-8?B?Sm9obiBQZXJraW5z?= <johnperkins21@yahoo.com>scripsit:

Quote
Solved - Kind of!



;-)



Quote
I'm still not sure why the late binding thing happens, but I turned

strict off and it works.



My response was sort of "joke". It's better ("recommended") to work

with 'Option Strict On'.



--

Herfried K. Wagner [MVP]

<www.mvps.org/dotnet>">www.mvps.org/dotnet>

-

Re:Option strict disallows late binding - newbie



Quote
-----Original Message-----

* =?Utf-8?B?Sm9obiBQZXJraW5z?= <johnperkins21@yahoo.com>

scripsit:

>Solved - Kind of!



;-)



>I'm still not sure why the late binding thing happens,

but I turned

>strict off and it works.



My response was sort of "joke". It's better

("recommended") to work

with 'Option Strict On'.



--

Herfried K. Wagner [MVP]

<www.mvps.org/dotnet>">www.mvps.org/dotnet>

.





Yeah, I caught that. It's weird that it works with strict

off though. I'm still very new to the whole idea of

creating classes though, so I could be doing something

wrong. If anyone is interested, I would like to show you

the whole code so I can learn what I did wrong (if

anything).



I do suspect that VB.net is just plain screwy sometimes

though. I have had a problem with updating my database as

well, and I know for a fact that the code is 100% correct,

it just doesn't work. Strange.



Thanks again for all the help.

-

Re:Option strict disallows late binding - newbie

* <anonymous@discussions.microsoft.com>scripsit:

Quote
Yeah, I caught that. It's weird that it works with strict

off though. I'm still very new to the whole idea of

creating classes though, so I could be doing something

wrong. If anyone is interested, I would like to show you

the whole code so I can learn what I did wrong (if

anything).



I think it's better to split it up to some smaller questions, it's

easier for the reader to answer small questions than reading 100 KB of

code.



;-)



--

Herfried K. Wagner [MVP]

<www.mvps.org/dotnet>">www.mvps.org/dotnet>

-