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
This was confirmed through 5 run throughs
I have no attached the sub that call Random_Limits to provide furhter detail
Sub Data_SetUp()
Application.ScreenUpdating = False
Sheets("Sheet1").Columns(2).Copy Destination:=Sheets("Sheet2").Columns(1)
Sheets("Sheet1").Columns(5).Copy Destination:=Sheets("Sheet2").Columns(2)
Worksheets("Sheet2").Activate
Rows(4).EntireRow.Delete
Cells(3, 1) = "Time"
Cells(3, 2) = "Throttle"
Cells(3, 3) = "Angle"
Cells(2, 1).Select
Selection.ClearContents
StartTimer = Timer
Iterations = InputBox("How many iteration would you like to run?")
IterationNumber = 1
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
End Sub
On request here is Limit_Def
Sub Limit_Def()
LimitUpdate = MsgBox("Would you like to keep the distance limit the same throughout?", vbYesNo)
If LimitUpdate = vbYes Then
LimitNow = MsgBox("Would you like to choose your limit now?", vbYesNo)
If LimitNow = vbYes Then
Limit = InputBox("Please set a line distance limit")
Else
End If
End If
Call Calculate_Angle
End Sub
Thank you for any help you can provide.