Hi, guys,
I need to learn how to create a custom class and I do not know where to start.
I am re-designing my old software that displays lab work results for a simulated patient. I need to create a custom class that I can call “LabParameter.”
The LabParameter would have the following properties:
LabParameter.Name
LabParameter.Value
LabParameter.Range
LabParameter.Units
It will be a super class to all the lab work parameters, for example
Hemoglobin.Name=“Hb”
Hemoglobin.Value=12
Hemoglobin.Range=“12 - 15”
Hemoglobin.Units=“g/dL”
Then in the application I would be able to refer to those Hemoglobin properties when I populate reports into the ListBoxes.
Any guidance to the right direction is very appreciated.
Thank you in advance,
Val
Is this a lab result? Result from a measure?
HI, Rick,
Each LabParameter is just an abstract entity without any GUI. It will not be measured. My app is a simulation.
So, it is an input value. Does any other “parameter” carrying extra values beyond Name, Value, Range and Units?
I want to be able to do something like this
Label1.Text=Hemoglobin.Name
Label2.Text=str(Hemoglobin.Value)
Label3.Text=Hemoglobin.Range
Label4.Text=Hemoglobin.Units
Yes, this is an input value. No other properties besides Name, Value, Range, and Units
Just one class solves this.
From what I understand based on your initial post, Hemoglobin would be an instance of your LabParameter class. So you would add a new class, name it LabParameter, then add the four properties to it and set their types (looks like they are all strings except the value in the example you wrote). Then you would write:
dim Hemoglobin as new LabParameter
Hemoglobin.Name=“Hb”
Hemoglobin.Value=12
Hemoglobin.Range=“12 - 15”
Hemoglobin.Units=“g/dL”
to set the properties for that instance.
Are you having trouble figuring out where to add the class and its properties in the IDE?
I guess I see what you mean.
Let’s say that the class is LabParameter then the code could be
Dim Hemoglobin as new LabParameter
Hemoglobin.Name=Hemoglobin
Hemoglobin.Value=13.5
Hemoglobin.Range="13 - 16"
Hemoglobin.Units="g/dL"
Similarly, I can create multiple other instances of the LabParameter that would represent the other lab results such as hematocrit, sodium, potassium etc.
Still, how do I create the LabParameter class with those four properties
Name (as string)
Value (as String)
Range (as String)
Units (as String)
[code]Class LabParam
Name As String
Range As String
Units As String
Value As Double
End Class
Dim hemoglobin As New LabParam
hemoglobin.Name=“Hb”
hem…
[/code]
Do I create this class in the “Open” event of the App?
Hi, Rick,
Thank you for your help. I very appreciate it.
Val
Nope. You must create it in the objects navigator of the IDE. It does not look like this code.
Insert menu -> Class to create the class, then set the name to LabParameter.
Then right click on LabParameter to get a contextual menu, Add to “LabParameter” -> Property, set property name and type. Do this for each property. Then you can reference your class in code as mentioned above.
Hi, guys,
I just have placed a sample project into the dropbox. Can you take a look?
It looks like it is working
When I try to put those values into the ListBox, I have the following error
Window1.Listbox1.Open, line 10
There is more than one item with this name and it’s not clear to which this refers.
ListBox1.AddRow(Hemoglobin.Name)
I moved the code from the Open event in the ListBox to the Open event in the Window.
Now it works.