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) [COLOR=#e74c3c]Hangles AppEvents.OnOpenPartProgram[/COLOR]
    ' 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) [COLOR=#e74c3c]Handles AppEvents.OnStartExecution[/COLOR]
    ' 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) [COLOR=#e74c3c]Handles AppEvents.OnEndExecution[/COLOR]
    ' 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


    Try this buddy.... on your Visual Studio VB.NET application.

    Here's my test...

    Imports PCDLRN
    Public Class Form1
    ' Globals
    Dim oPcd As Application = New Application()
    Dim WithEvents AppEvent As ApplicationObjectEvents
    
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim oPart As PartProgram = oPcd.ActivePartProgram
    AppEvent = oPcd.ApplicationEvents
    End Sub
    
    Private Sub AppEvents_OnOpenPartProgram(ByVal partProg As PartProgram) [COLOR=#e74c3c]Handles AppEvent.OnOpenPartProgram[/COLOR]
    partProg = oPcd.ActivePartProgram
    MsgBox("Part: " & partProg.Name & " opened.")
    End Sub
    End Class
    
    
    


    I even found this little guy: https://www.pcdmisforum.com/forum/pc...ual-basic-2008
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) [COLOR=#e74c3c]Hangles AppEvents.OnOpenPartProgram[/COLOR]
    ' 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) [COLOR=#e74c3c]Handles AppEvents.OnStartExecution[/COLOR]
    ' 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) [COLOR=#e74c3c]Handles AppEvents.OnEndExecution[/COLOR]
    ' 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


    Try this buddy.... on your Visual Studio VB.NET application.

    Here's my test...

    Imports PCDLRN
    Public Class Form1
    ' Globals
    Dim oPcd As Application = New Application()
    Dim WithEvents AppEvent As ApplicationObjectEvents
    
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim oPart As PartProgram = oPcd.ActivePartProgram
    AppEvent = oPcd.ApplicationEvents
    End Sub
    
    Private Sub AppEvents_OnOpenPartProgram(ByVal partProg As PartProgram) [COLOR=#e74c3c]Handles AppEvent.OnOpenPartProgram[/COLOR]
    partProg = oPcd.ActivePartProgram
    MsgBox("Part: " & partProg.Name & " opened.")
    End Sub
    End Class
    
    
    


    I even found this little guy: https://www.pcdmisforum.com/forum/pc...ual-basic-2008
Children
  • That makes complete sense! Going off of the code needed to activate button clicks...

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    All of the eventargs have it, so I think you fixed my problem! I will test this tonight but I'm confident this fixes it. If I could like on your post 5x I would right now.