×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

VBScript Existing Component Loop Problems

VBScript Existing Component Loop Problems

VBScript Existing Component Loop Problems

(OP)
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 --> VBSCript

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 

RE: VBScript Existing Component Loop Problems

try:

CODE --> vba

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

Eric N.
indocti discant et ament meminisse periti

RE: VBScript Existing Component Loop Problems

(OP)
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 --> VBScript

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 --> VBScript

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 

RE: VBScript Existing Component Loop Problems

ok sorry for that. my code works fine for me:

CODE --> CATVBA

Do While AskMsgBox  <> 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 --> CATScript

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

RE: VBScript Existing Component Loop Problems

(OP)
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!!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources