Author Topic: msgbox for button  (Read 1089 times)

Darrell

  • Full Member
  • ***
  • Posts: 198
  • Electrician / PLC Technician
    • View Profile
msgbox for button
« on: August 31, 2015, 08:12:56 AM »
I used this code that i found on this forum and I maybe missing something.
when i click a button to toggle a bit the message pops up with a yes or no question but the bit still toggles before I answer.


If MsgBox("Are you sure?", Microsoft.VisualBasic.MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
            EthernetIPforPLCSLCMicroCom1.Write("B3/100", "1")
        End If

Darrell

Cowboy1

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: msgbox for button
« Reply #1 on: August 31, 2015, 11:59:44 AM »
I used this code that i found on this forum and I maybe missing something.
when i click a button to toggle a bit the message pops up with a yes or no question but the bit still toggles before I answer.


If MsgBox("Are you sure?", Microsoft.VisualBasic.MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
            EthernetIPforPLCSLCMicroCom1.Write("B3/100", "1")
        End If

Darrell

Darrell,

I think this may work:

 If   
    MsgBox("Are you sure?", Microsoft.VisualBasic.MsgBoxStyle.YesNo)
EndIf

      If
        MsgBoxResult.Yes Then
            EthernetIPforPLCSLCMicroCom1.Write("B3/100", "1")
     End If

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: msgbox for button
« Reply #2 on: August 31, 2015, 03:11:56 PM »
I couldn't have that code work but this one did work:

Code: [Select]
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim result As MsgBoxResult = MsgBox("Are you sure?", Microsoft.VisualBasic.MsgBoxStyle.YesNo)
        If result = MsgBoxResult.Yes Then
            EthernetIPforPLCSLCMicroCom1.Write("B3/100", "1")
        End If
    End Sub