Hi All,
Does anyone know if it's possible to show Random Numbers Looping on a UserForm.
I'd like to show random numbers being generated using a Do Loop on a userform.
is this possible?
Thanks,
Jim
Hi All,
Does anyone know if it's possible to show Random Numbers Looping on a UserForm.
I'd like to show random numbers being generated using a Do Loop on a userform.
is this possible?
Thanks,
Jim
It's possible
This is in standard module, and there's a command button on the user form to stop it (attachment)
You'll need to integrate into your code of course
Option Explicit Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Public StopRand As Boolean Sub StartRand() Dim R As Double StopRand = False Load UserForm1 UserForm1.Show vbModeless R = Rnd Do UserForm1.Label1.Caption = Format(R, "0.000000") UserForm1.Repaint DoEvents R = Rnd Sleep 500 Loop Until StopRand UserForm1.Hide Unload UserForm1 End Sub
---------------------------------------------------------------------------------------------------------------------
Paul
Remember: Tell us WHAT you want to do, not HOW you think you want to do it
1. Use [CODE] ....[/CODE ] Tags for readability
[CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
2. Upload an example
Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
3. Mark the thread as [Solved] when you have an answer
Thread Tools (on the top right corner, above the first message)
4. Read the Forum FAQ, especially the part about cross-posting in other forums
http://www.vbaexpress.com/forum/faq...._new_faq_item3
Hi Paul,
Thank you.
This is exactly what I was looking for.
One last question. Is it possible to update a graph (in the userform beside these random numbers). Can a graph (i.e. histogram) dynamically change or update based on these random numbers all within the same userform?
Thanks,
Jim
Don't think so unless you updated the graph on a sheet, saved it as a picture, and then updated the image on the user form .... maybeIs it possible to update a graph (in the userform beside these random numbers). Can a graph (i.e. histogram) dynamically change or update based on these random numbers all within the same userform?
---------------------------------------------------------------------------------------------------------------------
Paul
Remember: Tell us WHAT you want to do, not HOW you think you want to do it
1. Use [CODE] ....[/CODE ] Tags for readability
[CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
2. Upload an example
Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
3. Mark the thread as [Solved] when you have an answer
Thread Tools (on the top right corner, above the first message)
4. Read the Forum FAQ, especially the part about cross-posting in other forums
http://www.vbaexpress.com/forum/faq...._new_faq_item3
You can fake a Graph with tall, Skinny Labels (Vertical Bars)
Place them in a Frame for easier math
Each Chart Bar (Label) Height would be set by its Random Number and its Top Property would then be Frame Height - Bar Height
For horizontal Bars, it's easier then that. All Lefts are fixed and Bar Widths are a function of the Random Numbers.
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
Thanks Paul and Sam.
That would be very cool to do but it's beyond my expertise a little. The random numbers looping on the userform will work for now. I guess I can show the same random numbers on a sheet and show the dynamic graph update with each random change.
Thanks again.
I would be no where without this help. Thx.
Jim
Paul's Form with Fake Graph
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
Thanks Sam. This is neat.
I was successful modifying the userform to add more labels and bars. But I wasn't able to make the bars go up and done (versus side to side).
Lets say I wanted to make the bars go up and down and make the chart look like a bell curve....so that the bars lengths would have a maximum (shaped like a bell curve), with the random number labels looping underneath each bar.
Could you help show that? I was having difficultly getting the bars to move up and down.
Thanks,
Jim
Bell Curve with random values? That ain't gonna happen in this world.
Place the Bars labels in a Frame. Under the Frame, organize the values Labels.
Add this line to the beginning of the StartRandom subUnder the With UserForm1 line, addDim MaxHeight as DoubleInside the For Each loop, replace .Controls("Bar" & i).Width = 100*R withMaxHeight = .Controls("Frame1").HeightNote that I did not redownload the workbook, so I am working from memory.With .Controls("Bar" & i) .Height = R * MaxHeight .Top = MaxHeight - (1 - R) End with
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
Try this version
Capture.JPG
You'll have to play with the sizes to get the legibility you want
---------------------------------------------------------------------------------------------------------------------
Paul
Remember: Tell us WHAT you want to do, not HOW you think you want to do it
1. Use [CODE] ....[/CODE ] Tags for readability
[CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
2. Upload an example
Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
3. Mark the thread as [Solved] when you have an answer
Thread Tools (on the top right corner, above the first message)
4. Read the Forum FAQ, especially the part about cross-posting in other forums
http://www.vbaexpress.com/forum/faq...._new_faq_item3
This is really really cool. Thanks Paul