I'm trying to setup an array so I can loop through a standard code that repeats itself many times. Looping through the values would make the code much more manageable.
When I add an array to the Sub main() the code won't run, and if I add it outside of the Sub, I get an error. I'm a newbie at VBA, but so I don't know if I'm not adding the array to the proper place.
Here is my code. I appreciate the help.
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
'Arrays
Dim lgth
lgth = Array(0.096162, 0.089293, 0.075556, 0.068687, 0.061818, 0.05495, 0.048018, 0.041212, 0.03434, 0.027475, 0.020606, 0.013737, 0.006869)
Dim baff
baff = Array(9, 8.5, 8, 7.5, 7, 6.5, 6, 5.5, 5, 4.5, 4, 3.4, 3, 2.5)
Set swApp = _
Application.SldWorks
Set Part = swApp.ActiveDoc
For i = 1 To LBound(lgth)
Set Part = swApp.ActiveDoc
'Build first baffle pair
'Build front square
Part.SketchManager.InsertSketch True
boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 6.41854988562748E-02, 0.031581989490289, 0, False, 0, Nothing, 0)
Part.ClearSelection2 True
boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swSketchAddConstToRectEntity, swUserPreferenceOption_e.swDetailingNoOptionSpecified, True)
boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swSketchAddConstLineDiagonalType, swUserPreferenceOption_e.swDetailingNoOptionSpecified, True)
Dim vSkLines As Variant
vSkLines = Part.SketchManager.CreateCenterRectangle(0, 0, 0, baff(i) / 2, baff(i) / 2, 0)
Dim myModelView As Object
Part.ClearSelection2 True
Part.SketchManager.InsertSketch True
'Build outlet
boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, True, 0, Nothing, 0)
Dim myRefPlane As Object
Set myRefPlane = Part.FeatureManager.InsertRefPlane(264, lgth(i), 0, 0, 0, 0)
myRefPlane.Name = "Plane1"
Part.Extension.SelectByID2 "Plane" & i, "PLANE", 0, 0, 0, False, 0, Nothing, 0
boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swSketchAddConstToRectEntity, swUserPreferenceOption_e.swDetailingNoOptionSpecified, True)
boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swSketchAddConstLineDiagonalType, swUserPreferenceOption_e.swDetailingNoOptionSpecified, True)
'Dim vSkLines As Variant
vSkLines = Part.SketchManager.CreateCenterRectangle(0, 0, 0, 0.02, 0.02, 0)
Part.ClearSelection2 True
Part.SketchManager.InsertSketch True
Next i
End Sub