PC Review


Reply
Thread Tools Rate Thread

Class struggle

 
 
=?Utf-8?B?RGF2aWQgR2Vyc3RtYW4=?=
Guest
Posts: n/a
 
      11th Sep 2007
I'm trying to set up a class in the VBE.

It doesn't make a difference if I try to include it in the regular or in a
class module,

when I write the following (for example)
Class budget
Public food As Currency
Public car As Currency
Public fun As Currency

end class

And hit return the "end class" gets flagged and I get
"Compile error:
Expected: If or Select or Sub or Function or Property or Type or With or
Enum of end of Statement."

What am I doing wrong? (I've also cut and pasted code for a class from MSDN
and gotten the same error.)

Or is there something wrong with my installation of VBA?

David
 
Reply With Quote
 
 
 
 
Jim Rech
Guest
Posts: n/a
 
      11th Sep 2007
I don't know if VB.NET supports a "class" declaration but VBA 6.0 in Excel
doesn't as far as I know.

If you're defining a user defined variable you would use this:

Type Budget
Public food As Currency
Public car As Currency
Public fun As Currency
End Type


--
Jim
"David Gerstman" <(E-Mail Removed)> wrote in message
news:BB8C3D91-636E-4CAE-BB47-(E-Mail Removed)...
| I'm trying to set up a class in the VBE.
|
| It doesn't make a difference if I try to include it in the regular or in a
| class module,
|
| when I write the following (for example)
| Class budget
| Public food As Currency
| Public car As Currency
| Public fun As Currency
|
| end class
|
| And hit return the "end class" gets flagged and I get
| "Compile error:
| Expected: If or Select or Sub or Function or Property or Type or With or
| Enum of end of Statement."
|
| What am I doing wrong? (I've also cut and pasted code for a class from
MSDN
| and gotten the same error.)
|
| Or is there something wrong with my installation of VBA?
|
| David


 
Reply With Quote
 
George Nicholson
Guest
Posts: n/a
 
      11th Sep 2007
I have used classes in Excel a lot, and I can only tell you what's worked
for me (up to & including XL & Access 2003):

- Insert a Class Module.
- The name of that module is the name of your class.
- Add Variable declarations, Properties & Methods as desired.
- No Class...End Class structure is necessary. In fact (fwiw), my language
references don't even show the existence of a "End Class" statement. They
show 'End Enum', 'End Type', 'End Property', etc., etc., but no 'End Class'.


HTH,


"David Gerstman" <(E-Mail Removed)> wrote in message
news:BB8C3D91-636E-4CAE-BB47-(E-Mail Removed)...
> I'm trying to set up a class in the VBE.
>
> It doesn't make a difference if I try to include it in the regular or in a
> class module,
>
> when I write the following (for example)
> Class budget
> Public food As Currency
> Public car As Currency
> Public fun As Currency
>
> end class
>
> And hit return the "end class" gets flagged and I get
> "Compile error:
> Expected: If or Select or Sub or Function or Property or Type or With or
> Enum of end of Statement."
>
> What am I doing wrong? (I've also cut and pasted code for a class from
> MSDN
> and gotten the same error.)
>
> Or is there something wrong with my installation of VBA?
>
> David



 
Reply With Quote
 
=?Utf-8?B?RGF2aWQgR2Vyc3RtYW4=?=
Guest
Posts: n/a
 
      11th Sep 2007
I am dealing with VBA 6.0, so that seems to work.

Thank you,

David

"Jim Rech" wrote:

> I don't know if VB.NET supports a "class" declaration but VBA 6.0 in Excel
> doesn't as far as I know.
>
> If you're defining a user defined variable you would use this:
>
> Type Budget
> Public food As Currency
> Public car As Currency
> Public fun As Currency
> End Type
>
>
> --
> Jim
> "David Gerstman" <(E-Mail Removed)> wrote in message
> news:BB8C3D91-636E-4CAE-BB47-(E-Mail Removed)...
> | I'm trying to set up a class in the VBE.
> |
> | It doesn't make a difference if I try to include it in the regular or in a
> | class module,
> |
> | when I write the following (for example)
> | Class budget
> | Public food As Currency
> | Public car As Currency
> | Public fun As Currency
> |
> | end class
> |
> | And hit return the "end class" gets flagged and I get
> | "Compile error:
> | Expected: If or Select or Sub or Function or Property or Type or With or
> | Enum of end of Statement."
> |
> | What am I doing wrong? (I've also cut and pasted code for a class from
> MSDN
> | and gotten the same error.)
> |
> | Or is there something wrong with my installation of VBA?
> |
> | David
>
>
>

 
Reply With Quote
 
=?Utf-8?B?RGF2aWQgR2Vyc3RtYW4=?=
Guest
Posts: n/a
 
      11th Sep 2007
Is there anyway to rename to the class module? Or am I stuck with Class1,
Class2 etc.

I have seen code samples with the Class ... End Class structure. But not
frequently.

Thanks very much,

David

"George Nicholson" wrote:

> I have used classes in Excel a lot, and I can only tell you what's worked
> for me (up to & including XL & Access 2003):
>
> - Insert a Class Module.
> - The name of that module is the name of your class.
> - Add Variable declarations, Properties & Methods as desired.
> - No Class...End Class structure is necessary. In fact (fwiw), my language
> references don't even show the existence of a "End Class" statement. They
> show 'End Enum', 'End Type', 'End Property', etc., etc., but no 'End Class'.
>
>
> HTH,
>
>
> "David Gerstman" <(E-Mail Removed)> wrote in message
> news:BB8C3D91-636E-4CAE-BB47-(E-Mail Removed)...
> > I'm trying to set up a class in the VBE.
> >
> > It doesn't make a difference if I try to include it in the regular or in a
> > class module,
> >
> > when I write the following (for example)
> > Class budget
> > Public food As Currency
> > Public car As Currency
> > Public fun As Currency
> >
> > end class
> >
> > And hit return the "end class" gets flagged and I get
> > "Compile error:
> > Expected: If or Select or Sub or Function or Property or Type or With or
> > Enum of end of Statement."
> >
> > What am I doing wrong? (I've also cut and pasted code for a class from
> > MSDN
> > and gotten the same error.)
> >
> > Or is there something wrong with my installation of VBA?
> >
> > David

>
>
>

 
Reply With Quote
 
George Nicholson
Guest
Posts: n/a
 
      11th Sep 2007
A module is pretty much like any other object. You can change its
properties, including Name, in the Properties window.

In the VBE: View>Properties (F4). Under the properties for the Module, you
can change the Name of Class1 to whatever your heart desires (as long as
it's comprised of legal characters, etc.).

BTW, the same is also true for General code modules. modAppVariables,
modGeneralFunctions, modFormHandling, modStringHandling, modArrayHandling...

HTH,

"David Gerstman" <(E-Mail Removed)> wrote in message
news:66C2867E-C0A8-4BB0-8DD7-(E-Mail Removed)...
> Is there anyway to rename to the class module? Or am I stuck with Class1,
> Class2 etc.
>
> I have seen code samples with the Class ... End Class structure. But not
> frequently.
>
> Thanks very much,
>
> David
>
> "George Nicholson" wrote:
>
>> I have used classes in Excel a lot, and I can only tell you what's worked
>> for me (up to & including XL & Access 2003):
>>
>> - Insert a Class Module.
>> - The name of that module is the name of your class.
>> - Add Variable declarations, Properties & Methods as desired.
>> - No Class...End Class structure is necessary. In fact (fwiw), my
>> language
>> references don't even show the existence of a "End Class" statement. They
>> show 'End Enum', 'End Type', 'End Property', etc., etc., but no 'End
>> Class'.
>>
>>
>> HTH,
>>
>>
>> "David Gerstman" <(E-Mail Removed)> wrote in message
>> news:BB8C3D91-636E-4CAE-BB47-(E-Mail Removed)...
>> > I'm trying to set up a class in the VBE.
>> >
>> > It doesn't make a difference if I try to include it in the regular or
>> > in a
>> > class module,
>> >
>> > when I write the following (for example)
>> > Class budget
>> > Public food As Currency
>> > Public car As Currency
>> > Public fun As Currency
>> >
>> > end class
>> >
>> > And hit return the "end class" gets flagged and I get
>> > "Compile error:
>> > Expected: If or Select or Sub or Function or Property or Type or With
>> > or
>> > Enum of end of Statement."
>> >
>> > What am I doing wrong? (I've also cut and pasted code for a class from
>> > MSDN
>> > and gotten the same error.)
>> >
>> > Or is there something wrong with my installation of VBA?
>> >
>> > David

>>
>>
>>



 
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
Can anyone help toolbar struggle Rivers Microsoft Excel Programming 5 2nd Nov 2008 12:04 AM
Phew what a struggle !! Abarbarian Gaming 11 25th Nov 2007 11:48 PM
Concatenation Struggle =?Utf-8?B?RGFycmlu?= Microsoft Excel Programming 4 14th Feb 2006 10:04 PM
SDI / MDI / The struggle for efficiency (NOT the default) Uriel Microsoft Word Document Management 0 25th Dec 2005 03:50 PM
Struggle with The Move to .NET =?Utf-8?B?TWljaGFlbCBHZWlzdA==?= Microsoft ASP .NET 21 24th Nov 2004 09:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:21 AM.