  Sub Main()

NewTool = GetSelectedTool()
OldTool = GetCurrentTool()
MaxToolNum = 4 'Max number of tools for the changer

While NewTool > MaxToolNum
NewTool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend

If NewTool = OldTool Or NewTool = 0 Then
Exit Sub
End If

If OldTool <> NewTool Then

'This section of code will turn on the correct tool number output to the input
'you need on the PLC.

If (NewTool = 1) Then
deActivateSignal(10) 'this output goes from Mach to your PLC input 1
deActivateSignal(11)
ActivateSignal(12)
End If

If (NewTool = 2) Then
deActivateSignal(10) 'this output goes from Mach to your PLC input 2
ActivateSignal(11)
ActivateSignal(12)
End If

If (NewTool = 3) Then
ActivateSignal(10) 'this output goes from Mach to your PLC input 3
deActivateSignal(11)
ActivateSignal(12)
End If

If (NewTool = 4) Then
ActivateSignal(10) 'this output goes from Mach to your PLC input 4
ActivateSignal(11)
ActivateSignal(12)
End If


End If

SetOEMDRO(824,NewTool)
Code "G4 P4" 'A pause time of 4 seconds to give your turret time to index
While IsMoving
Wend

'This section of code Turns the Output from Mach off after your turret
'has indexed to the new position.


DeActivateSignal(12) 'this output goes from Mach to your PLC input 1
End If


End Sub
Main
