Big thank you to all who helped me with learning how to create a custom class. I had some trouble in the instantiation during runtime vs instantiation via IDE area but I solved all the issues.
I need to make a strategic decision, and I would like some advice.
I am creating a class LabWorkParameter. This class will have the following properties
LabParam.Name as String
LabParam.Abbreviation as String
LabParam.Value as … (?)
LabParam.ReferenceRange as String
LabParam.Units as String
I need to make a decision of what kind of variable would be the Value parameter. Some of the lab work results are doubles such as potassium (4.2 mmol/L) while others are strings such as blood culture result could be “Staph. Aureus.”
Should I use Variant instead of Double and String?
Thank you in advance for any suggestions.
You have different possibilities, here are two:
- make clsValue (I would call it Results myself, but that is your cal) class and declare Value as the class. The clsValus class would contain a stringValue, a DoubleValue etc.
- Make Value a Variant. It will accept pretty much any kind of data.
The value property could even be an array to store many different results for one lab request, regardless of the option you choose. (I know that my blood tests are a long list and many tubes!)
I’ve made a lab work app, and all results are stored as a string. works nice like that.
because sometimes you need a result like “<0.05” and you can’t store it in a variant.
the units are stored as string in another field like you do.
As I was posting, I knew that there had to be a better answer…
Yes, you can. Such string is a string stored in a Variant. Any value can be stored in a Variant.
You need to know what you will do with such value later. Probably just a string is enough, but you must guarantee the integrity of the value, and if using the value for something other then presentation (like calculations) probably you will need a property that makes you know this condition for proper handling/conversions (including, maybe, number of decimals digits to store). Or even having a shadow equivalent Double property storing its full calculated value. Many options.
should have said “you can’t store it in a double” …
Thank you very much for your replies.
Just to test if can convert between different types of data, I did the following:
- Created an instance of the LabParam with Value as Variant
- Created an instance called Potassium
- Created a Label as an output for the Potassium value
- Created a slider to change the value of the Potassium, and put the following code into the ValueChanged method
Changing the position of the slider I was able to change the Potassium value and it was displayed as a decimal fraction with two digits after the decimal point.
The following code did not produce a decimal fraction for the Potassium value
Instead, it produced a number with 10 with some power. That was still a valid result but not convenient for human reading.
Thank you again for all your help.
look into the format function (which turns a number into a formatted string)… but Scientific Notation happens with Double values once the exceed certain parameters