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?
Printable View
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?
:confused: What is "div"?
whats div??
divide?
randomvalue = mynumber / 1000
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
"Div" not a VB function. Are you using VB or VBA?
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.Quote:
Originally Posted by kazoo
Moved to Office Development
http://www.vbforums.com/Quote:
Originally Posted by kazoo
not that ive ever seen.. is it a WORKSHEET function?
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)
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
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
If div is a function or operator then you probably use Excel 2010 or 2011.
Unfortunately we do not have this update yet :) :)
Ifthen div = divideQuote:
e.g. 50 div 7, it will give the highest common factor of the number(integer),
so in this case it would be 7
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
where did u get that code from?Quote:
Originally Posted by kazoo
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 /)
Integer division (\ operator) works, but integers alone do not. For comparision:Quote:
Originally Posted by Static
55 / 7 = 8
55 \ 7 = 7
(I think :confused: )
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 /
;) i too forgot that it rounds... bah!
well.. at least \ works :)
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
ok.. but my only point was DIV is not any sort of function etc in EXCEL :)
ok, so i shall use the backslash key then