Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Is it possible to emulate a ten-key entry in Excel? | Excel Discussion (Misc queries) | |||
How do u emulate nesting seven IF functions in a cell? | Excel Worksheet Functions | |||
selection.copy - how emulate Paste command? | Excel Discussion (Misc queries) | |||
How do I emulate rightclick on a hyperlink in an Excel Macro | Excel Discussion (Misc queries) | |||
How can I emulate MROUND in VBA | Excel Programming |