+ Reply to Thread
Results 1 to 7 of 7

How do I add a visual aspect to my macro??

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-23-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    239

    How do I add a visual aspect to my macro??

    I would like to add some visual aspects to my lottery macro. Like numbers flipping through the range as they appear (and I can control how long they flip through the range) and maybe a little rand () function as the numbers are picked. How would I do this and where would I add these two aspects???
    Can someone give me some help please?

    Thank you,

    Here is my code I am working with.

    Const l&         'lower value
    Const u& =       'upper value
    Const n& =         'number of numbers per draw
    rws = 100       'number of lottery draws
    ReDim a(1 To rws, 1 To n)
    
    Randomize
    For i = 1 To rws
        ReDim b(l To u): k = 0: s = ""
        Do
            x = Int(Rnd * u) + l
     
    End Sub
    Last edited by b_rianv; 09-01-2014 at 10:06 AM.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How do I add a visual aspect to my macro??

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Contributor
    Join Date
    06-23-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    239

    Re: How do I add a visual aspect to my macro??

    Sorry, I forgot to do that. But It is corrected now.

  4. #4
    Forum Contributor lancer102rus's Avatar
    Join Date
    04-02-2014
    Location
    Ufa
    MS-Off Ver
    Excel 2010, 2013
    Posts
    252

    Re: How do I add a visual aspect to my macro??

    try this
    222.xlsm

  5. #5
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: How do I add a visual aspect to my macro??

    To add "visuals", it is actually creating some form delay. I use a separate function to create the delay, and make it generate lots of random numbers before displaying results.

    Sub YourLottery()
    
        Const l& = 1 'lower value
        Const u& = 53 'upper value
        Const n& = 6 'number of numbers per draw
        Dim a(), b() As Boolean
        Dim rws&, i&, x&, k&, j&, j2&
        rws = 100 'number of lottery draws
        ReDim a(1 To rws, 1 To n)
        
        Randomize
        For i = 1 To rws
            Cells(i, 1).Value = "Draw " & i
            
            ReDim b(l To u): k = 0
            Do
                x = Int(Rnd * u) + l
                If Not b(x) Then k = k + 1: b(x) = True
            Loop Until k = n
            
            For j = 1 To 50
                For j2 = 1 To n
                    Cells(i, 2 + j2).Value = Int(Rnd * u) + l
                Next
                Delay 0.01
            Next
            
            k = 0
            For x = l To u
                If b(x) Then k = k + 1: Cells(i, 2 + k).Value = x
            Next x
        Next i
    End Sub
    
    
    
    Private Function Delay(secs As Variant)
        On Error GoTo Err_Pause
        Dim PauseTime As Variant, start As Variant
        PauseTime = secs
        start = Timer
        Do While Timer < start + PauseTime
            DoEvents
        Loop
    Exit_Pause:
        Exit Function
    Err_Pause:
        MsgBox Err.Number & " - " & Err.Description, vbCritical, "Delay()"
        Resume Exit_Pause
    End Function
    多么想要告诉你 我好喜欢你

  6. #6
    Forum Contributor
    Join Date
    06-23-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    239

    Re: How do I add a visual aspect to my macro??

    Thanks guys I will test these two and let you know

  7. #7
    Forum Contributor
    Join Date
    06-23-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    239

    Re: How do I add a visual aspect to my macro??

    I would like to thank both of you guys, the codes that you gave me work perfectly. Thanks again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 05-23-2013, 11:15 AM
  2. Get aspect ratio from dimensions
    By martix in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-05-2011, 09:19 PM
  3. Is aspect ratio possible in an XY scatter
    By mewingkitty in forum Excel Charting & Pivots
    Replies: 12
    Last Post: 03-05-2009, 10:47 PM
  4. How to copy a graphic and keep the same aspect
    By feejo in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 11-15-2007, 12:53 PM
  5. Replies: 1
    Last Post: 09-13-2005, 07:06 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1