Consulting

Results 1 to 5 of 5

Thread: Small problem with my code

  1. #1
    VBAX Regular
    Joined
    Jul 2016
    Posts
    13
    Location

    Small problem with my code

    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 <<<<<<<
    Last edited by SamT; 08-05-2016 at 05:12 AM. Reason: Text Formatting, CODE Tags, White Space in code

  2. #2
    VBAX Regular
    Joined
    Jul 2016
    Posts
    13
    Location
    Ok sorry I'm stupid. Sometimes I only see the problem with my codewhen I'm not using VBA.

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Yeah,me too. I'll post, then edit it ten times over.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Please post your correction for the benefit of others
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    ReDm Frequency(o To 1000) As Integer '<<<<<<<<<<<<<<<<<<

    ReDm Frequency(OH To 1000)
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •