Partprograms.open scripting error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Partprograms.open scripting error

    Ok so I have stolen some code from here on using a script to open a program and run it, then closes the program. It runs and works perfectly... UNTIL I try to make the filepath variable, such as ("C:\Users\Public\Desktop" + strID ) so that I can use a barcode scanner to input the last bit of filepath into the script and execute that way. I keep getting an error message on the PCDpartprogams.open line stating "wrong number of dimensions". Any ideas?


    Originally posted by vpt.se View Post
    Found this in my repository...


    Code:
    Dim PCDApp, PCDPartPrograms, PCDPartProgram
    
    Set PCDApp = CreateObject("PCDLRN.Application")
    Set PCDPartPrograms = PCDApp.PartPrograms
    
    PCDApp.Visible = True
    PCDPartPrograms.Open "Z:\test1.PRG", "CMM1"
    
    Set PCDPartProgram = PCDApp.ActivePartProgram
    
    'msgbox "This will start the execution of the partprogram!"
    PCDPartProgram.Execute
    
    ' PC-DMIS executes the partprogram
    
    PCDPartProgram.Close
    
    ' PC-DMIS closes and saves the partprogram
    
    PCDPartPrograms.Open "Z:\test2.PRG", "CMM1"
    
    Set PCDPartProgram = PCDApp.ActivePartProgram
    
    'msgbox "This will start the execution of the partprogram!"
    PCDPartProgram.Execute
    
    ' PC-DMIS executes the partprogram
    
    PCDPartProgram.Close
    
    ' PC-DMIS closes and saves the partprogram
    
    ' Cleanup
    Set PCDPartProgram = nothing
    Set PCDPartPrograms = nothing
    Set PCDApp = nothing


    This should (in theory) open "test1.prg", execute it, close and save and then open "test2.prg", execute it, close and save.

  • #2
    FYI I have confirmed via msgbox that the "filepath" + strID does produce the correct program filepath and ends in .PRG

    Comment


    • #3
      Have you confirmed that your line of code reads "PCDPartPrograms.Open var1, "CMM1"" exactly, where var1 is the filepath string?

      You are using PCDPartPrograms instead of PCDPartProgram?
      You are including the "CMM1" at the end?

      Comment


      • #4
        The code is as follows.

        Code:
        Sub main(strID As String)
        Dim PCDApp, PCDPartPrograms, PCDPartProgram
        
        Set PCDApp = CreateObject("PCDLRN.Application")
        Set PCDPartPrograms = PCDApp.PartPrograms
        Dim Fpath As String
        Fpath= "L:\CUSTOM_GLOBAL_PROGRAMS_\" + strID
        
        MsgBox Fpath
        'MsgBox To verify filepath is correct
        PCDApp.Visible = True
        PCDPartPrograms.Open Fpath, "CMM1"
        
        Set PCDPartProgram = PCDApp.ActivePartProgram
        
        'MsgBox "This will start the execution of the partprogram!"
        PCDPartProgram.Execute
        
        ' PC-DMIS executes the partprogram
        
        PCDPartProgram.Close
        
        ' PC-DMIS closes And saves the partprogram
        
        'PCDPartPrograms.Open "Z:\test2.PRG", "CMM1"
        
        'Set PCDPartProgram = PCDApp.ActivePartProgram
        
        'MsgBox "This will start the execution of the partprogram!"
        'PCDPartProgram.Execute
        
        ' PC-DMIS executes the partprogram
        
        'PCDPartProgram.Close
        
        ' PC-DMIS closes And saves the partprogram
        
        ' Cleanup
        Set PCDPartProgram = Nothing
        Set PCDPartPrograms = Nothing
        Set PCDApp = Nothing
        End Sub

        Comment


        • #5
          What does the MessageBox command return?


          Fpath= "L:\CUSTOM_GLOBAL_PROGRAMS_" + strID

          I wonder if the concatenation is putting an extra space in the string? If so, it would be interpreted as two separate arguments. . . .

          You might need to parse it out before you use it.

          Comment


          • #6
            MSGBOX.png
            This is the msgbox result. I am assuming the text is wrapped due to a fixed box size?

            Comment


            • #7
              I vaguely recall having a similar incident. I had to split the strID variable into only having the name and adding + ".prg" into the assignment for my vbs to work.

              Edit: After looking at your msgbox, I'm thinking it might not like all the . in the file name. Could be misreading the extension. Try changing to _ and see if it works?
              Last edited by Sora5; 03-25-2021, 10:53 AM.

              Comment


              • #8
                It will run the program if the whole filepath is entered as shown from the msgbox. It will not run when it is "filepath" + strID and I just tried removing the . and got the same result.

                EDIT: even if I place the whole filepath as a variable and pass it into the script it does not work.
                Last edited by samus; 03-25-2021, 11:29 AM.

                Comment


                • #9
                  Just a guess - Try wrapping the filepath in a second set of quotation marks, or use a wrapping quotation with apostrophe marks like so " ' Test ' + strID "

                  Comment


                  • #10
                    just a question how are you executing the script? If inside pcdmis the first PRG loaded will be connected to the machine by default (assuming you are online). All others will be offline. Nt sure if this matters or not as I don't run many scripts.

                    Maybe attach some the code making the script call?
                    PCDMIS version?

                    Comment


                    • #11
                      OK... so it wont work with the
                      "Sub main (strID as string)

                      End Sub"

                      as this was not part of the original code

                      but I am unsure of how to pass the variable without the Sub / End sub?

                      Comment


                      • #12
                        OK, so I finally figured it out, it works if a add "PCDApp." in front of the "PartsPrograms.Open" ".Execute", and ".Close"

                        Code:
                        Sub main (strID As String)
                        MsgBox strID
                        Dim Fpath As String
                        Dim PCDApp, PCDPartPrograms, PCDPartProgram
                        Set PCDApp = CreateObject("PCDLRN.Application")
                        Set PCDPartPrograms = PCDApp.PartPrograms
                        Fpath = strID
                        MsgBox Fpath
                        PCDApp.Visible = True
                        With PCDAPartPrograms
                        PCDApp.PartPrograms.Open Fpath, "CMM1"
                        
                        Set PCDPartProgram = PCDApp.ActivePartProgram
                        End With
                        
                        'MsgBox "This will start the execution of the partprogram!"
                        PCDApp.ActivePartProgram.Execute
                        
                        ' PC-DMIS executes the partprogram
                        
                        PCDApp.ActivePartProgram.Close
                        
                        ' PC-DMIS closes And saves the partprogram
                        
                        'PCDPartPrograms.Open "Z:\test2.PRG", "CMM1"
                        
                        'Set PCDPartProgram = PCDApp.ActivePartProgram
                        
                        'MsgBox "This will start the execution of the partprogram!"
                        ' PCDPartProgram.Execute
                        
                        ' PC-DMIS executes the partprogram
                        
                        ' PCDPartProgram.Close
                        
                        ' PC-DMIS closes And saves the partprogram
                        
                        ' Cleanup
                        Set PCDPartProgram = Nothing
                        Set PCDPartPrograms = Nothing
                        Set PCDApp = Nothing
                        End Sub
                        Thanks for all the help guys!

                        Comment


                        • SABarber
                          SABarber commented
                          Editing a comment
                          Nice. Thanks for the update.

                      Related Topics

                      Collapse

                      Working...
                      X