Class struggle

D

David Gerstman

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
 
J

Jim Rech

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

George Nicholson

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,
 
D

David Gerstman

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
 
G

George Nicholson

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,
 

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