LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Bias in rand for excel 07

Ah, so that is how you draw into a UserForm... ThunderDFrame... I'll have to
remember that.

Thanks for performing the conversion. First, I removed the "1" off of the
Randomize statement in the second loop so that both Randomize statements
draw from the Timer for their seed values. Yes, this scatters the bar effect
on the second picture, but I think it is a fairer display of what is going
on. Second, I think if you change the Const C assignment statement in the
PaintPixel procedure to this...

Const C As Long = 16711680

you get a much starker (and more amazing) contrast between the two displays,
especially with the the Randomizer seed change mention above, especially
when you repeatedly click the UserForm. Yes, this removes the sharp vertical
lines that the seed value of 1 produced, but it still shows (and more fairly
I think) the sharp difference in randomization that occurs if you use the
Randomize statement only once. The modified code implementing the above is
shown below my signature.

Again, thanks for performing the compiled VB to Excel VBA conversion... you
did a nice job with it. I will be using your coded translation (with
appropriate acknowledgement to you, of course) should a similar question
rise in the future.

Rick

Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Private Declare Function SetPixel Lib "gdi32" _
(ByVal hDc As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal crColor As Long) As Long

Private Declare Function GetPixel Lib "gdi32" _
(ByVal hDc As Long, _
ByVal x As Long, _
ByVal y As Long) As Long

Private Declare Function GetDC Lib "user32" ( _
ByVal hWnd As Long) As Long

Private Declare Function ReleaseDC Lib "user32" ( _
ByVal hWnd As Long, ByVal hDc As Long) As Long

Private Sub PaintPixels()
Dim hWnd As Long, hDc As Long
Dim tp As Long, lt As Long
Dim x As Long, y As Long
Dim colr As Long

Const Z As Long = 128 * 2 - 1
Const C As Long = 16711680

Me.Left = 10: Me.Top = 10
Me.Width = (Z * 2) * 0.75 + 45: Me.Height = Z * 0.75 + 60
' if form is too small, change 0.75 to 1 or 1.25

hWnd = FindWindow("ThunderDFrame", Me.Caption)
hDc = GetDC(hWnd)

tp = Me.Top + 15
lt = Me.Left + 10

Randomize
For y = tp To tp + Z
For x = lt To lt + Z
colr = Rnd * C
SetPixel hDc, x, y, colr
Next
Next

lt = lt + Z + 15
For y = tp To tp + Z
For x = lt To lt + Z
Randomize
colr = Rnd * C
SetPixel hDc, x, y, colr
Next
Next

ReleaseDC hWnd, hDc
End Sub

Private Sub UserForm_Activate()
Me.Caption = "Click me to (re-) PaintPixels"
PaintPixels
End Sub

Private Sub UserForm_Click()
' Me.Repaint
PaintPixels
End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Random numbers but with a bias nurrrthk Excel Discussion (Misc queries) 5 July 17th 09 10:15 PM
how can i set up rand or rand between to give only -1 or 1? Uesiet Excel Worksheet Functions 8 October 27th 08 02:28 PM
Goal Seek Bias Tina Excel Worksheet Functions 1 March 30th 07 01:16 AM
excel rand() negative Rustin Excel Programming 2 September 26th 06 02:06 PM
Excel 2003-RND() vs Rand() Leigh[_2_] Excel Programming 4 May 2nd 04 11:15 AM


All times are GMT +1. The time now is 09:51 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"