# Thread: simple div operator question

1. ## 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. ## Re: simple div operator question

What is "div"?

3. ## Re: simple div operator question

whats div??

divide?

randomvalue = mynumber / 1000

4. ## 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. ## Re: simple div operator question

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

6. ## Re: simple div operator question

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

7. ## Re: simple div operator question

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. ## Re: simple div operator question

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?

9. ## 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. ## 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

11. ## 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. ## 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:
```dim randomvalue as integer
randomvalue = mynumber /1000```

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

INTEGER do not take decimal so will equal 7

13. ## Re: simple div operator question

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[???]

using an integer or (integer division) will have this result

integer division is this

result = 15\4
(note the slash is \ and not /)

14. ## Re: simple div operator question

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 )

15. ## 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. ## Re: simple div operator question

i too forgot that it rounds... bah!
well.. at least \ works

17. ## 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. ## Re: simple div operator question

ok.. but my only point was DIV is not any sort of function etc in EXCEL

19. ## 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
•