hexagon logo

Error executing basic script!

This is the error message I get when I try to run a script in my programs.  No line reference, just this error.  I've tried with more than one script, but this is all I get.  The scripts will compile in the edit window, but they won't run.  I'm new to using scripts, but I can't get past square one.  Any ideas what the problem could be?

Parents
  • Can you share the error message in a snapshot? Or perhaps share the script if you can. If you execute it from the script editing window does it give a line reference error?

  • My company firewall won't let me post pics on this board apparently, so I'll explain as best I can.  When I try to execute it from the edit window nothing happens.  When I insert it as a line of code and CTRL+U it, I get the error, which is those words exactly, and the file path below that. 

    I created this program containing a for loop and nothing else.  When I run it, I get the error.  However, when I remove the for loop, I don't get the error message.  Is there a different way to do it?  It seems like there's nothing to cause a problem.

    Sub test2
    Dim PCDApp As Object
    Dim PCDPartProgram As Object
    Dim PCDCommands As Object
    Dim PCDCommand As Object

    Set PCDApp = CreateObject("PCDLRN.Application")
    Set PCDPartProgram = PCDApp.ActivePartProgram
    Set PCDCommands = PCDPartProgram.Commands

    For Each PCDCommand In PCDCommands
    Next PCDCommand

    End Sub

     

  • Have you tried putting an Exit For at the end of the for loop?

    For Each cmd In PCDCommands
    
    If cmd.Type = 171 Then
    	
    	'do something
    	     
        End If
        Exit For
    
        Next cmd

  • I think I spoke too soon, now I'm getting the error again.  I don't know what the deal is.

  • This works for me. It's your script pasted into my program, I just added the MsgBox for testing and the Exit For

    Sub Main
    
    Dim PCDApp As Object
    Dim PCDPartProgram As Object
    Dim PCDCommands As Object
    Dim PCDCommand As Object
    
    Set PCDApp = CreateObject("PCDLRN.Application")
    Set PCDPartProgram = PCDApp.ActivePartProgram
    Set PCDCommands = PCDPartProgram.Commands
    
    For Each PCDCommand In PCDCommands
    MsgBox "Text"
    Exit For
    Next PCDCommand
    
    End Sub

  • I'll paste it in and give it a try, thanks a lot.  Side note, why is the Exit For necessary?  Doesn't that restrict it to only one iteration?

  • You are right, it does. I was about to correct myself here. I cannot tell why you were getting an error, BUT I have also gotten the same error as you before, and the error always went away when I deleted the For Each loop. I can't explain it. This works, but it's the same as your original program except for the MsgBox. To note I have had weird issues whenever I copy and paste into scripts as well. 

    Sub Main
    
    Dim PCDApp As Object
    Dim PCDPartProgram As Object
    Dim PCDCommands As Object
    Dim PCDCommand As Object
    
    Set PCDApp = CreateObject("PCDLRN.Application")
    Set PCDPartProgram = PCDApp.ActivePartProgram
    Set PCDCommands = PCDPartProgram.Commands
    
    For Each PCDCommand In PCDCommands
    MsgBox "Text"
    Next PCDCommand
    End Sub

Reply
  • You are right, it does. I was about to correct myself here. I cannot tell why you were getting an error, BUT I have also gotten the same error as you before, and the error always went away when I deleted the For Each loop. I can't explain it. This works, but it's the same as your original program except for the MsgBox. To note I have had weird issues whenever I copy and paste into scripts as well. 

    Sub Main
    
    Dim PCDApp As Object
    Dim PCDPartProgram As Object
    Dim PCDCommands As Object
    Dim PCDCommand As Object
    
    Set PCDApp = CreateObject("PCDLRN.Application")
    Set PCDPartProgram = PCDApp.ActivePartProgram
    Set PCDCommands = PCDPartProgram.Commands
    
    For Each PCDCommand In PCDCommands
    MsgBox "Text"
    Next PCDCommand
    End Sub

Children