PDA

View Full Version : [SOLVED] Small problem with my code



Anthon
08-05-2016, 02:37 AM
Hey guys again, and thank you very much for helping me with my last problem. Here's another one I encountered. Script is below:


Sub RandomNumberSimulation() 'Sinmulating the lognormal distribution with delta t = 1
Application.ScreenUpdating = False
Range("starttime") = Time
n = Range("runs").Value
mean = Range("mean")
sigma = Range("sigma")

ReDm Frequency(o To 1000) As Integer '<<<<<<<<<<<<<<<<<<
For Index = 1 To n
start:
Static rand1, rand2, S1, S2, X1, X2
rand1 = 2 * Rnd - 1
rand2 = 2 * Rnd - 1
S1 = rand1 ^ 2 + rand2 ^ 2
If S1 > 1 Then GoTo start

S2 = Sqr(-2 * Log(S1) / S1)
X1 = rand1 * S2
X2 = rand2 * S2

Return1 = Exp(mean + sigma * X1)
Return2 = Exp(mean + sigma * X2)
Frequency(Int(Return1 / 0.01)) = _
Frequency(Int(Return1 / 0.01)) + 1
Frequency(Int(Return2 / 0.01)) = _
Frequency(Int(Return2 / 0.01)) + 1
Next Index

For Index = 0 To 400
Range("simuloutput").Cells(Index + 1, 1) = Frequency(Index) / n
Next Index

Range("stoptime") = Time
Range("elapsed") = Range("stoptime") - Range("starttime")
Range("elapsed").NumberFormat = "hh:mm:ss"
End Sub

The red font text is where the problem lies. Error message says Expected List separator or ). Your advice is highly appreciated thanks!

Moderator Note: Font formatting (RED) removed to place CODE Tags around code text. Error line indicated with commented <<<<<<<

Anthon
08-05-2016, 02:39 AM
Ok sorry I'm stupid. Sometimes I only see the problem with my codewhen I'm not using VBA.

SamT
08-05-2016, 05:10 AM
Yeah,me too. I'll post, then edit it ten times over. :crying:

mdmackillop
08-05-2016, 11:35 PM
Please post your correction for the benefit of others

SamT
08-06-2016, 08:48 AM
ReDm Frequency(o To 1000) As Integer '<<<<<<<<<<<<<<<<<<

ReDm Frequency(OH To 1000)