|
-
Jul 23rd, 2003, 12:27 PM
#1
Thread Starter
Hyperactive Member
Last edited by adzzzz; Jul 23rd, 2003 at 12:40 PM.
-
Jul 23rd, 2003, 12:32 PM
#2
Using found Mod 200 does the Redim when found is 200, 400, 600, etc.
-
Jul 23rd, 2003, 12:32 PM
#3
Re: Err, integers!
Originally posted by adzzzz
Ello, first off; sorry I really couldn't think of a subject for this thread!
And now for the question... I was reading some code on VBnet and found a piece of code that has baffled me.
VB Code:
'if found is at 200, then add some more array elements
If found Mod 200 = 0 Then ReDim Preserve fArray(found + 200)
You see it? I don't understand the point of using 'Mod 200 = 0', what's wrong with just using 'found = 200'? Is there some sort of advantage noone has told me about with using Mod this way?
If anyone can explain why the coder has done this it'd make my day , well not quite, but nearly.
-Cheers
yeah... perhaps the coder wanted to make the code look harder than it needs to be... or maybe it was an example on a use for the mod operator
-
Jul 23rd, 2003, 12:33 PM
#4
Frenzied Member
What that does is redimension the array each time the array size gets to 200, 400, 600, 800, etc etc
It is more efficient than redimming every single time. That code is a bit hard to read since its all in one line.
-
Jul 23rd, 2003, 12:34 PM
#5
i guess it is a case of bad commenting
-
Jul 23rd, 2003, 12:35 PM
#6
Thread Starter
Hyperactive Member
Yer, I knew what the Mod did but I just don't see the point in using that instead of found = 200? Maybe it's like kleinma said, I dunno.
-Cheers
-
Jul 23rd, 2003, 12:36 PM
#7
Frenzied Member
It is looking to see if 200 divides into the "variable" found (whatever the value) evenly..
Rudy
Used to divide two numbers and return only the remainder.
Syntax
result = number1 Mod number2
The Mod operator syntax has these parts:
Part Description
result Required; any numericvariable.
number1 Required; anynumeric expression.
number2 Required; any numeric expression.
Remarks
The modulus, or remainder, operator divides number1 by number2 (rounding floating-point numbers to integers) and returns only the remainder as result. For example, in the followingexpression, A (result) equals 5.
A = 19 Mod 6.7
Usually, thedata type of result is aByte, Byte variant,Integer, Integer variant,Long, orVariant containing a Long, regardless of whether or not result is a whole number. Any fractional portion is truncated. However, if any expression isNull, result is Null. Any expression that isEmpty is treated as 0.
10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".
-
Jul 23rd, 2003, 12:39 PM
#8
Originally posted by adzzzz
Yer, I knew what the Mod did but I just don't see the point in using that instead of found = 200? Maybe it's like kleinma said, I dunno.
-Cheers
Do you understand now that while If found = 200 does it only once while if found Mod 200 = 0 does it multiple times?
-
Jul 23rd, 2003, 12:39 PM
#9
Thread Starter
Hyperactive Member
AHH! So the condition would still be true if it was 400 or 800 as well, I see. Didn't read it right, cheers
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
|