RTrain3k
RTrain3k

Reputation: 867

Print/Output variable values to immediate window

I'm trying to write some vba that will print the values which satisfy the below constraints:

b * k = t * k 

lambda = r * (k - 1) / (t - 1), where (t - 1) >= (k - 1) & lambda must be an integer.

Here is the algorithm:

Sub BIBDs()

Dim t, b, k, r As Integer
Dim lambda As String

For t = 2 To 50
    For b = 2 To 20
        For r = 1 To 20
            For k = 3 To 5
                If b * k = t * k & (t - 1) >= (k - 1) Then
                lambda = r * (k - 1) / (t - 1)
                    If lambda = Int(lambda) Then
                        Debug.Print t, b, r, k, lambda
                    End If
                End If
            Next k
        Next r
    Next b
Next t

End Sub

Nothing is printed in the "Immediate" window. I'm not sure it there is something wrong with the algorithm or my print method. Specifically, I'm not sure if I'm correctly checking that lambda is an integer.

Upvotes: 2

Views: 645

Answers (1)

Leo Chapiro
Leo Chapiro

Reputation: 13979

Try

If b * k = t * k And (t - 1) >= (k - 1) Then

instead of

If b * k = t * k & (t - 1) >= (k - 1) Then

The & operator in VBA is not the same like logical And operator: https://msdn.microsoft.com/en-us/library/wfx50zyk.aspx

Upvotes: 2

Related Questions