hexagon logo

VB code/ If a program is running

Does anyone know what code would be used to find out if a program is currently running in PC-Dmis? I wrote some code to automate the execution process and if I use it while a program is running, it closes the program and opens the new program while the original program continues to run. (Not sure for how long though. I stopped it after I tested it.)
Parents


  • I updated my code to remove Global variables and pass arguments instead. I also added some extra functionality so that it can totally replace all shortcuts for the operator and they can use only my program and I used some code suggested here. I still hit the same road block as before though. The event handler is giving me trouble. I found some code in a repository that does exactly what I need. It works perfect in excel but when I transfer it to visual studio, it only opens PC-Dmis. This is the excel code...

    Dim PCDApp As PCDLRN.Application
    Dim WithEvents AppEvents As PCDLRN.ApplicationObjectEvents
    Sub Start()
        HideExcel
    End Sub
    Private Sub HideExcel()
        Dim intAnswer As Integer
        intAnswer = MsgBox("Do you want to make Excel invisible? For this test, you should click Yes. It will become visible when you open a part program.", vbYesNo, "Hide Excel?")
    
        If intAnswer = vbYes Then
            Application.Visible = False
        Else
            Application.Visible = True
        End If
    
        LaunchPCDMIS
    
    End Sub
    Sub LaunchPCDMIS()
        Set PCDApp = CreateObject("PCDLRN.Application")
        Set AppEvents = PCDApp.ApplicationEvents
        PCDApp.Visible = True
    End Sub
    Private Sub AppEvents_OnOpenPartProgram(ByVal PartProg As PCDLRN.IPartProgram)
        ' Event subroutine. This activates when you OPEN a part program.
        Set PartProg = PCDApp.ActivePartProgram
        Application.Visible = True
        MsgBox "Part Program " & PartProg.Name & " opened. Excel should also be visible."
    End Sub
    Private Sub AppEvents_OnStartExecution(ByVal PartProg As PCDLRN.IPartProgram)
        ' Event subroutine. This activates when you START EXECUTION of the part program.
        MsgBox "STARTING EXECUTION OF " & PartProg.Name & ". Click OK to continue."
    End Sub
    Private Sub AppEvents_OnEndExecution(ByVal PartProg As PCDLRN.IPartProgram, ByVal TerminationType As Long)
        ' Event subroutine. This activates when you END EXECUTION of the part program.
        MsgBox "ENDING EXECUTION OF " & PartProg.Name & ". Click OK to continue."
    End Sub


    I've tried to remove the excel portion of this and launch LaunchPCDMIS through a button and it doesn't work. Does anyone have any advice on how to update this code to be current? FYI, I removed the "Set" before every variable and surrounded the MsgBox with ()
    My end goal here is when PC-Dmis starts running a program it will disable the buttons on my form so someone can't open something over top the running program and when the execution ends it enables the buttons. If I can only get the event handler to work I could get the rest done.
    Thanks again for your help guys
Reply


  • I updated my code to remove Global variables and pass arguments instead. I also added some extra functionality so that it can totally replace all shortcuts for the operator and they can use only my program and I used some code suggested here. I still hit the same road block as before though. The event handler is giving me trouble. I found some code in a repository that does exactly what I need. It works perfect in excel but when I transfer it to visual studio, it only opens PC-Dmis. This is the excel code...

    Dim PCDApp As PCDLRN.Application
    Dim WithEvents AppEvents As PCDLRN.ApplicationObjectEvents
    Sub Start()
        HideExcel
    End Sub
    Private Sub HideExcel()
        Dim intAnswer As Integer
        intAnswer = MsgBox("Do you want to make Excel invisible? For this test, you should click Yes. It will become visible when you open a part program.", vbYesNo, "Hide Excel?")
    
        If intAnswer = vbYes Then
            Application.Visible = False
        Else
            Application.Visible = True
        End If
    
        LaunchPCDMIS
    
    End Sub
    Sub LaunchPCDMIS()
        Set PCDApp = CreateObject("PCDLRN.Application")
        Set AppEvents = PCDApp.ApplicationEvents
        PCDApp.Visible = True
    End Sub
    Private Sub AppEvents_OnOpenPartProgram(ByVal PartProg As PCDLRN.IPartProgram)
        ' Event subroutine. This activates when you OPEN a part program.
        Set PartProg = PCDApp.ActivePartProgram
        Application.Visible = True
        MsgBox "Part Program " & PartProg.Name & " opened. Excel should also be visible."
    End Sub
    Private Sub AppEvents_OnStartExecution(ByVal PartProg As PCDLRN.IPartProgram)
        ' Event subroutine. This activates when you START EXECUTION of the part program.
        MsgBox "STARTING EXECUTION OF " & PartProg.Name & ". Click OK to continue."
    End Sub
    Private Sub AppEvents_OnEndExecution(ByVal PartProg As PCDLRN.IPartProgram, ByVal TerminationType As Long)
        ' Event subroutine. This activates when you END EXECUTION of the part program.
        MsgBox "ENDING EXECUTION OF " & PartProg.Name & ". Click OK to continue."
    End Sub


    I've tried to remove the excel portion of this and launch LaunchPCDMIS through a button and it doesn't work. Does anyone have any advice on how to update this code to be current? FYI, I removed the "Set" before every variable and surrounded the MsgBox with ()
    My end goal here is when PC-Dmis starts running a program it will disable the buttons on my form so someone can't open something over top the running program and when the execution ends it enables the buttons. If I can only get the event handler to work I could get the rest done.
    Thanks again for your help guys
Children
No Data