-
Apr 26th, 2006, 01:28 PM
#1
Thread Starter
Junior Member
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?
-
Apr 26th, 2006, 01:29 PM
#2
Re: simple div operator question
What is "div"?
-
Apr 26th, 2006, 01:30 PM
#3
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"
-
Apr 26th, 2006, 01:32 PM
#4
Thread Starter
Junior Member
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
-
Apr 26th, 2006, 01:33 PM
#5
Re: simple div operator question
"Div" not a VB function. Are you using VB or VBA?
-
Apr 26th, 2006, 01:37 PM
#6
Thread Starter
Junior Member
Re: simple div operator question
i am using visual basic in excel (whatever that is?), and i guarantee it is a function
-
Apr 26th, 2006, 01:41 PM
#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
-
Apr 26th, 2006, 01:43 PM
#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?
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Apr 26th, 2006, 01:44 PM
#9
Thread Starter
Junior Member
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)
-
Apr 26th, 2006, 01:48 PM
#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
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Apr 26th, 2006, 01:56 PM
#11
Thread Starter
Junior Member
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
-
Apr 26th, 2006, 01:58 PM
#12
Addicted Member
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
-
Apr 26th, 2006, 02:04 PM
#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[???]
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"
-
Apr 26th, 2006, 02:34 PM
#14
Lively Member
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 )
"Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )
-
Apr 26th, 2006, 02:39 PM
#15
Addicted Member
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 /
-
Apr 26th, 2006, 02:43 PM
#16
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"
-
Apr 26th, 2006, 02:59 PM
#17
Fanatic Member
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
-
Apr 26th, 2006, 03:26 PM
#18
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"
-
Apr 26th, 2006, 03:37 PM
#19
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|