Solved

Converson of C- UNION struct  into VB

Posted on 2001-07-02
5
305 Views
Last Modified: 2011-09-20
How does one convert the following C structure into VB type. Especially the UNION. I have to keep the same type .Thanks

typedef struct ELEMENT2
{
  int type;                            
  int flip;                          
  char pc1_stkno[65];
  double wt;
  union
  {
    struct    
    {
      double od;              
      double id;              
      double thk;              
      double hod;              
      double hthk;            
      double fod;              
      double fthk;            
      double bc;              
      double bh;
      double collar_od;        
      double collar_id;        
      double collar_length;
    } fr;                        
    struct        
    {
      double od;              
      double id;              
      double thk;              
      double hod;              
      double hthk;            
      double bc;              
      double bh;
      double collar_od;        
      double collar_id;        
      double collar_length;
    } ff;                    
   } params;
} entity;
0
Comment
Question by:rian
  • 3
5 Comments
 
LVL 28

Accepted Solution

by:
AzraSound earned 100 total points
Comment Utility
try just declaring as a Variant, e.g.,


Type ELEMENT2
   type As Integer
   flip As Integer
   pc1_stkno As String
   wt As Double
   params As Variant
End Type
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
you may have problems coercing your two UDTs that make up the union into a Variant data type.  if so, you will probably want to work with classes instead.  create your interface class sharing the common properties between the two unioned structures, and then create two classes to represent those structures which implement your common interface. e.g.,


'-- IParams class

Property Get od() As Double
End Property
Property let od(ByVal Newod As Double)
End Property

Property Get id() As Double
End Property
Property Let id(ByVal Newid As Double)
End Property

'etc for the COMMON values the two structures share



'-- Structure1 class

Implements IParams

'fill in required values for interface

'then add properties not included in the interface



'-- Structure2 class

Implements Iparams

'fill in required values for interface - this should cover all of the properties the class requires




then your common type can be:

Type ELEMENT2
   type As Integer
   flip As Integer
   pc1_stkno As String
   wt As Double
   params As IParams
End Type


and youll be able to pass as the params argument, either an instance of Structure1 or an instance of Structure2
0
 
LVL 4

Expert Comment

by:WolfgangKoenig
Comment Utility
You can't restict string datatype in VB and there is no
union datatype only type...
Your struct is in VB the following:
Type frfr
    od As Double
    id As Double
    thk As Double
    hod As Double
    hthk As Double
    fod As Double
    fthk As Double
    bc As Double
    bh As Double
    collar_od As Double
    collar_id As Double
    collar_length As Double
End Type

Type ffff
    od As Double
    id As Double
    thk As Double
    hod As Double
    hthk As Double
    bc As Double
    bh As Double
    collar_od As Double
    collar_id As Double
    collar_length As Double
End Type

Type paramsparams
  fr As frfr
  ff As ffff
End Type

Type ELEMENT2
 type As Integer
 flip As Integer
 pc1_stkno As String
 wt As Double
 params As paramsparams
End Type

Dim Entity As ELEMENT2

Nice day!
WoK
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
well if the idea is to be able to pass an object arbitrary of its type, then you will need to use interfaces.  otherwise, as mentioned, you will just have to implicitly declare each type you want to use in your structure.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
hearing...
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

772 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

10 Experts available now in Live!

Get 1:1 Help Now