Note: The header in this sample script is the minimum required and can be used for all delivery types.
Const NULLCHARACTER = Chr$(0)
Const CRLF = Chr$(13) + Chr$(10)
Const QUOTE = Chr$(34)
Const DOCUMENTDELIVERYVERSION = "101"
Sub OnMouseUp(x As Long, y As Long, flags As Long)
'Set up the destination file name.
'Format Bottlingyyyymmdd.txt
Dim destinationFileName as string
destinationFileName = "Bottling"
Dim currentDate As Date
currentDate = Date
destinationFileName = destinationFileName + format( currentDate, "yyyy" )
destinationFileName = destinationFileName + format( currentDate, "mm" )
destinationFileName = destinationFileName + format( currentDate, "dd" )
destinationFileName = destinationFileName + ".txt"
'Set up the required Document Delivery Header
dim DocumentDeliveryHeader as string
DocumentDeliveryHeader = DOCUMENTDELIVERYVERSION
DocumentDeliveryHeader = DocumentDeliveryHeader + NULLCHARACTER
‘ Now set up the XML Header
DocumentDeliveryHeader = DocumentDeliverHeader + "<Header>"
DocumentDeliveryHeader = DocumentDeliverHeader + "<DestinationFilename filename="
DocumentDeliveryHeader = DocumentDeliverHeader + QUOTE + destinationFileName + QUOTE
DocumentDeliveryHeader = DocumentDeliverHeader + "/>"
DocumentDeliveryHeader = DocumentDeliverHeader + "</Header>"
DocumentDeliveryHeader = DocumentDeliveryHeader + NULLCHARACTER + CRLF
'Start the content string
Dim documentContent as string
'Total Bottles
Dim totalBottles As New point
totalBottles.Id ="\\NORTH1\TOTALBOTTLES"
totalBottles.Get
documentContent = "Total Bottles = " + cstr( totalBottles.Value )
documentContent = documentContent + CRLF
'Bottles Failed
Dim bottlesFailed As New point
bottlesFailed.Id ="\\NORTH1\BOTTLESFAILED"
bottlesFailed.Get
documentContent = documentContent + "Bottles Failed = " + cstr( bottlesFailed.Value )
documentContent = documentContent + CRLF
'Gripper Errors
Dim gripperErrors As New point
gripperErrors.Id ="\\NORTH1\GRIPPERERRORS"
gripperErrors.Get
documentContent = documentContent + "Gripper Errors = " + cstr( gripperErrors.Value )
documentContent = documentContent + CRLF
'Gate Open Errors
Dim gateOpenErrors As New point
gateOpenErrors.Id ="\\NORTH1\GATEOPENERRORS"
gateOpenErrors.Get
documentContent = documentContent + "Gate Open Errors = " + cstr( gateOpenErrors.Value )
documentContent = documentContent + CRLF
'No Box Errors
Dim noBoxErrors As New point
noBoxErrors.Id ="\\NORTH1\NOBOXERRORS"
noBoxErrors.Get
documentContent = documentContent + "No Box Errors = " + cstr( noBoxErrors.Value )
documentContent = documentContent + CRLF
'Boxes Processed
Dim boxesProcessed As New point
boxesProcessed.Id ="\\NORTH1\BOXESPROCESSED"
boxesProcessed.Get
documentContent = documentContent + "Boxes Processed = " + cstr( boxesProcessed.Value )
documentContent = documentContent + CRLF
'A unique Filename is required for Document Delivery
dim outputDocument as string
outputDocument = "MYDelivery"
Dim uniqueIndex As New Point
uniqueIndex.Id ="\\NORTH1\MYDELIVERYINDEX"
uniqueIndex.Get
outputDocument = outputDocument + cstr(uniqueIndex.value)
'Increment the index for the next usage
uniqueIndex.value = uniqueIndex.value + 1
uniqueIndex.set
'Write to a temporary file
Dim temporaryFilename As String
temporaryFilename = "c:\" + outputDocument
Open temporaryFilename For Output Access Write Lock Read Write As #1
Print #1, DocumentDeliveryHeader
Print #1, documentContent
Close #1
'Copy the file to the correct directory
Dim root As String
root = Environ( "SITE_ROOT" )
Dim finalDestination As String
finalDestination = root + "\DocumentDelivery\MyDelivery\" + outputDocument
FileCopy temporaryFilename, finalDestination
'Delete the temporary file
Kill temporaryFilename
End Sub
Document Delivery technical notes. |