|
-
Oct 4th, 2000, 04:07 PM
#1
Thread Starter
New Member
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
-
Oct 4th, 2000, 04:15 PM
#2
Monday Morning Lunatic
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
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 4th, 2000, 04:15 PM
#3
_______
<?>
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]
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Oct 4th, 2000, 04:16 PM
#4
Hyperactive Member
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
-
Oct 4th, 2000, 04:19 PM
#5
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...
-
Oct 4th, 2000, 04:23 PM
#6
Monday Morning Lunatic
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
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 4th, 2000, 04:24 PM
#7
_______
<?>
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.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Oct 4th, 2000, 04:33 PM
#8
Monday Morning Lunatic
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".
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 4th, 2000, 04:45 PM
#9
_______
<?>
that's all...who cares..it works and it's less than oodles and ooldles of pages.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Oct 4th, 2000, 04:47 PM
#10
Monday Morning Lunatic
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).
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 9th, 2000, 03:43 PM
#11
Thread Starter
New Member
thanks
Thanks for the response..... i cut down my code from 3 pages to just a couple lines.
I love this forum : )
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
|