I have this code where i testing weather a picturbox's X value is the same as or similar (within about 3 pixels) as another picturbox's X value. The code is below:
vb Code:
Private Sub AI_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AI.Tick Dim Left, Right, Left2, Right2, Left3, Right3, Left4, Right4 As Integer Dim Up, Down, Up2, Down2, Up3, Down3, Up4, Down4 Left = P1CoOrds.X Left2 = P1CoOrds.X - 1 Left3 = P1CoOrds.X - 2 Left4 = P1CoOrds.X - 3 Right = P1CoOrds.X Right2 = P1CoOrds.X + 1 Right3 = P1CoOrds.X + 2 Right4 = P1CoOrds.X + 3 lbl1.Text = Pic1.Location.X lbl2.Text = Pic1.Location.Y lbl3.Text = AI1.Location.X lbl4.Text = AI1.Location.Y If AI1.Left = Left Or Left2 Or Left3 Or Left4 Then CreatePicBox(50, 20, AI1.Location, Color.Blue) 'This is only here to see if the code is being triggered. End If End Sub Private Sub CreatePicBox(ByVal Height As Integer, ByVal Width As Integer, ByVal Pos As Point, ByVal Colour As Color) PicBox = New PictureBox PicBox.Height = Height PicBox.Width = Width PicBox.Location = Pos PicBox.BackColor = Colour Controls.Add(PicBox) PicBoxNo += 1 lbl5.Text = PicBoxNo End Sub
the first block of code is in a timer running at 1 millisecond. Later on I'll probably reduce that. Anyway, with the "Left or Left2 or Left3 or Left4" it is triggering the code where ever the picturebox is. The x values are completely different and the code is still being triggered.
It works however if i house all the "Lefts" in their own If Then statements. Same goes with all the "Rights", "Ups" and "Downs".
Could someone provide insight into this rather annoying problem?
thanks.




Reply With Quote