I'm back on this project, see what we can do today. Thanks for all the input.
When an operator prints from their database, it creates a file, either in a manual or auto folder. My main program then opens it and sends it to this proprietary Linx 6800 printer. If they choose Manual, there is a form that gives them more options, but the final send is the same as the auto module.
The main reason that I'm needing to do 2 applications is because this industrial jet printer only comes with VB code, which is only working once. If I close and re-load again when needed, it works fine.
So here's the small app that will always be running. I put in the 1 second pause otherwise it had 100% CPU usage!
PRINTLINX.EXE :
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public AReady As Boolean, MReady As Boolean
Public AutoFile
Public ManFile
Public Sub Main()
Dim LinxAppID
Do
Pause 1
Dim fso As New FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
AutoFile = Dir("C:\auto\*.TXT")
AReady = fso.FileExists("c:\auto\" & AutoFile)
ManFile = Dir("C:\manual\*.TXT")
MReady = fso.FileExists("c:\manual\" & ManFile)
If ((AReady = True) Or (MReady = True)) Then
LinxAppID = Shell("C:\Program Files\Linx\Linx6800.EXE", 0)
Do While LinxAppID > 0
DoEvents ' Yield to other processes.
Loop
LinxAppID = 0
End If
Loop
End Sub
Private Sub Pause(iSecs As Integer)
' Makes the program sleep for 1 seconds
Dim i As Integer
For i = 1 To iSecs * 10
Sleep 100
DoEvents
Next
End Sub
HERE'S THE AUTO MODULE CODE FOR THE MAIN APP, THE ONE I NEED TO STOP :
Public AReady As Boolean, MReady As Boolean
Dim CodeLot As String, CodeColor As String, CodeGrade As String
Dim CodeProduct As String, CodeMessage As String
Public AutoFile
Public ManFile
Public PrinterObj As New LINX6800PRINTERLib.Simple6800Printer
Public fso As New FileSystemObject
Public bConnected As Boolean
Public Sub Main()
Dim TheContents As String
Dim PrintStuff As String
Dim FirstComma As Integer
Dim SecondComma As Integer
Dim FLength As Integer
Dim WinOpen As Integer
Dim Lot As String, Color As String, Grade As String
Dim Product As String, Message As String
Dim RemoteLot As String, RemoteColor As String, RemoteGrade As String
Dim RemoteProduct As String, RemoteMessage As String
WinOpen = 0
RemoteGrade = "Grade"
RemoteColor = "Color"
RemoteLot = "Lot"
RemoteProduct = "Product"
RemoteMessage = "Message"
Do
Set PrinterObj = New LINX6800PRINTERLib.Simple6800Printer
Set fso = CreateObject("Scripting.FileSystemObject")
AutoFile = Dir("C:\auto\*.TXT")
AReady = fso.FileExists("c:\auto\" & AutoFile)
If AReady = True Then
Open "c:\auto\" & AutoFile For Input As #1
FLength = LOF(1)
TheContents = Input$(FLength, 1): Close #1
PrintStuff = Mid(TheContents, 13, (FLength - 16))
FLength = FLength - 16
FirstComma = InStr(1, PrintStuff, ",")
SecondComma = InStr((FirstComma + 1), PrintStuff, ",")
CodeLot = Mid(PrintStuff, 1, (FirstComma - 1))
CodeGrade = Mid(PrintStuff, (FirstComma + 1), (SecondComma - FirstComma - 1))
CodeColor = Mid(PrintStuff, (SecondComma + 1), (FLength - SecondComma))
CodeProduct = "ULTEM"
CodeMessage = "55#/25KG"
' Connect to remote device
' See if we are connected first, if so, disconnect
If bConnected = True Then
PrinterObj.Disconnect
bConnected = False
End If
' Now connect
bConnected = PrinterObj.InitComponent(RS232, "COM1")
' Register the Fields
CodeRegisterField RemoteGrade
CodeRegisterField RemoteColor
CodeRegisterField RemoteLot
CodeRegisterField RemoteProduct
CodeRegisterField RemoteMessage
'Send Field Data to Linx6800
CodeSendField RemoteGrade, CodeGrade
CodeSendField RemoteColor, CodeColor
CodeSendField RemoteLot, CodeLot
CodeSendField RemoteProduct, CodeProduct
CodeSendField RemoteMessage, CodeMessage
If bConnected = True Then
PrinterObj.Disconnect
End If
bConnected = False
Set PrinterObj = Nothing
'Kill "c:\auto\" & AutoFile
AutoFile.Delete
AutoFile = "X"
AReady = False
End If
ManFile = Dir("C:\manual\*.TXT")
MReady = fso.FileExists("c:\manual\" & ManFile)
If MReady = True Then
Open "c:\manual\" & ManFile For Input As #1
FLength = LOF(1)
TheContents = Input$(FLength, 1): Close #1
PrintStuff = Mid(TheContents, 13, (FLength - 16))
FLength = FLength - 16
FirstComma = InStr(1, PrintStuff, ",")
SecondComma = InStr((FirstComma + 1), PrintStuff, ",")
LinxForm.frmLot = Mid(PrintStuff, 1, (FirstComma - 1))
LinxForm.frmGrade = Mid(PrintStuff, (FirstComma + 1), (SecondComma - FirstComma - 1))
LinxForm.frmColor = Mid(PrintStuff, (SecondComma + 1), (FLength - SecondComma))
If WinOpen = 0 Then
LinxForm.Show
WinOpen = 1
Do While WinOpen = 1
DoEvents ' Yield to other processes.
Loop
End If
'ManFile.Delete
Kill "c:\manual\" & ManFile
ManFile = ""
MReady = False
End If
Loop Until ((AReady = False) And (MReady = False))
End
Stop
Unload linx6800.exe
End Sub
Private Sub CodeDisplay(Error As GPIError, TextType As String)
Dim ErrStr As String
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim sLogFile As String, sLogPath As String
Dim fso, f
If Error.Code = NoError Then
ErrStr = "Ok"
Else
Dim ErrCode As String
Dim DevErrCode As String
Dim DevErrString As String
ErrCode = Error.Code
DevErrCode = Error.DeviceErrorCode
DevErrString = Error.DeviceErrorString
ErrStr = TextType + ", GPI Code = " + ErrCode + ", Dev ErrCode = " + DevErrCode + ", " + DevErrString
'Set the path and filename of the log
sLogPath = App.Path & "\" & App.EXEName
sLogFile = sLogPath & ".log"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fs

penTextFile(sLogFile, ForAppending, True)
'Append the log-entry to the file together with time and date
f.WriteLine Now() & vbTab & ErrStr
End If
End Sub
Private Sub CodeRegisterField(FieldName As String)
Dim Error As GPIError, TextType As String
If FieldName = "" Then
'Do nothing
Else
Error = PrinterObj.PrepareRemoteField(FieldName)
If ((Error.Code <> NoError) And (FieldName = "Message")) Then
MsgBox "Error encountered, please retry.", vbExclamation, "RegisterField Error"
TextType = "RegisterField Error"
CodeDisplay Error, TextType
End If
End If
End Sub
Private Sub CodeSendField(FieldName As String, FieldText As String)
Dim Error As GPIError, TextType As String
If FieldName = "" Then
'Do Nothing
Else
Error = PrinterObj.SetRemoteField(FieldText, FieldName)
If ((Error.Code <> NoError) And (FieldName = "Message")) Then
MsgBox "Error encountered, please retry.", vbExclamation, "SendField Error"
TextType = "SendField Error"
CodeDisplay Error, TextType
End If
End If
End Sub