Thread: What data type?
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Harald Staff Harald Staff is offline
external usenet poster
 
Posts: 1,327
Default What data type?

I can't mod those huge numbers either, so I can only confirm the problems.

You may then regain some speed by not selecting anything. Shorten your code
to (not tested):

a = Range("B1").Value
c = Range("B2").Value
m = Range("B3").Value
varKolicina = Range("B4").Value
y = Range("B5").Value

For i = 1 To varKolicina
z = a * y
Range("I1").FormulaR1C1 = z
x = Range("I2").Value
Range("A7").Offset(i, 0).FormulaR1C1 = x
y = x
Next i

--
HTH. Best wishes Harald
Followup to newsgroup only please

"Srdjan Kovacevic" skrev i melding
...
Post the code please. The overflow may be caused by something else that

the
receiving variable.


Thanks for your reply... The code is below...

However, I've made a slight change, that turned out to be a workaround...
See, I've noticed that the program can't perform Mod operation with two
numbers over 6 digits each, if the mod is called from within the code.
However, if I try to do that operation in the worksheet, it works

perfectly
(but substantially slower).

That's why I've made it copy certain values in the worksheet, do the
calculation in the cell and then copy the value from the cell to the
variable (the bit in the loop -- I2 is the cell where I've put the Mod()
operation)..

As I said, if I try to do "x = z mod m" operation in the code (where z is

of
the scale of E12 and m is a 6-digit number) it reports overflow...

thx.s


Sub LCG_MLCG()
'
' LCG Makronaredba
' Makronaredbu dana 10.10.2003 snimio Sršan
'

Dim a As Double
Dim c As Double
Dim m As Double
Dim x As Double
Dim y As Double
Dim z As Double

Dim varKolicina As Long

Range("B1").Select
a = ActiveCell.Value

Range("B2").Select
c = ActiveCell.Value

Range("B3").Select
m = ActiveCell.Value

Range("B4").Select
varKolicina = ActiveCell.Value

Range("B5").Select
y = ActiveCell.Value



For i = 1 To varKolicina

z = a * y

Range("I1").Select
ActiveCell.FormulaR1C1 = z

Range("I2").Select
x = ActiveCell.Value

Range("A7").Select

ActiveCell.Offset(i, 0).Select
ActiveCell.FormulaR1C1 = x

y = x


Next i

End Sub