Re: using arrays with loop statements
- From: Stefan Hoffmann <stefan.hoffmann@xxxxxxxxxx>
- Date: Thu, 13 Jul 2006 14:35:19 +0200
hi,
Grimwadec wrote:
Thanks Stefan...looks like I am out of my depth here...I don't understand the range definitions of closed, half-open or open interval ?open: Ll < Na * Sa + Nb * Sb < Lu
No boundary is part of the range.
half-open: Ll < Na * Sa + Nb * Sb <= Lu or
Ll <= Na * Sa + Nb * Sb < Lu
One boundary is part of the range.
closed: Ll <= Na * Sa + Nb * Sb <= Lu
Both boundaries are part of the range.
what I am aiming for is the matrix result to be BOTH equal to or greater than 590 AND equal to or less than 600..It is a closed range, because both boundaries are a solution to your problem. So the <= operator is necessary for both checks.
as it transpires I don't think I really need to understand it but it would be useful to know how to effect the transformation to use it for computation in excel even though I have been able to transform it for Access purposes, and with some further thought as to how to write the Loop statement code in VBA (for Access purposes) I think I now know how to approach writing that code...the whole exercise by the way, is for a database that my nephew will use in his business for formulating the most efficient means of setting out objects for printing (by a new machine he is getting)on a continuous roll of material 600mm wide.I assume that it is better to have more large objects then small objects.
Dim Ll As Long ' lower boundary
Dim Lu As Long ' upper boundary
Dim Sa As Long ' size of elements in array A
Dim Sb As Long ' size of elements in array B
Dim A() As Long
Dim B() As Long
Public Function TestNumbers(Na As Long, Nb As Long) As Boolean
TestNumbers = ((Na * Sa) + (Nb * Sb)) >= Ll And _
((Na * Sa) + (Nb * Sb)) <= Lu
End Function
Public Sub CalcNumbers
Dim CountA As Long
Dim CountB As Long
Dim Na As Long
Dim Nb As Long
' initialize your arrays
' initialize calculation
Ll = 590
Lu = 600
Sa = 29
Sb = 15
Na = 0
Nb = 0
For CountA = LBound(A()) To UBound(A())
For CountB = LBound(B()) To UBound(B())
If TestNumbers(A(CountA), B(CountB)) Then
' output all solutions to the immediate window
Debug.? "Solution (" & A(CountA) & ", " & B(CountB) & ")."
If Sa > Sb Then
If A(CountA) > Na Then
Na = A(CountA)
Nb = B(CountB)
End If
Else
If B(CountA) > Nb Then
Na = A(CountA)
Nb = B(CountB)
End If
End If
End If
Next CountB
Next CountA
MsgBox "Best solution (" & Na & ", " & Nb & ")."
End Sub
mfG
--> stefan <--
.
- Follow-Ups:
- Re: using arrays with loop statements
- From: Grimwadec
- Re: using arrays with loop statements
- References:
- Re: using arrays with loop statements
- From: Stefan Hoffmann
- Re: using arrays with loop statements
- From: Stefan Hoffmann
- Re: using arrays with loop statements
- Prev by Date: Re: recordset problem
- Next by Date: Re: using arrays with loop statements
- Previous by thread: Re: using arrays with loop statements
- Next by thread: Re: using arrays with loop statements
- Index(es):
Relevant Pages
|