
n=d%*d% NO, bla=d% n=bla*bla YES, beginners question
Quote:
> > On Fri, 22 Nov 1996 05:34:04 GMT, Horst Stratemeier
> > : ndim% = Int(readndim.Text)
> > : ntot = ndim% * ndim%
> > : works only for ndim% up to 180.
> > I believe that the conversion to type variant (bla = ndim%) is
> > what saves the second piece of code. In effect, a% * b% probably attempts
> > to return something of type "%"; thus the overflow. When you explicitly
> > perform (bla * bla), the value returned is probably of type Variant. You
> > could simply convert one of the factors (ndim%) in your expression before
> > multiplying to avoid this error...*if* I'm right.
> Hira,
> Almost right !
> When VB processes an expression, it uses the first parameter in each parse
> to store the result of that parse. Hence it is trying to store 180*180
> in ndim% (temporarily) before assigning it to ntot.
> The way to get around it is,
> ntot = cLng(ndim%) * ndim%
> Steve.
Steve,
This is not true. If VB worked the way you say ndim% would be trashed
by the operation, and it's not. What happens is VB looks at the types
of the operands in an operation and takes the smallest that will fit
both. For example, with Integer * Integer VB performs an integer
multiplication. With Integer * Single VB would convert the Integer to
a single and then do a single presision operation. For more complex
expressions VB treats each seperatly. Thus:
d% = c!/ (a% * b%)
would first perform an integer multiplication of a% and b% yealding an
integer, which it would then convert to a single and do a single
precision division between c! and this result. The resultant single
preceision number would then be rounded and transfered to d%. In VB4
this goes a step further, for example:
a="123"
b%=10
debug.print a * b%
would produce 1230 when run within VB. The string is evaluated to a
number for the operation.
To answer the original question 200(Integer) * 200(Integer) = 40000
which is more that an integer can contain, thus the overflow.
You could stop it with:
nTot = clng(ndim%) * clng(ndim%)
However you could just change:
ndim% = Int(readndim.Text)
to
ndim& = clng(readndim.text)
which would produce a long integer in the first place.
HTH
Ken
----------------------------------------------------------------------
Applications Programmer/Network Manager Phone : (+44) (0)1865 224149
Diabetes Research, RI, Oxford, England Fax : (+44) (0)1865 723884