rian
asked on
Converson of C- UNION struct into VB
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;
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;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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.
hearing...
'-- 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