Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

VBScript Existing Component Loop Problems

Status
Not open for further replies.

tpalsl125

Automotive
Apr 24, 2015
44
0
0
DE
Hello all,

I made the script to make Existing Component with Do ... Loop.

This can make just first time and after can't make it and pop up the errors.

Here is my script. Could you tell me where it is wrong?

Code:
Sub CATMain()


Set productDocument1 = CATIA.ActiveDocument
Set product1 = productDocument1.Product
Set products1 = product1.Products

Do

Dim arrayOfVariantOfBSTR1(0)
arrayOfVariantOfBSTR1(0) = "C:\tmp\Part1.CATPart"
products1.AddComponentsFromFiles arrayOfVariantOfBSTR1, "All"

AskMsgBox = MsgBox("Whould you like to do once more?", vbYesNo, "Question")
Loop Until AskMsgBox = vbNo


End Sub
 
Replies continue below

Recommended for you

try:

Code:
do while AskMsgBox = vbNo
....
AskMsgBox = MsgBox("Whould you like to do once more?", vbYesNo, "Question")
loop

Eric N.
indocti discant et ament meminisse periti
 
Thank you for your reply.

I tried to do with your script. I'm sorry but anything doesn't happen, even the Msgbox doesn't work.

So I modified yours to below script. But also this doesn't work with pop up the error.

Only 1st time can make it and after it doesn't work.

Could you tell me why it doesn't work..?
Code:
Do until AskMsgBox = vbNo
  Dim arrayOfVariantOfBSTR1(0) ' -----> Here is error line
  arrayOfVariantOfBSTR1(0) = "C:\Temp\Part1.CATPart"
  products1.AddComponentsFromFiles arrayOfVariantOfBSTR1, "All"
  AskMsgBox = MsgBox("Whould you like to do once more?", vbYesNo, "Question")
Loop
Code:
Do while AskMsgBox = vbYes
  Dim arrayOfVariantOfBSTR1(0) ' -----> Here is error line
  arrayOfVariantOfBSTR1(0) = "C:\Temp\Part1.CATPart"
  products1.AddComponentsFromFiles arrayOfVariantOfBSTR1, "All"
  AskMsgBox = MsgBox("Whould you like to do once more?", vbYesNo, "Question")
Loop
 
ok sorry for that. my code works fine for me:
Code:
Do While AskMsgBox [COLOR=#EF2929] <>[/color] vbNo

    Dim arrayOfVariantOfBSTR1(0)
    arrayOfVariantOfBSTR1(0) = "C:\temp\Part1.CATPart"
    products1.AddComponentsFromFiles arrayOfVariantOfBSTR1, "All"
    
    AskMsgBox = MsgBox("Whould you like to do once more?", vbYesNo, "Question")
Loop

ok now with VBScript:

I change your code to

Code:
Sub CATMain()

	Set productDocument1 = CATIA.ActiveDocument
	Set product1 = productDocument1.Product
	Set products1 = product1.Products

	Dim arrayOfVariantOfBSTR1(0)
	arrayOfVariantOfBSTR1(0) = "C:\temp\Part1.CATPart"

	Do While AskMsgBox <> vbNo
    		products1.AddComponentsFromFiles arrayOfVariantOfBSTR1, "All"
    		AskMsgBox = MsgBox("Whould you like to do once more?", vbYesNo, "Question")
	Loop

End Sub

and it works. you see the added files only after you reply No.

Eric N.
indocti discant et ament meminisse periti
 
Thanks a lot for your fast answer!!
Perfectly this works what I want. Now I can work!! ㅜ.ㅜ
I hope everything are going well with you!!
 
Status
Not open for further replies.
Back
Top