-
Is there a more efficient way to write this code:
If num >= 2000 And num <= 2035 Then
lblResponse.Caption = "correct"
Call correct
Else
If num >= 2100 And num <= 2135 Then
lblResponse.Caption = "correct"
Call correct
Else
If num >= 2200 And num <= 2235 Then
lblResponse.Caption = "correct"
Call correct
Else
.....and the code goes on and on (for a couple pages)with numbers ending always with
##00 and ##35.
TIA
-
How about a loop?
Code:
For i = 2000 to 6000 Step 100
If num >= i And num <= (i+35) Then
lblResponse.Caption = "correct"
Correct
End If
Next i
It may not be more efficient, but it looks quite nice :)
-
<?>
Code:
If Right(num, 2) >= 0 And Right(num, 2) <= 35 Then
lblResponse.Caption = "correct"
Call correct
End If
[Edited by HeSaidJoe on 10-04-2000 at 05:42 PM]
-
Try this:
n = 2000
do while n <= 5000 'or however far you need to go
If num >= n And num <= (n + 35) Then
lblResponse.Caption = "correct"
Call correct
end if
n = n + 100
loop
-
Try this:
Code:
If (num Mod 1000 >= 0) And (num Mod 1000 <= 35) Then
lblResponse.Caption = "correct"
Call correct
End If
I think it's the most efficient way...
HeSaidJoe: Aren't you using Evil Type Conversion ? ;)
Parksie: I don't think you understood the question? ;)
Enjoy...
-
My code does exactly the same as the rest...so what do you think the question was?
Although ntropee is now spoilt for choice with about 3 different methods ;)
-
<?>
Say what?
HeSaidJoe: Aren't you using Evil Type Conversion ?
If you are looking for a number between 0 and 35 as the
2 right digits of any number why wouldn't it work?
Anytime num is passed it checks the last 2 digits and if
they fall within 0 to 35 then correction is called.
-
I think he means that you're converting from number to string to number, rather than comparing numbers.
RobIII - Instruction-wise, + is faster than Mod, since less CPU instructions are needed (1 as opposed to about 4). Also, the compiler can optimise "through-the-loop".
-
<?>
that's all...who cares..it works and it's less than oodles and ooldles of pages.
:D
-
Yeah. In these times of 1GHz processors, I think smaller, more readable code is more important than sheer speed. Anyway, there won't be much in it with so few runs through the loop (you'd need to take thousands before there was much difference).
-
thanks
Thanks for the response..... i cut down my code from 3 pages to just a couple lines.
I love this forum : )