Hello guys,
I am currently working on a bot for Guitar Hero by using an Arduino Uno. However, I have a small problem with the Visual Studio code. I am getting the following error and don't know how to solve it:
Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
And here is the entire Visual Studio code:
Public Class Form1
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Start()
Timer2.Start()
Timer3.Start()
Timer4.Start()
Timer5.Start()
End SubPrivate Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim BMP As New Drawing.Bitmap(1, 1)
Dim GFX As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(BMP)
GFX.CopyFromScreen(New Drawing.Point(698, 839), _
New Drawing.Point(0, 0), BMP.Size)
Dim Pixel As Drawing.Color = BMP.GetPixel(0, 0)
CPpanel.BackColor = Pixel
Redtxt.Text = Pixel.R
Greentxt.Text = Pixel.G
Bluetxt.Text = Pixel.B
TextBox1.Text = Pixel.R & Pixel.G & Pixel.B
If Greentxt.Text > 100 Then
TextBox2.Text = "ja"
Else
TextBox2.Text = "nee"
End If
End SubPrivate Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Dim BMP2 As New Drawing.Bitmap(1, 1)
Dim GFX2 As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(BMP2)
GFX2.CopyFromScreen(New Drawing.Point(824, 839), _
New Drawing.Point(0, 0), BMP2.Size)
Dim Pixel2 As Drawing.Color = BMP2.GetPixel(0, 0)
CPpanel2.BackColor = Pixel2
Redtxt2.Text = Pixel2.R
Greentxt2.Text = Pixel2.G
Bluetxt2.Text = Pixel2.B
TextBox6.Text = Pixel2.R & Pixel2.G & Pixel2.B
If Redtxt2.Text > 100 Then
TextBox5.Text = "ja"
Else
TextBox5.Text = "nee"
End If
End SubPrivate Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
Dim BMP3 As New Drawing.Bitmap(1, 1)
Dim GFX3 As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(BMP3)
GFX3.CopyFromScreen(New Drawing.Point(954, 839), _
New Drawing.Point(0, 0), BMP3.Size)
Dim Pixel3 As Drawing.Color = BMP3.GetPixel(0, 0)
CPpanel3.BackColor = Pixel3
Redtxt3.Text = Pixel3.R
Greentxt3.Text = Pixel3.G
Bluetxt3.Text = Pixel3.B
TextBox11.Text = Pixel3.R & Pixel3.G & Pixel3.B
If (Redtxt3.Text > 100 And Greentxt3.Text > 100) And Bluetxt3.Text < 100 Then
TextBox10.Text = "ja"
Else
TextBox10.Text = "nee"
End If
End SubPrivate Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
Dim BMP4 As New Drawing.Bitmap(1, 1)
Dim GFX4 As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(BMP4)
GFX4.CopyFromScreen(New Drawing.Point(1079, 839), _
New Drawing.Point(0, 0), BMP4.Size)
Dim Pixel4 As Drawing.Color = BMP4.GetPixel(0, 0)
CPpanel4.BackColor = Pixel4
Redtxt4.Text = Pixel4.R
Greentxt4.Text = Pixel4.G
Bluetxt4.Text = Pixel4.B
TextBox16.Text = Pixel4.R & Pixel4.G & Pixel4.B
If (Bluetxt4.Text > 100 And Redtxt4.Text < 180) Or ((Bluetxt4.Text > 200 And Redtxt4.Text > 200) And Greentxt4.Text > 200) Then
TextBox15.Text = "ja"
Else
TextBox15.Text = "nee"
End If
End SubPrivate Sub Timer5_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer5.Tick
Dim BMP5 As New Drawing.Bitmap(1, 1)
Dim GFX5 As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(BMP5)
GFX5.CopyFromScreen(New Drawing.Point(1203, 839), _
New Drawing.Point(0, 0), BMP5.Size)
Dim Pixel5 As Drawing.Color = BMP5.GetPixel(0, 0)
CPpanel5.BackColor = Pixel5
Redtxt5.Text = Pixel5.R
Greentxt5.Text = Pixel5.G
Bluetxt5.Text = Pixel5.B
TextBox21.Text = Pixel5.R & Pixel5.G & Pixel5.B
If Redtxt5.Text > 150 And Greentxt5.Text > 150 Then
TextBox20.Text = "ja"
Else
TextBox20.Text = "nee"
End IfTextBox3.Text = MousePosition.X : TextBox4.Text = MousePosition.Y
End SubPrivate Sub btnOpenCOMPort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenCOMPort.Click
If TextBox2.Text = "ja" Then
If SerialPort1.IsOpen Then
SerialPort1.Close()
End If
SerialPort1.PortName = "COM4"
SerialPort1.Open()
SerialPort1.Write("?")
Else
If SerialPort1.IsOpen Then
SerialPort1.DtrEnable = True
SerialPort1.DtrEnable = False
SerialPort1.Close()
End If
End If
End SubPrivate Sub ArduinoSend_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles ArduinoSend.DoWork
Dim data As Byte = 0If Not (e.Argument.ToString = "") Then
If e.Argument.ToString.Contains("G") Then
data = data + &H40
End If
If e.Argument.ToString.Contains("R") Then
data = data + &H20
End If
If e.Argument.ToString.Contains("Y") Then
data = data + &H10
End If
If e.Argument.ToString.Contains("B") Then
data = data + &H8
End If
If e.Argument.ToString.Contains("O") Then
data = data + &H4
End If
data = data + &H2
End If
If SerialPort1.IsOpen Then
SerialPort1.Write(ChrW(data))
End If
End SubPrivate Sub TextBox2_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox2.TextChanged
If TextBox2.Text = "ja" Then btnOpenCOMPort.PerformClick()
End SubEnd Class