Select ...Case or some other way?

Sorry if I'm asking too many questions :) but I'm hardly able to solve the following:

I want a Sub to check coordinates of a Rectangle
Like :
Select Rectangle.Y
Case Rectangle.Y < 150 ' Doesn't work
... do something
Case Rectangle.Y < 135
..... do something
.................................
End Select

Or should I just go:
If Rectangle.Y < 150 Then
.......do something
End If
If Rectangle.Y < 135 Then
.......do something
End If
........... and so on

Any suggestions?:sign0085:
 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
It is a more clean aproach to use the case select statements, but both are doable.
BUT, I think case select can only be used to check for equals, and not for relative values, like "bigger than" or "smaller than" values.

In the case statements, you would have

B4X:
Select value
            Case Value1
                        ...
            Case Value2,Value3,Value4 (True if one of the values matches)
                        ...
            Case Else
                        ...
End Select

wich in you case would translate as..

B4X:
Select Rectangle.Y
Case < 150 ' Doesn't work
... do something
Case < 135
..... do something
.................................
End Select
/Code]

You are already telling the case sttement to select the Rectangle.Y value, so

Case Rectangle.Y < 135

Means nothing to the case statement.

I have NOT tested any of this, so I can only tell you what I know for sure...
Both are capable of doing comparison selections and act upon matches BUT, I think that only the If loop can checg for "bigger or smaller than" values .
 
Converted from the help file.


Code:
Select Rectangle.Y
Case < 150
do something
Case < 135
do something
End Select

I wouldn't have posted without having tested it :)
Thank you anyway


I think case select can only be used to check for equals, and not for relative values, like "bigger than" or "smaller than" values.

You are probably right Paulo

I'm rewriting a good old game.When it's finished i'll post it
:)
 
Rectangle.Dispose

I'm rewriting a good old game.When it's finished i'll post it

I wish I were able to finish it ...

Sub CheckIfIntersects
For n = 91 To 100 ' The first row of bricks.
If RectBall.IntersectsWith(Rectangle("RectBrick" & n).Value = True Then
' if the ball hits the brick
Drawer.FillRectangle(EraseBrush.Value,Rectangle("RectBrick" & n).Value)
Drawer.Refresh2(Rectangle("RectBrick" & n).Value
' erase the brick hit by the ball
Speed.Y = - Speed.Y ' bounce - change the ball's direction
' RectBrick5.Dispose - Null Reference Exception :confused:
End If
Next
End Sub

The bricks hit by the ball are erased but the ball bounces off the erased bricks
:sign0163:
What can be done about it?
:BangHead:

I can uplode my "project" if somebody cares.
Thank you.
 
Top