Defining a Data Type array in VBA

Daveyk01

Registered User.
Local time
Today, 11:33
Joined
Jul 3, 2007
Messages
144
Hello there. This eaxmple is from C+, I think. I am tryijng to interpret data fed back in to VBA via the serial port of an instrument (UI am using a comm library).

Anyway, I was told it was simple... here is all that you need to do...

typedef struct // DATATYPE DEFINITION - Gate Data Results
{ //
unsigned long ulAmp; // Gate Amplitude Value
#define GATE_AMP_STATE_MASK 0x80000000 // bit 31: Gate Amplitude Status
#define GATE_AMP_VALID (GATE_AMP_STATE_MASK * 0) // 0: gate amplitude is valid
#define GATE_AMP_INVALID (GATE_AMP_STATE_MASK * 1) // 1: gate amplitude is invalid
#define GATE_ALARM_STATE_MASK 0x40000000 // bit 30: Gate Alarm Status
#define GATE_ALARM_ACTIVE (GATE_ALARM_STATE_MASK * 0) // 0: gate alarm active
#define GATE_ALARM_INACTIVE (GATE_ALARM_STATE_MASK * 1) // 1: gate alarm inactive
// bits 29 -> 23: <unused>
#define GATE_ACCUM_CYCLE_MASK 0x007f0000 // bits 22 -> 16: Accumulated Amp Cycle Number - 1
#define GATE_ACCUM_CYCLE_SHIFT 16 // NOTE: valid on for ulAccumIFGateAmp,
// ulAccumAGateAmp, ulAccumBGateAmp
// bits 15 -> 12: <unused>
#define GATE_AMP_MASK 0x00000fff // bits 11 -> 0: Gate Amplitude Value (rectified)
#define GATE_AMP_FS 0x00000fff // 4095 counts = 100%
#define GATE_AMP_BASELINE 0x0000 // 0 counts = 0%
// SCREEN % = 100 - ((100 * (0xfff - AMP)) / 0xfff)
unsigned long ulTOF; // Gate Time Of Flight Value
#define GATE_TOF_STATE_MASK 0x80000000 // bit 31: Gate Time Of Flight Status
#define GATE_TOF_VALID (GATE_TOF_STATE_MASK * 0) // 0: gate TOF is valid
#define GATE_TOF_INVALID (GATE_TOF_STATE_MASK * 1) // 1: gate TOF is invalid
// bits 30 -> 20: <unused>
#define GATE_TOF_MASK 0x000fffff // bits 19 -> 0: Gate Time Of Flight Value
// 1 count = 5 ns
// Relative to SAP if gate is IP started
// Relative to IF TOF if gate is IF started
} STR_GATE_RESULT;

How do I do this in VBA?
 
VBA and C++ differ in some ways. You don't really need to specifically declare a different name for a LONG. It's just a LONG.

As to the individual lines of bit-masking...

I'm going to declare a few of your variables as examples. I choose to declare them as PUBLIC but you could choose PRIVATE (or leave it unstated).

PUBLIC CONST GATE_AMP_STATE_MASK &H80000000

PUBLIC CONST GATE_ALARM_STATE_MASK &H40000000

PUBLIC CONST GATE_ACCUM_CYCLE_MASK &H007F0000

PUBLIC CONST GATE_TOF_MASK &H000FFFFF
 

Users who are viewing this thread

Back
Top Bottom