PC Review


Reply
Thread Tools Rate Thread

declaration expected was unexpected

 
 
baret bonden
Guest
Posts: n/a
 
      24th Oct 2004


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


 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      24th Oct 2004
"baret bonden" <(E-Mail Removed)> 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/>


 
Reply With Quote
 
baret bonden
Guest
Posts: n/a
 
      24th Oct 2004
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]" <hirf-spam-me-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "baret bonden" <(E-Mail Removed)> 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/>
>
>



 
Reply With Quote
 
Larry Serflaten
Guest
Posts: n/a
 
      24th Oct 2004

"baret bonden" <(E-Mail Removed)> wrote
in message news:(E-Mail Removed)...
>
> 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
 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      25th Oct 2004
"baret bonden" <(E-Mail Removed)> 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/>


 
Reply With Quote
 
baret bonden
Guest
Posts: n/a
 
      25th Oct 2004
Got it; works fine; many thanks !


"Herfried K. Wagner [MVP]" <hirf-spam-me-(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> "baret bonden" <(E-Mail Removed)> 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/>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declaration Expected eBob.com Microsoft VB .NET 3 5th May 2006 03:19 PM
declaration expected ? TJS Microsoft ASP .NET 2 29th Oct 2004 01:47 PM
Declaration Expected Simon Harris Microsoft ASP .NET 2 18th Oct 2004 06:21 AM
declaration expected Simon Harris Microsoft ASP .NET 2 3rd Oct 2004 10:03 PM
Declaration Expected? D. Shane Fowlkes Microsoft ASP .NET 9 24th Nov 2003 12:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:32 PM.