# Custom Class

**URL:** <https://forum.xojo.com/t/custom-class/48753>\
**Category:** General\
**Created:** [May 28, 2019, 7:30pm UTC](https://forum.xojo.com/t/custom-class/48753 "2019-05-28T19:30:11Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Val\_Kozmenko](https://forum.xojo.com/letter_avatar_proxy/v4/letter/v/85f322/32.png) [@Val\_Kozmenko](https://forum.xojo.com/u/Val_Kozmenko)\
**Post date:** [May 28, 2019, 7:30pm UTC](https://forum.xojo.com/t/custom-class/48753/1 "2019-05-28T19:30:11Z")

</div>

Hi, guys,

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.

Val

---

<div class="post-metadata">

**Author:** ![Louis\_D](https://forum.xojo.com/letter_avatar_proxy/v4/letter/l/cab0a1/32.png) [@Louis\_D](https://forum.xojo.com/u/Louis_D)\
**Post date:** [May 28, 2019, 8:07pm UTC](https://forum.xojo.com/t/custom-class/48753/2 "2019-05-28T20:07:26Z")

</div>

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!)

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [May 28, 2019, 8:14pm UTC](https://forum.xojo.com/t/custom-class/48753/3 "2019-05-28T20:14:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Louis\_D](https://forum.xojo.com/letter_avatar_proxy/v4/letter/l/cab0a1/32.png) [@Louis\_D](https://forum.xojo.com/u/Louis_D)\
**Post date:** [May 28, 2019, 8:16pm UTC](https://forum.xojo.com/t/custom-class/48753/4 "2019-05-28T20:16:48Z")

</div>

As I was posting, I knew that there had to be a better answer…

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [May 28, 2019, 8:17pm UTC](https://forum.xojo.com/t/custom-class/48753/5 "2019-05-28T20:17:05Z")

</div>

> [@438796:@Jean-Yves Pochez](#):
>
> sometimes you need a result like “\<0.05” and you can’t store it in a variant.

Yes, you can. Such string is a string stored in a Variant. Any value can be stored in a Variant.

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [May 28, 2019, 8:21pm UTC](https://forum.xojo.com/t/custom-class/48753/6 "2019-05-28T20:21:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [May 28, 2019, 8:41pm UTC](https://forum.xojo.com/t/custom-class/48753/7 "2019-05-28T20:41:03Z")

</div>

> [@438799:@Rick Araujo](#):
>
> Yes, you can. Such string is a string stored in a Variant. Any value can be stored in a Variant.

should have said “you can’t store it in a double” …

---

<div class="post-metadata">

**Author:** ![Val\_Kozmenko](https://forum.xojo.com/letter_avatar_proxy/v4/letter/v/85f322/32.png) [@Val\_Kozmenko](https://forum.xojo.com/u/Val_Kozmenko)\
**Post date:** [May 28, 2019, 9:42pm UTC](https://forum.xojo.com/t/custom-class/48753/8 "2019-05-28T21:42:33Z")

</div>

Hi, everyone,

Thank you very much for your replies.

Just to test if can convert between different types of data, I did the following:

1. Created an instance of the LabParam with Value as Variant
2. Created an instance called Potassium
3. Created a Label as an output for the Potassium value
4. Created a slider to change the value of the Potassium, and put the following code into the ValueChanged method

```auto

Potassium.Value=me.Value/1000000
Label2.Text=str(val(Potassium.Value))

```

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

```auto
Potassium.Value=me.Value/1000000
Label2.Text=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.

Val

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [May 28, 2019, 9:50pm UTC](https://forum.xojo.com/t/custom-class/48753/9 "2019-05-28T21:50:14Z")

</div>

> [@438814:@Val Kozmenko](#):
>
> Instead, it produced a number with 10 with some power. That was still a valid result but not convenient for human reading.

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

```auto
label2.text=format(val(potassium.value),"##,###.##")
```

---

<div class="post-metadata">

**Author:** ![Val\_Kozmenko](https://forum.xojo.com/letter_avatar_proxy/v4/letter/v/85f322/32.png) [@Val\_Kozmenko](https://forum.xojo.com/u/Val_Kozmenko)\
**Post date:** [May 28, 2019, 10:13pm UTC](https://forum.xojo.com/t/custom-class/48753/10 "2019-05-28T22:13:39Z")

</div>

Thank you, Dave.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [April 29, 2021, 3:57pm UTC](https://forum.xojo.com/t/custom-class/48753/11 "2021-04-29T15:57:30Z")

</div>


