Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Emulate C/C++ struct in VBA?

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Emulate C/C++ struct in VBA?

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




wrote in message
...
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Emulate C/C++ struct in VBA?

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?


-----Original Message-----
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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Emulate C/C++ struct in VBA?

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++.


wrote in message
...
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?


-----Original Message-----
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




  #5   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Emulate C/C++ struct in VBA?

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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Emulate C/C++ struct in VBA?

*
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

--
Message posted from http://www.ExcelForum.com

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Emulate C/C++ struct in VBA?


Take a look at the following KB article about how to view the error log...

http://support.microsoft.com/?id=308538


Also, you may want to verify that you have the latest serive packs for
office and excel.

http://office.microsoft.com

and then click on downloads

Kendal Ferner
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Emulate C/C++ struct in VBA?

wrote in message
...
-----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]


<supersarcasmYou are welcome!</supersarcasm

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.

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.



  #9   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Emulate C/C++ struct in VBA?

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.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to emulate a ten-key entry in Excel? Garth Hales Excel Discussion (Misc queries) 9 November 28th 06 11:55 AM
How do u emulate nesting seven IF functions in a cell? Arpee Ong Excel Worksheet Functions 2 February 9th 06 06:30 AM
selection.copy - how emulate Paste command? topola Excel Discussion (Misc queries) 1 January 7th 06 03:43 PM
How do I emulate rightclick on a hyperlink in an Excel Macro Emulate RightClick on Hyperlink in Macro Excel Discussion (Misc queries) 0 January 2nd 06 08:40 AM
How can I emulate MROUND in VBA Jay Fincannon Excel Programming 1 August 8th 03 03:39 AM


All times are GMT +1. The time now is 05:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"