-
Jan 27th, 2023, 01:01 AM
#1
Thread Starter
New Member
Click event of button not working continually
Hello there,
I am trying to do as below.
On the click event of Button, if the button is already zero it will be 1 and will pass the string of 1.
Now if I press the button again it will be zero and pass the string of 0.
I have written as below but it's not working accurately and continually.
Please help me with this.
Try
If TextBox5.Text = "Stop" Then
TextBox5.Text = "Start"
Frm_MDI.Timer_drum.Stop()
If (Frm_MDI.SerialPort1.IsOpen) Then
Frm_MDI.SerialPort1.Close()
End If
':0110-00ED-0001-02-xxxx-xx-<CR><LF>
SerialPort1.Open()
SerialPort1.Write(":011000EC00010200013E" & vbCrLf)
SerialPort1.Close()
TextBox5.Text = "Start"
Frm_MDI.Timer_drum.Start()
ElseIf TextBox5.Text = "Start" Then
TextBox5.Text = "Stop"
Frm_MDI.Timer_drum.Stop()
If (Frm_MDI.SerialPort1.IsOpen) Then
Frm_MDI.SerialPort1.Close()
End If
SerialPort1.Open()
SerialPort1.Write(":011000EC00010200003F" & vbCrLf)
SerialPort1.Close()
TextBox5.Text = "Stop"
Frm_MDI.Timer_drum.Start()
End If
Catch ex As Exception
MsgBox(ex.ToString, vbInformation, "DMSCADA_SPV315A")
End Try
-
Jan 27th, 2023, 01:04 AM
#2
Re: Click event of button not working continually
Please don't post unformatted code snippets. They are too hard to read, most notably because indenting is lost. Format your code properly, for readability.
-
Jan 27th, 2023, 01:08 AM
#3
Re: Click event of button not working continually
Here's your code formatted properly:
Code:
Try
If TextBox5.Text = "Stop" Then
TextBox5.Text = "Start"
Frm_MDI.Timer_drum.Stop()
If (Frm_MDI.SerialPort1.IsOpen) Then
Frm_MDI.SerialPort1.Close()
End If
':0110-00ED-0001-02-xxxx-xx-<CR><LF>
SerialPort1.Open()
SerialPort1.Write(":011000EC00010200013E" & vbCrLf)
SerialPort1.Close()
TextBox5.Text = "Start"
Frm_MDI.Timer_drum.Start()
ElseIf TextBox5.Text = "Start" Then
TextBox5.Text = "Stop"
Frm_MDI.Timer_drum.Stop()
If (Frm_MDI.SerialPort1.IsOpen) Then
Frm_MDI.SerialPort1.Close()
End If
SerialPort1.Open()
SerialPort1.Write(":011000EC00010200003F" & vbCrLf)
SerialPort1.Close()
TextBox5.Text = "Stop"
Frm_MDI.Timer_drum.Start()
End If
Catch ex As Exception
MsgBox(ex.ToString, vbInformation, "DMSCADA_SPV315A")
End Try
-
Jan 27th, 2023, 01:10 AM
#4
Re: Click event of button not working continually
Originally Posted by Riya_vb
On the click event of Button, if the button is already zero it will be 1 and will pass the string of 1.
Now if I press the button again it will be zero and pass the string of 0.
Buttons are not numbers so they can't be 0 or 1 and I see nothing in that code that relates to any Button at all. Please provide a FULL and CLEAR explanation of the problem and provide ALL and ONLY the relevant information.
-
Jan 27th, 2023, 01:14 AM
#5
Re: Click event of button not working continually
If you want to do two different things alternately on the Click of a Button then it is generally better to use a CheckBox instead. You can set the Appearance to Button and then the control looks exactly like a Button. When you click it, instead of depressing and releasing each time, as a Button does, the control will stay depressed on the first click and release on the second. You can then handle the CheckedChanged event and act based on the Checked property.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|