|
-
May 3rd, 2008, 03:59 AM
#1
Thread Starter
Lively Member
[RESOLVED] [2005] Odd If statement problem --> code triggered when 'Or' is placed in
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.
Last edited by squrrilslayer; May 3rd, 2008 at 04:29 AM.
-
May 3rd, 2008, 04:08 AM
#2
Re: [2005] Odd If statement problem --> code triggered when 'Or' is placed in
This is incorrect syntax:
vb.net Code:
If AI1.Left = Left Or Left2 Or Left3 Or Left4 Then
It should be:
vb.net Code:
If AI1.Left = Left OrElse AI1.Left = Left2 OrElse AI1.Left = Left3 OrElse AI1.Left = Left4 Then
Apart from that, a Timer with an Interval of 1 millisecond is completely unacceptable. How long do you think it would take to execute the code inside the Tick event handler?
-
May 3rd, 2008, 04:28 AM
#3
Thread Starter
Lively Member
Re: [2005] Odd If statement problem --> code triggered when 'Or' is placed in
i have no idea how long that would take to tick through a timer!
and thanks. OrElse, not Or!
-
May 3rd, 2008, 04:37 AM
#4
Re: [RESOLVED] [2005] Odd If statement problem --> code triggered when 'Or' is placed in
There are 1000 milliseconds in 1 second. You're displaying text in four Lables and creating a PictureBox in that event handler. Do you expect to be able to do that 1000 times per second, plus whatever else your app has to do?
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
|