Author Topic: 2 commands atached to a button, but getting 2-3 inputs on every button press  (Read 943 times)

Madmax

  • Newbie
  • *
  • Posts: 4
    • View Profile
I think ive seen this question asked before here but cant seem to find it now..so

I have 2 alternate commands attached to a single button, so when pressed once it activates one command then when pressed again the button activates the second command etc. etc. 

But on each press im getting both commands (or more)  executed each time,

Code im using:

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
FirstOperation()
SecondOperation()
End Sub

Private Sub FirstOperation()
"my code for command one here"
End Sub

Private Sub SecondOperation()
"my code for command 2here"
End Sub

I would like one click activates 1command then another click activates the second command, then back to command one on the next click.... Basicly im sending a "turn on command then a turn off command" on each button press.

But im getting multiple inputs or command activation's on each button press... Something to do with the rate/speed the code is run, the button the seen as pressed on multiple passes of the code... I think i need some type of "read once then ignore until next press" type of adjustment..

sure there must be a reasonably easy solution..

Cheers
Matt

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Are you trying to toggle a bit on the PLC?

Phrog30

  • Guest
Each time you press the button the click event is calling both subs, so that's your problem.  You only need code in the click event, something like:

Code: [Select]

            If Not Memory Then
                'Do 1st thing
            Else
                'Do 2nd thing
            End If
       
            Memory = Not Memory


You can declare the variable Memory about the click event.  You can call this stuff whatever you want.

Madmax

  • Newbie
  • *
  • Posts: 4
    • View Profile
Are you trying to toggle a bit on the PLC?

Im sending a http command to a home automation controller (a zwave controller) that is on the same home network as advancedhmi,

Sample command:
http://192.168.1.104:3480/data_request?id=lu_action&output_format=json&DeviceNum=18&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1

The end target value turns on or off particular switches etc...

I have a button on the hmi to turn on and off the same light etc..  One click to turn on, then one click on the same button to turn off

Matt