Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript with a subroutine calling itself

Status
Not open for further replies.

jmarkus

Technical User
Oct 15, 2002
124
0
0
CA
I am trying to write a VBScript to perform some nested functions. Within my Subroutine I need to call the same subroutine (passing a different variable) until I have worked through the structure. What are the limitations (if any) I need to understand to make it work. For the record, my script currently runs correctly in terms of reporting out the values of various variables, but it doesn't perform the functions on those variables correctly. It is almost as if once it gets into the first nested call of the subroutine it nulls the functions and doesn't do anything.

I hope that makes sense and somebody can help shed some light on the subject.

Thanks,
Jeff
 
hi,

Post your code.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
This is the basic VBScript (it runs inside CATIA):

Code:
Sub CATMAIN()
Dim oTopProduct As Product
Dim MainDocument As ProductDocument
Set MainDocument = CATIA.ActiveDocument
Set oTopProduct = MainDocument.Product

Call TurnOff(oTopProduct)

End Sub

Sub TurnOff(oTopProduct)

Dim i,j
Dim selection1 As Selection
Dim visPropertySet1 As VisPropertySet
Dim ItemToHide As Product
Dim NumberOfItems As Long
Dim SelectionList as String

Set selection1 = oTopProduct.Parent.Selection
Set visPropertySet1 = selection1.VisProperties
NumberOfItems = oTopProduct.Products.Count
SelectionList = ""

selection1.Clear
For i = 1 to NumberOfItems
    set ItemToHide = oTopProduct.Products.Item(i)
	selection1.Add ItemToHide
	MsgBox "Added " & ItemToHide.PartNumber
	SelectionList = SelectionList & chr(10) & selection1.Item(i).LeafProduct.PartNumber
next
MsgBox "Selection is " & SelectionList

Set visPropertySet1 = selection1.VisProperties
VisPropertySet1.SetShow 1 'HIDE
MsgBox "Selected components should be off"

For j = 1 to NumberOfItems
Set ItemToHide = oTopProduct.Products.Item(j)
k = ItemToHide.Products.Count
if k > 0 then
	VisPropertySet1.SetShow 0 'SHOW
	MsgBox "Entering " & ItemToHide.ReferenceProduct.PartNumber
	selection1.Clear
	Call TurnOff(ItemToHide.ReferenceProduct)
	VisPropertySet1.SetShow 1 'HIDE
end if
next

End Sub

All the MsgBoxes show the right information, but the SetShow methods only work the first time around.

Thanks,
Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top