Results 1 to 9 of 9

Thread: Err, integers! - resolved

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506

    Lightbulb Err, integers! - resolved

    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:
    1. 'if found is at 200, then add some more array elements
    2.     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
    Last edited by adzzzz; Jul 23rd, 2003 at 12:40 PM.

  2. #2

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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:
    1. 'if found is at 200, then add some more array elements
    2.     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

  4. #4
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    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.

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    i guess it is a case of bad commenting

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    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

  7. #7
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    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".

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    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?

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    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
  •  



Click Here to Expand Forum to Full Width