Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21335

Storing different data types in the same memory space.

$
0
0
I am writing an application to read a motor controller via a serial MODBUS interface. Numeric data is transmitted in IEEE 754 single-precision format, so I have to store each data value in memory as 4 bytes of variable type char, then access the same memory as variable type float. This is easy to do in C using a union:

union
{
float motor_data_float;
char motor_data_char[4];
} motor_data;

The same 4-byte memory space can be accessed as a floating-point variable or as an array of 4 bytes.
How can this be implemented in VB6?

Viewing all articles
Browse latest Browse all 21335

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>