Please can you supply the full environment or define your problem more closely? Thank you.
Sub SquaresInCircle()
Dim dblRadius As Double 'radius of circle
Dim dblLength As Double 'length of side
Dim dblTopRow As Double 'distance from centre of top of top row
Dim iTopCount As Integer 'number in top row
Dim iSquareTotal As Integer 'count of squares
Dim dblCurrentHeight As Double
Dim dblRowWidth As Double 'width of row
Dim dblRowCount As Integer
Dim iStartLimit As Integer
Dim iMaxCount As Integer
Dim iMaxStart As Integer
dblRadius = 100 'samplesizes
dblLength = 10
iTopCount = 1
iStartLimit = Int(2 * dblRadius / dblLength)
Do Until iTopCount > iStartLimit
dblTopRow = Sqr(dblRadius ^ 2 - ((dblLength / 2) * iTopCount) ^ 2)
dblCurrentHeight = dblTopRow
dblRowCount = 0
iSquareTotal = 0
Do
iSquareTotal = iSquareTotal + dblRowCount
dblCurrentHeight = dblCurrentHeight - dblLength
If dblCurrentHeight ^ 2 > dblRadius ^ 2 Then
Exit Do
End If
dblRowWidth = 2 * Sqr(dblRadius ^ 2 - dblCurrentHeight ^ 2)
dblRowCount = Int(dblRowWidth / dblLength)
If iStartLimit = Int(2 * dblRadius / dblLength) Then
iStartLimit = dblRowCount
End If
Loop Until dblRowCount = 0
If iSquareTotal > iMaxCount Then
iMaxCount = iSquareTotal
iMaxStart = iTopCount
End If
iTopCount = iTopCount + 1
Loop
Debug.Print iMaxCount, iMaxStart
End Sub
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
18 Experts available now in Live!