Solved

Unions?

Posted on 1998-06-10
10
370 Views
Last Modified: 2010-05-03
Union is not possible in Visual Basic, I think, how do you get around this then?
0
Comment
Question by:k_chen
10 Comments
 
LVL 4

Expert Comment

by:zsi
ID: 1463010
Strike.
0
 

Author Comment

by:k_chen
ID: 1463011
Please, serious answers please.
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1463012
The closest thing we have to unions is the user defined type.  Kind of like saying the closest we have to a battleship is a rubber duck.

Sorry, humour goes with the territory.
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1463013
In C++:
Union {
float f;
int n;
} UDF

In VB:
Type UDF
  f As Single
  n As Integer
End Type
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1463014
Also, unnamed UDTs are not allowed.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Expert Comment

by:JayMerritt
ID: 1463015
Could you be referring to UNION not existing in Access SQL?
0
 

Author Comment

by:k_chen
ID: 1463016
I'm referring to union as how ClifABB described it in C++. Not the SQL command. Another question on Visual Basic's flaw. I don't think it's possible to declare constants in Type Declartion, is it?
0
 
LVL 6

Accepted Solution

by:
clifABB earned 40 total points
ID: 1463017
You are absolutely correct.  Constants aren't allowed in UDTs.

Why did you reject my answer?  It is correct.  (It wasn't the rubber duck joke, was it?)

Perhaps it was an oversight so I will submit this as an answer.
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1463018
By the way...
I've been pondering this all night.  Why would anyone want to declare a constant in a union, struct, or UDT?  It's a very inefficient use of memory.  Every time you construct using the union you would be creating a new copy of the constant, when a single constant, declared globally, would be much more efficient.
0
 

Author Comment

by:k_chen
ID: 1463019
I think the point of having a constant in a UDT is to encapsulate     data objects. You're right, it does not have any merit from efficiency point of view.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now