?
Solved

Converson of C- UNION struct  into VB

Posted on 2001-07-02
5
Medium Priority
?
316 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 28

Accepted Solution

by:
AzraSound earned 300 total points
ID: 6245410
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
ID: 6245474
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
ID: 6245563
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
ID: 6245667
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
ID: 6246132
hearing...
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

771 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