declaration expected was unexpected

B

baret bonden

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
 
H

Herfried K. Wagner [MVP]

baret bonden said:
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?
 
B

baret bonden

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"
 
L

Larry Serflaten

baret bonden said:
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
 
H

Herfried K. Wagner [MVP]

baret bonden said:
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
///
 
B

baret bonden

Got it; works fine; many thanks !


Herfried K. Wagner said:
and

That's OK.


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
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top