Hi,
WE HAVE A WINNER !
D Jungk won on this using neither Select Case nor If Then Else, but Floor !
[Later comment: read far below, there's no need for Floor either!]
Here is the If Then Else block I used:
If Between(Y,0,100) Then
startY = 0
endY = 100
ElseIf Between(Y,100,200) Then
startY = 100
endY = 200
ElseIf Between(Y,190,300) Then
startY = 200
endY = 300
ElseIf Between(Y,290,400) Then
startY = 300
endY = 400
ElseIf Between(Y,400,500) Then
startY = 400
endY = 500
End If
Here’s the Between Function (I could name it isBetween instead!):
Function Between(Y As Integer, StartVal As Integer, EndVal As Integer) As
Boolean
//
// Function: Between
// Inputs: Y As Integer, StartVal As Integer, EndVal As Integer
// Outputs: Boolean
// Syntax: Boolean = Between(Y,StartVal,EndVal)
// Creator: Emile Schwarz
// Created: August 21, 2006
//
Dim Inside As Boolean
// Is Y inside the passed values ?
If Y > StartVal And Y < EndVal Then
Inside = True
Else
Inside = False
End If
// Return the result
Return Inside
End Function
and at last here is D Junk code to replace all of the above...:
startY = floor(Y / 100) * 100
endY = startY + 100
It works fine!
Thanks D Junk!
BTW: I can even remove the line that feeds endY (the second line); after
checking my code some minutes ago, I realized that I do not used the endY
variable because all I needed was 100 (pixels tall; the area height is 100
pixels; endY = 100, always).
A little more testings reveals that I do not need to do a floating point divide
(/), an integer divide is enough (\) and more, the use of the Floor Statement is
useless in this condition, so the used code is now:
startY = (Y \ 100) * 100 // startY is not the best var name; I could use baseY
since it is the base (top base) of the Row
One more bunch of thanks people,
Emile
PS: "how can I do what the example code below suggest I want to do!"
What I wanted to do is to highlight a 100 pixel tall, full window width, section
of the window where the user clicks to make a user feedback (the user know what
unique "Row" is selected) on a 5 rows basis (the window height is 500 pixels)
--
“The light comes from constructive discussions.”
--------- --------- --------- --------- --------- --------- --------- ---------
-- D Junk original answer (with my question-:
Subject: Re: My troubles with Select Case
From: D Jungk <a class="moz-txt-link-rfc2396E"
href="mailto:[EMAIL PROTECTED]"><[EMAIL PROTECTED]></a>
Date: Tue, 22 Aug 2006 17:05:29 -0500
On Tuesday 22 August 2006 10:20 am, Emile Schwarz wrote:
</pre><blockquote type=cite><pre wrap>Hi,
REALbasic 2006 Release 3
Mac OS X 10.4.7
The question is: how can I do what the example code below suggest I want
to do!
[In Window.MouseDown] I wanted to use Select Case, tried some solutions
and fall into:
Select Case Y
Case Is < 100 // Was: Y < 100 // Row #1
startY = 0
endY = 100
Case Between(Y,100,200) // Was: Is > 100 And Is < 200 // Row #2
startY = 100
endY = 200
Case Between(Y,200,300) // Was: Is > 100 And Is < 200 // Row #3
startY = 200
endY = 300
Case Between(Y,300,400) // Was: Is > 100 And Is < 200 // Row #4
startY = 300
endY = 400
Case Between(Y,400,500) // Was: Is > 100 And Is < 200 // Row #5
startY = 400
endY = 500
End Select
But this does not works:
Type mismatch error. Expected Int32, but got Boolean.
Select Case Select Case Y
</pre></blockquote><pre wrap><!---->Hi Emile,
I know you're asking about Select Case, but do you have to use it? Could you
use something like:
startY=floor(Y/100)*100
endY=startY+100
DJ
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>