469,331 Members | 6,053 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,331 developers. It's quick & easy.

declaration expected was unexpected



Trying to learn OOP. Pasted some MS example code inside a form class(but of
course made the test class outside of the form class);

I get "declaration epected" pointing to"Currentsale" ; this is the same
error I get with my own test code....

Dim CurrentSale As New SalesRecord

CurrentSale.CustomerName = "Matthew"

Public Class SalesRecord

Private _CustomerName As String

Private _Total As Decimal

Public Property CustomerName() As String

Get

Return _CustomerName

End Get

Set(ByVal Value As String)

_CustomerName = Value

End Set

End Property

Public Property Total() As Decimal

Get

Return _Total

End Get

Set(ByVal Value As Decimal)

If Value >= 0 Then

_Total = Value

Else

' Raise an error here.

End If

End Set

End Property

Public Function EstimateLatePaymentCost(ByVal _

YearsLate As Single) As Decimal

' Assuming 5%/year late payment fee.

Return (_Total * (1 + YearsLate * 0.05))

End Function

End Class
Nov 21 '05 #1
5 2686
"baret bonden" <ar****@networks-cc.com> schrieb:
Trying to learn OOP. Pasted some MS example code
inside a form class(but of course made the test class
outside of the form class);

I get "declaration epected" pointing to"Currentsale" ; this is the same
error I get with my own test code....

Dim CurrentSale As New SalesRecord

CurrentSale.CustomerName = "Matthew"


Where did you place this code?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #2
I put the class at the end of a windows form, outside the form's class , and
I put the

Dim CurrentSale As New SalesRecord
CurrentSale.CustomerName = "Matthew"

simply inside the form's clode
as in:

Public Class test

Inherits System.Windows.Forms.Form

dim CurrentSale As New SalesRecord

CurrentSale.CustomerName = "Matthew"
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ed*************@TK2MSFTNGP11.phx.gbl...
"baret bonden" <ar****@networks-cc.com> schrieb:
Trying to learn OOP. Pasted some MS example code
inside a form class(but of course made the test class
outside of the form class);

I get "declaration epected" pointing to"Currentsale" ; this is the same
error I get with my own test code....

Dim CurrentSale As New SalesRecord

CurrentSale.CustomerName = "Matthew"


Where did you place this code?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #3

"baret bonden" <ar****@networks-cc.com> wrote
in message news:2u*************@uni-berlin.de...

Public Class test

Inherits System.Windows.Forms.Form

dim CurrentSale As New SalesRecord

CurrentSale.CustomerName = "Matthew"


Executable code has to be placed in a procedure. You need
to place that last line in a Sub or Function....

LFS
Nov 21 '05 #4
"baret bonden" <ar****@networks-cc.com> schrieb:
I put the class at the end of a windows form, outside the form's class , and

That's OK.
I put the

Dim CurrentSale As New SalesRecord
CurrentSale.CustomerName = "Matthew"

simply inside the form's clode
as in:

Public Class test

Inherits System.Windows.Forms.Form

dim CurrentSale As New SalesRecord

CurrentSale.CustomerName = "Matthew"


You will have to put the code into a procedure (at least the 2nd line), for
example (inside your class):

\\\
Public Sub Foo()
Dim CurrentSale As New SalesRecord()
CurrentSale.CustomerName = "Matthew"
...
End Sub
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #5
Got it; works fine; many thanks !
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:#n**************@TK2MSFTNGP14.phx.gbl...
"baret bonden" <ar****@networks-cc.com> schrieb:
I put the class at the end of a windows form, outside the form's class , and

That's OK.
I put the

Dim CurrentSale As New SalesRecord
CurrentSale.CustomerName = "Matthew"

simply inside the form's clode
as in:

Public Class test

Inherits System.Windows.Forms.Form

dim CurrentSale As New SalesRecord

CurrentSale.CustomerName = "Matthew"


You will have to put the code into a procedure (at least the 2nd line),

for example (inside your class):

\\\
Public Sub Foo()
Dim CurrentSale As New SalesRecord()
CurrentSale.CustomerName = "Matthew"
...
End Sub
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by =?Utf-8?B?Y2FzaGRlc2ttYWM=?= | last post: by
1 post views Thread by haryvincent176 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.