Results 1 to 19 of 19

Thread: simple div operator question

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    18

    simple div operator question

    when i write this simple line of code that seems to have no problem:

    randomvalue = mynumber div 1000

    i receive a error msgbox, saying something like expected end of statement/line

    how can this be resolved?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: simple div operator question

    What is "div"?

  3. #3
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: simple div operator question

    whats div??

    divide?

    randomvalue = mynumber / 1000
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    18

    Re: simple div operator question

    div is best demonstrated in an example:

    e.g. 50 div 7, it will give the highest common factor of the number(integer),
    so in this case it would be 7

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: simple div operator question

    "Div" not a VB function. Are you using VB or VBA?

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    18

    Re: simple div operator question

    i am using visual basic in excel (whatever that is?), and i guarantee it is a function

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: simple div operator question

    Quote Originally Posted by kazoo
    i am using visual basic in excel (whatever that is?), and i guarantee it is a function
    It is not a function in VB, although it appears as though it is a function in Excel VBA.

    Moved to Office Development

  8. #8
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: simple div operator question

    Quote Originally Posted by kazoo
    i am using visual basic in excel (whatever that is?), and i guarantee it is a function


    not that ive ever seen.. is it a WORKSHEET function?
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    18

    Re: simple div operator question

    so now that we agree it is a operator, can someone solve my first question pls. i have basic knowledge , but it is in the visual basic user form code thats all i know (when you click tools , macro etc)

  10. #10
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: simple div operator question

    I cant find this anywhere?? Ive look in the object browser.. in the help.. worksheet functions.. nothing.
    Typed it into the imediate window as well.. I dont see it
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    18

    Re: simple div operator question

    here is proof of it from another piece of code i have seen

    In the algorithm, DIV is an operator that divides one integer by a second integer and truncates the
    result to its integer part. This means that
    15 DIV 4 is 3
    19 DIV 2 is 9
    0 size = 10
    1 sep = size DIV 2
    2 WHILE sep > 0
    3 FOR count = 1 TO size - sep
    4 index = count
    5 WHILE (index > 0) AND (Sift[index] > Sift[index + sep])
    6 spare = Sift[index]
    7 Sift[index] = Sift[index + sep]
    8 Sift[index + sep] = spare
    9 index = index - sep
    10 ENDWHILE
    11 NEXT count
    12 sep = sep DIV 2
    13 ENDWHILE

  12. #12
    Addicted Member
    Join Date
    Jan 2006
    Location
    Montreal, Canada
    Posts
    152

    Re: simple div operator question

    If div is a function or operator then you probably use Excel 2010 or 2011.
    Unfortunately we do not have this update yet

    If
    e.g. 50 div 7, it will give the highest common factor of the number(integer),
    so in this case it would be 7
    then div = divide
    this code will do the tricks

    VB Code:
    1. dim randomvalue as integer
    2. randomvalue = mynumber /1000

    since randomvalue is an INTEGER
    e.g. 50/7 = 7.XXXXX

    INTEGER do not take decimal so will equal 7

  13. #13
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: simple div operator question

    Quote Originally Posted by kazoo
    here is proof of it from another piece of code i have seen

    In the algorithm, DIV is an operator that divides one integer by a second integer and truncates the
    result to its integer part. This means that
    15 DIV 4 is 3
    19 DIV 2 is 9
    0 size = 10
    1 sep = size DIV 2
    2 WHILE sep > 0
    3 FOR count = 1 TO size - sep
    4 index = count
    5 WHILE (index > 0) AND (Sift[index] > Sift[index + sep])
    6 spare = Sift[index]
    7 Sift[index] = Sift[index + sep]
    8 Sift[index + sep] = spare
    9 index = index - sep
    10 ENDWHILE
    11 NEXT count
    12 sep = sep DIV 2
    13 ENDWHILE
    where did u get that code from?
    ENDWHILE is not VB or VBA
    Sift[???]

    but as far as your answer billhuard is correct..
    using an integer or (integer division) will have this result

    integer division is this

    result = 15\4
    (note the slash is \ and not /)
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  14. #14
    Lively Member New2vba's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    95

    Re: simple div operator question

    Quote Originally Posted by Static
    using an integer or (integer division) will have this result
    Integer division (\ operator) works, but integers alone do not. For comparision:

    55 / 7 = 8

    55 \ 7 = 7

    (I think )
    "Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )

  15. #15
    Addicted Member
    Join Date
    Jan 2006
    Location
    Montreal, Canada
    Posts
    152

    Re: simple div operator question

    You're right!!!!!
    just did the test and VBA is rouding to the nearest odd number called Banker rounding

    So to get your result you should use \ and not /

  16. #16
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: simple div operator question

    i too forgot that it rounds... bah!
    well.. at least \ works
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  17. #17
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    610

    Re: simple div operator question

    I don't believe the listing is visual basic code. It is psuedo code to illustrate an algorithm. Look at page 4 of this:

    http://www.ocr.org.uk/OCR/WebSite/Da...Level93039.pdf

  18. #18
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: simple div operator question

    ok.. but my only point was DIV is not any sort of function etc in EXCEL
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  19. #19

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    18

    Re: simple div operator question

    ok, so i shall use the backslash key then

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