Author Topic: Basic Labels  (Read 4024 times)

StefanA

  • Newbie
  • *
  • Posts: 33
    • View Profile
Basic Labels
« on: December 27, 2013, 06:13:14 AM »
In the Basic Label user manual the is a piece about event and manipulation. One
example is how to change the colour of the labels based on value.

I have a bunch of Basic Labels which I would like to change the background colour on according
to a counter register. When the counter is  ≥  1 Basic Label one turn green when the counter
shows 2 Label two change colour and so on.

I tried to use the example in the manual but I think the code must be changed for this use and
I need help with that.

//Stefan

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Basic Labels
« Reply #1 on: December 27, 2013, 07:54:26 AM »
Are you using a BasicLabel to display the counter value also?

StefanA

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: Basic Labels
« Reply #2 on: December 27, 2013, 12:45:04 PM »
I had not planned to do that but if its makes things easier that's no problem.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Basic Labels
« Reply #3 on: December 27, 2013, 01:49:02 PM »
It only means the difference of using a DataSubscriber versus a BasicLabel. Try this:

1) Add a DataSubscriber to your form
2) Set the PLCAddressValue to the address with the counter
3) Double click the DataSubscriber to get back to the code and add this code:

Code: [Select]
If DataSubscriber1.Value>=1 then
   BasicLabel1.BackColor=Colors.Green
else
  BasicLabel1.BackColor=Colors.Black
end if

If DataSubscriber1.Value>=2 then
  BasicLabel2.BackColor=Colors.Green
else
  BasicLabel2.BackColor=Colors.Black
end if

StefanA

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: Basic Labels
« Reply #4 on: December 28, 2013, 09:10:59 AM »
Where can I find the DataSubscriber component? Can't get my eyes on it in the toolbox.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Basic Labels
« Reply #5 on: December 28, 2013, 09:24:43 AM »
Are you using version 3.59 or later?

StefanA

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: Basic Labels
« Reply #6 on: December 28, 2013, 11:32:36 AM »
3.40

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Basic Labels
« Reply #7 on: December 28, 2013, 09:12:22 PM »
That version doesn't have the DataSubscriber, so you will have to add a BasicLabel to the form that reads the counter value. You can then add the TextChanged event handler to that BasicLabel. If you don't want it to display, you can set the Foreground color to same thing as the form background color to make it invisible.

In the TextChanged event handler, use the code from above

StefanA

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: Basic Labels
« Reply #8 on: December 29, 2013, 09:39:31 AM »
I decided it was time to upgrade to the latest version and the Data Subscriber solution seems to work fine, thanks.

You have made a demo screen called Chemical Mixer Adder. Above the tanks the are two low level indicator lights. Which component is that? They look like the Pilotlight but the Pilotlight I found in the toolbox are clickable and I only want a indicator light in the same style.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Basic Labels
« Reply #9 on: December 29, 2013, 06:52:24 PM »
They were PilotLights. As long as you leave PLCAddressClick blank and only use PLCAddressValue, clicking them will do nothing.

StefanA

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: Basic Labels
« Reply #10 on: December 30, 2013, 11:17:49 AM »
Ok, thought it was a different component. I attach a screenshot with a message that have been popping up. Can it have something to do with the DataSubscriber I added?

StefanA

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: Basic Labels
« Reply #11 on: January 07, 2014, 11:48:47 AM »
Why do I get these error messages, have I done something wrong when adding a DataSubscriber?

When you click on a pilot light which is lit, the light goes out for a short while even if no click address are specified. Is is possible to get rid of that?

baguinn

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Basic Labels
« Reply #12 on: January 07, 2014, 03:29:12 PM »
The DataSubScriber is reading the address as a string.  You must convert the DataSubScriber.Value from a string to a value before being able to use it as a number

dim DataValue as integer

DataValue=Val(DataSubScriber.Value)

then just put DataValue in place of the DataSubScriber.Value in the code.

StefanA

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: Basic Labels
« Reply #13 on: January 08, 2014, 01:22:14 PM »
Ok, so the code should look like this?



Private Sub DataSubscriber1_DataChanged(ByVal sender As System.Object, ByVal e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs) Handles DataSubscriber1.DataChanged

        Dim DataValue As Integer
        DataValue = Val(DataSubscriber1.Value)


        If DataValue >= 1 Then
            BasicLabel1.BackColor = Color.Green
        Else
            BasicLabel1.BackColor = Color.Silver
        End If

        If DataValue >= 2 Then
            BasicLabel4.BackColor = Color.Green
        Else
            BasicLabel4.BackColor = Color.Silver
        End If
       
        End Sub