This is a bit of an intellectual exercise. I am trying to gain more knowledge on the use of CLASS.
I think I understand the principle, have read bits-and-bobs on their use but have never have real use for them. I think I created my own CLASS for one program
This is mainly because I do simple coding for my own use.
I am looking at an old vba programme which parse data from a file, data is extracted and value put in excel – Standard stuff
The simple workflow is
Read the whole file
Split the file content into blocks at a specific “header”
Process each block
Split the block into lines
Process each line
If the line contains specific string then split line , extract data
It works just fine (speed is not an issue as the file is not very large)
A typical block data is shown at the end of thread. The 1st line is always the dashed line as it is the “header” used to split the file into blocks
The question
Could a CLASS be used to get the data wanted? For example
The example would return an array (3 values) containing the data from the line after the containing the keyword ‘ INERTIA at CENTER OF GRAVITY with respect to _YYYYYY’
This is what the current code does for a given block
Example of a block data - The 1st line is always the dashed line as it is the “header” used to split the file into blocks
---------------------------------------------
MASS PROPERTIES FOR XXXXX
VOLUME = 3.0237829e+01
SURFACE AREA = 9.8488930e+01
DENSITY = 2.7000000e-03
MASS = 8.1642139e-02
CENTER OF GRAVITY with respect to _ XXXXX coordinate frame:
X Y Z 0.0000000e+00 2.5000000e+00 0.0000000e+00
INERTIA at CENTER OF GRAVITY with respect to _ XXXXX coordinate frame
INERTIA TENSOR:
Ixx Ixy Ixz 2.5226579e-01 0.0000000e+00 0.0000000e+00
Iyx Iyy Iyz 0.0000000e+00 1.6435583e-01 0.0000000e+00
Izx Izy Izz 0.0000000e+00 0.0000000e+00 2.5226562e-01
PRINCIPAL MOMENTS OF INERTIA
I1 I2 I3 1.6435583e-01 2.5226535e-01 2.5226606e-01
CENTER OF GRAVITY with respect to _YYYYYY coordinate frame:
X Y Z -8.5350000e+01 2.1200000e+02 -9.0750000e+01
INERTIA at CENTER OF GRAVITY with respect to _YYYYYY coordinate frame
INERTIA TENSOR:
Ixx Ixy Ixz 1.6435583e-04 0.0000000e+00 0.0000000e+00
Iyx Iyy Iyz 0.0000000e+00 2.5226579e-04 0.0000000e+00
Izx Izy Izz 0.0000000e+00 0.0000000e+00 2.5226562e-04
I think I understand the principle, have read bits-and-bobs on their use but have never have real use for them. I think I created my own CLASS for one program
This is mainly because I do simple coding for my own use.
I am looking at an old vba programme which parse data from a file, data is extracted and value put in excel – Standard stuff
The simple workflow is
Read the whole file
Split the file content into blocks at a specific “header”
Process each block
Split the block into lines
Process each line
If the line contains specific string then split line , extract data
It works just fine (speed is not an issue as the file is not very large)
A typical block data is shown at the end of thread. The 1st line is always the dashed line as it is the “header” used to split the file into blocks
The question
Could a CLASS be used to get the data wanted? For example
VBA Code:
Dim Cdb As ClassDatablock
Set Cdb = New ClassDatablock
'And in the main code
CG = Cdb.GettheCG()
'And so on for each “attribute” wanted
The example would return an array (3 values) containing the data from the line after the containing the keyword ‘ INERTIA at CENTER OF GRAVITY with respect to _YYYYYY’
This is what the current code does for a given block
VBA Code:
For i = 0 to lastline
Check if line contains keyword
If true then select next line (i+1)
Split line at the space
Get field (3,4,5)
Example of a block data - The 1st line is always the dashed line as it is the “header” used to split the file into blocks
---------------------------------------------
MASS PROPERTIES FOR XXXXX
VOLUME = 3.0237829e+01
SURFACE AREA = 9.8488930e+01
DENSITY = 2.7000000e-03
MASS = 8.1642139e-02
CENTER OF GRAVITY with respect to _ XXXXX coordinate frame:
X Y Z 0.0000000e+00 2.5000000e+00 0.0000000e+00
INERTIA at CENTER OF GRAVITY with respect to _ XXXXX coordinate frame
INERTIA TENSOR:
Ixx Ixy Ixz 2.5226579e-01 0.0000000e+00 0.0000000e+00
Iyx Iyy Iyz 0.0000000e+00 1.6435583e-01 0.0000000e+00
Izx Izy Izz 0.0000000e+00 0.0000000e+00 2.5226562e-01
PRINCIPAL MOMENTS OF INERTIA
I1 I2 I3 1.6435583e-01 2.5226535e-01 2.5226606e-01
CENTER OF GRAVITY with respect to _YYYYYY coordinate frame:
X Y Z -8.5350000e+01 2.1200000e+02 -9.0750000e+01
INERTIA at CENTER OF GRAVITY with respect to _YYYYYY coordinate frame
INERTIA TENSOR:
Ixx Ixy Ixz 1.6435583e-04 0.0000000e+00 0.0000000e+00
Iyx Iyy Iyz 0.0000000e+00 2.5226579e-04 0.0000000e+00
Izx Izy Izz 0.0000000e+00 0.0000000e+00 2.5226562e-04