Emulate C/C++ struct in VBA?

G

Guest

I was wondering if there is a way to emulate a struct?

I have a series of statistics I am collecting from a
spreadsheet and I would like one container for a number of
different data types to hold those statistics (top 5 most
used tests, most expensive test, etc.).

Do I have to implement a whole VBA class do be able to do
this?

If I do, can someone point me to a tutorial on
implementing VBA classes as I've only been using VBA for
perhaps two weeks.

Thanks
 
C

Chip Pearson

In VBA, structures are created with the Type statement. E.g.,


Type TheType
X As Long
Y As Long
Z As Long
End Type

Note that Types must be declared outside of any procedures, but
variables of that type may be declared within procedures:

Sub AAA()
Dim T As TheType
' more code
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
G

Guest

Thanks for your reply

I defined one as:

Private Type Test
ID As String
Name As String
Price As Double
End Type

and then defined an array:

Dim Tests(3000) As Test

Now what happens is Excel (2000) will crash and display a
a messagebox saying (Win2K Pro - OS):

***
EXCEL.exe has generated errors and will be closed by
Windows. You will need to restart the program.

An Error log is being created.
***

unless I disable Macros or comment out the new type. This
without even running any of the code working on that array.

Am I hitting some kind of memory limit?

And where is this error log actually being written to?
 
D

Daniel P.

Dude, move to Excel 2003 and use an assembly written in .NET.
Forget about VBA! Use a real programming language like C# or managed C++.
 
G

Guest

-----Original Message-----
Dude, move to Excel 2003 and use an assembly written
in .NET.
Forget about VBA! Use a real programming language like C#
or managed C++.

[sarcasm] Thanks for the great reply! [/sarcasm]

You sound like you are perhaps still in high school or in
college and have not entered into the real world.

Once you do, you'll learn that you have to use what's
available, because a company will not necessarily upgrade
their systems or software just to make their programmers
happy.

So perhaps in the future, maybe you could better spend
your time doing something more productive than posting a
completely useless reply.

As for this reply, it was not a waste if it actually makes
you think.
 
K

KJTFS

*
You sound like you are perhaps still in high school or in
college and have not entered into the real world.
*


LOL, I was thinking the same thing. I wish my company would upgrade t
2003 and give me visual studio. NET I am happy they upgraded to XP..

Keith
www.kjtfs.co
 
D

Daniel P.

-----Original Message-----
Dude, move to Excel 2003 and use an assembly written
in .NET.
Forget about VBA! Use a real programming language like C#
or managed C++.

[sarcasm] Thanks for the great reply! [/sarcasm]

You sound like you are perhaps still in high school or in
college and have not entered into the real world.

You are making assumptions. My email was just wishful thinking because I too
have to put up with VBA and other old tehcnologies.
 
G

Guest

I defined one as:
Private Type Test
ID As String
Name As String
Price As Double
End Type

and then defined an array:

Dim Tests(3000) As Test

The error was being caused by having the array being
declared Global. Once I made it Local to a subroutine, it
worked correctly.
 

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