以下代码用于VBA中
Function CountIt(total As Integer, Blong As Double, Bwide As Double, Slong As Double, Swide As Double) As Integer
a = a + 1
'********************************** Type a **********************************
b = 1
If (Blong >= Swide) And (Bwide >= Slong) Then
total = total + Fix(Blong / Swide)
mode1 = mode1 + CStr(1)
CountIt total, Blong, Bwide - Slong, Slong, Swide
total = total - Fix(Blong / Swide)
mode1 = Left(mode1, Len(mode1) - 1)
Else
If maxc < total Then
maxc = total
mode2 = mode1
End If
End If
'********************************** Type b **********************************
b = 2
If (Blong >= Slong) And (Bwide >= Swide) Then
total = total + Fix(Blong / Slong)
mode1 = mode1 + CStr(2)
CountIt total, Blong, Bwide - Swide, Slong, Swide
total = total - Fix(Blong / Slong)
mode1 = Left(mode1, Len(mode1) - 1)
Else
If maxc < total Then
maxc = total
mode2 = mode1
End If
End If
'********************************** Type C **********************************
b = 3
If (Blong >= Swide) And (Bwide >= Slong) Then
total = total + Fix(Bwide / Slong)
mode1 = mode1 + CStr(3)
CountIt total, Blong - Swide, Bwide, Slong, Swide
total = total - Fix(Bwide / Slong)
mode1 = Left(mode1, Len(mode1) - 1)
Else
If maxc < total Then
maxc = total
mode2 = mode1
End If
End If
'********************************** Type D **********************************
b = 4
If (Blong >= Slong) And (Bwide >= Swide) Then
total = total + Fix(Bwide / Swide)
mode1 = mode1 + CStr(4)
CountIt total, Blong - Slong, Bwide, Slong, Swide
total = total - Fix(Bwide / Swide)
mode1 = Left(mode1, Len(mode1) - 1)
Else
If maxc < total Then
max = total
mode2 = mode1
End If
End If