Author Topic: How to make value always update  (Read 824 times)

Padex

  • Newbie
  • *
  • Posts: 11
    • View Profile
How to make value always update
« on: January 17, 2017, 01:22:59 AM »
Hi All,

I need your help to looking on my vb. Currently Im trying to calculate integer data from PLC and used vb to publish the result by button control.
But when I push the button only show the current value. How to make it button to always counting when the button push.

  Private Sub BasicButton1_Click(sender As Object, e As EventArgs) Handles BasicButton1.Click, BasicLabel298.Click
        Dim MyValue1 As Integer
        MyValue1 = BSA1.Read("Counter_Built_Out.acc")
        Dim MyValue2 As Integer
        MyValue2 = BSA2.Read("Counter_Built_Out.acc")
        Dim Built_plan As Integer = TextBox1.Text
        Dim Balance_built As Integer
        Balance_built = Built_plan - (MyValue1 + MyValue2)
        BasicLabel298.Text = Balance_built
    End Sub


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Re: How to make value always update
« Reply #1 on: January 17, 2017, 05:23:06 AM »
This will be one way to do it:

- Add a BasicLabel to the form
- In the Properties window, change the Name property to Built1Label
- Set ComComponent property to BSA1
- Set PLCAddressValue to Counter_Built_Out.acc

- Add another BasicLabel
- Change Name property to Built2Label
- Set ComComponent property to BSA2
- Set PLCAddressValue to Counter_Built_Out.acc

- From the All Windows group in the Toolbox, add a Label
- In the properties Window, change the Name to ResultLabel
- Right click on your form and select View Code
- Add this code:
Code: [Select]
    Private Sub BasicLabel1_ValueChanged(sender As Object, e As EventArgs) Handles Built1Label.ValueChanged, Built2Label.ValueChanged
        Try
            ResultLabel.Text = CInt(TextBox1.Text) - (CInt(Built1Label.Text) + CInt(Built2Label.Text))
        Catch ex As Exception
        End Try
    End Sub

Padex

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: How to make value always update
« Reply #2 on: January 17, 2017, 07:19:21 PM »
Hi Archie,

The code is function well... thanks so much with your great answer and support....