Question best practice: creating 100 labels or ...?

mmy

Member
Joined
Oct 5, 2007
Messages
24
Programming Experience
1-3
Hi,

I'm developping a project to receive and display properties with values from a PBX (how many calls in progress, ...)

Each property has its own propertyID (fixed), title (random) and value (random).
Example:
- propertyID = "9", title = "number of calls", value = 5
- propertyID = "15", title= "calls waiting", value = 3

Assume there can be 100 different properties. Depending on the user's preferences, some properties are hidden. At regular intervals, I will receive new values for the properties (so the value displayed will change).

All the properties that should be monitored are stored in an array (onLoad event)

At this moment I'm working like this:

1) I have 100 labels on my form, called lblInfo + the propertyID (-> lblInfo1, lblInfo2, ...). The visisble property = false for every label.

2) OnLoad: cycle through the array of desired properties and do a select case
-> case propertyID = 1 -> lblInfo1.visible = true and lblInfo1.text = ....
-> case propertyID = 2 -> lblINfo2.visible = true and lblInfo2.text = ...
-> ...

Using the label.location property I can align all the labels (so the vertical spacing is equal between every label).

3) when I receive new values for the properties, I do the same (a select case)
-> case new value received for propertyID = 1 -> lblInfo1.text = new received value
-> case new value received for propertyID = 2 -> lblInfo2.text = ...
-> ...

I'm sure I can do this in a more simple way, however I don't know how.
I tried configuring a label programatically

onLoad for every wanted property in my array:
-> dim lblInfo as Label = new Label
-> lblInfo.text = ...
-> me.controls.add(lblInfo)


But how can I change the text in the labels when I receive new values (in a different sub then the OnLoad)
I can't do: lblInfo & receivedID .text = ...


Maybe someone has a better idea? I can continue to work with all the labels, but if I want to monitor a 2nd PBX I should create all the labels again.

update: forgot to mention - when I receive new values from the PBX, I only receive the propertyIDs with value for the properties that have new values. So I can't generate all the labels again with their values (if I used dim lblInfo as Label / lblInfo.text = ...) The properties with the values that haven't changed should remain on the screen with their old text
 
Last edited:
edit: think I got a better solution...
1) global variable: dim lblInfo(100) as Label
2) on the Onload
-> lblPrefix(propertyID).Text = ....
-> lblPrefix(propertyID).Location = ...
-> me.controls.add(lblPrefix(propertyID))

3) when I receive new values
-> lblPrefix(propertyID).Text = new value

Correct me if I'm wrong...
 
Back
Top