mardi 16 janvier 2018

Why does this only generate 1 pair of solutions

This is a slightly wired question.

I have a long 1500 line code with multiple subs within, the idea behind is smoothing 100,000's data points.

I have a random number generator within the code, found below but whenever I run the main code my two Limits are always UpperAngleLimit= 79 and LowerAngleLimit = 6 but whenever I run only this sub I find that I get totaly random number like planned.

Below is the code for the Random Limits generateion.

Sub Random_Limits()

UpperAngleLimit = Int((90 - 1 + 1) * Rnd + 1)
LowerAngleLimit = Int((90 - 1 + 1) * Rnd + 1)




If UpperAngleLimit = LastUpperLimit Then

    Call Random_Limits

Else

    If LowerAngleLimit = LastLowerLimit Then

        Call Random_Limits

    Else

        If UpperAngleLimit > LowerAngleLimit Then

            If UpperAngleLimit > 60 Then

                If LowerAngleLimit < 45 Then

                    LastLowerLimit = LowerAngleLimit
                    LastUpperLimit = UpperAngleLimit

                    Call Calculate_Angle

                Else

                    Call Random_Limits

                End If

            Else

                Call Random_Limits

            End If

        Else

            Call Random_Limits

        End If

    End If

End If

End Sub

I've have also placed all other mentions of either UpperAngleLimit & LowerAngleLimit as well.

Global UpperAngleLimit As Double
Global LowerAngleLimit As Double

^^Variable definitaions

RandomLimits = MsgBox("Would you like to have random limits generated?", vbYesNo)

If RandomLimits = vbYes Then

    Call Random_Limits

End If

UpperAngleLimit = InputBox("What Upper Angle Limit would you like to spline the curve from?")
LowerAngleLimit = InputBox("What Lower Angle Limit would you like to spline the curve from?")

Call Limit_Def

^^ Used if the user dosen't want to generate the limits randomly

If Cells(j, 3) < UpperAngleLimit And Cells(j, 3) > LowerAngleLimit Then

^^ Used to identify indiviual cells

Cells(1, 4) = "Curve Data produced for limits at " & UpperAngleLimit & " and " & LowerAngleLimit & " @ " & Limit

^^ Used to name data group

These are all the mentions of the both UpperAngleLimit and LowerAngleLimit

I relise that I may be hard for you to get the same issue as I have with them always being 79 & 6 but you may be able to see a glearing error that I have overlooked.

Some extra detail,

The code will always produce 79 and 6 on its 3rd loop with the same number being produced beforehand.

Run 1 - UpperAngleLimit = 64 LowerAngleLimit = 49 Run 2 - UpperAngleLimit = 74 LowerAngleLimit = 64 Run 3 - UpperAngleLimit = 78 lowerAngleLimit = 72 Run 4 - UpperAngleLimit = 79 LowerAngleLimit = 6

Thank you for any help you can provide.




Aucun commentaire:

Enregistrer un commentaire