' **************************************************************************
' Output definitions - Lotus/123 compatible DIF file (XXXXXX.DIF)
' XXXXXX.DIF  (XXXXXX=Disk Pack Serial Number) is created by this program.
' XXXXXX.DIF is translated to LOTUS/123 .WK3 format by the LOTUS Translate
' application.
' XXXXXX.WK3 is then loaded into LOTUS/123 for sorting and graphing.
' Sorted output is printed as a report by LOTUS/123.
' Graph output is imported into AmiPro for use in the VTOC report document.
' **************************************************************************
Global DifName As String
Global DifRec() As Variant
Global Const DIFDIR = "C:\123W\"    'Directory for DIF file
Global Const QT = """"          'Double quote
Global Const TTBL = "TABLE"     'Tables entry
Global Const TTBLS = "0,1"      'Number of tables
Global Const TCOL = "VECTORS"   'Columns entry
Global Const TCOLS = "0,11"     'Number of columns
Global Const TROW = "TUPLES"    'Rows entry
Global Const TROWS = "0,"       'Number of rows
Global Const DESC = "DATA"      'Data descriptor header
Global Const DESCS = "0,0"      'Data descriptor
Global Const HOME = "-1,0"      'Next row (1)
Global Const BOT = "BOT"        'Beginning of row (2)
Global Const EOD = "EOD"        'End of data
Global Const DATAF = "1,0"      'Data field delimiter
Global Const VALUF = "0,"       'Value field begin delimiter
Global Const V = "V"            'Value field end delimiter
Global Const C1 = "Label"       'Column labels for 123
Global Const C2 = "Date"
Global Const C3 = "Type"
Global Const C4 = "RecLen"
Global Const C5 = "Used"
Global Const C6 = "Avail"
Global Const C7 = "KeyP"
Global Const C8 = "KeyL"
Global Const C9 = "Records"
Global Const C10 = "Blocks"
Global Const C11 = "BlockNo"
Global Const COLS = 11

' **************************************************************************
' Subroutine to write .DIF format files.  Note that DifRec() array is
' dimensioned with three dimensions:
'  Dimension 1 is sized to accomodate the number of input lines read
'    from the source file being translated to .DIF format
'  Dimension 2 is sized to contain the number of spreadsheet columns.
'  Dimension 3 contains two fields:
'    Field 1 contains the string delimiter that defines the beginning
'    of a text or number field.
'    Field 2 contains the delimiter for the end of the text of number field.
' **************************************************************************

Sub Write_DIF ()
    Dim i As Integer, j As Integer, k As Integer
    Dim DIFfile As String
    Dim Entry As Variant
    ReDim DifRec(VTOCIndx, COLS, 1)
    DifRec(0, 0, 0) = HOME          'DifRec(0) contains table definitions
    DifRec(0, 0, 1) = BOT           'and column headings.
    DifRec(0, 1, 0) = DATAF
    DifRec(0, 1, 1) = QT & C1 & QT
    DifRec(0, 2, 0) = DATAF
    DifRec(0, 2, 1) = QT & C2 & QT
    DifRec(0, 3, 0) = DATAF
    DifRec(0, 3, 1) = QT & C3 & QT
    DifRec(0, 4, 0) = DATAF
    DifRec(0, 4, 1) = QT & C4 & QT
    DifRec(0, 5, 0) = DATAF
    DifRec(0, 5, 1) = QT & C5 & QT
    DifRec(0, 6, 0) = DATAF
    DifRec(0, 6, 1) = QT & C6 & QT
    DifRec(0, 7, 0) = DATAF
    DifRec(0, 7, 1) = QT & C7 & QT
    DifRec(0, 8, 0) = DATAF
    DifRec(0, 8, 1) = QT & C8 & QT
    DifRec(0, 9, 0) = DATAF
    DifRec(0, 9, 1) = QT & C9 & QT
    DifRec(0, 10, 0) = DATAF
    DifRec(0, 10, 1) = QT & C10 & QT
    DifRec(0, 11, 0) = DATAF
    DifRec(0, 11, 1) = QT & C11 & AT
    For i = 1 To VTOCIndx           'DifRec(1 to end) contain actual data.
        DifRec(i, 0, 0) = HOME
        DifRec(i, 0, 1) = BOT
        For j = 1 To COLS
            Entry = VTOCArray(i, j)
            If IsNumeric(Entry) Then
                DifRec(i, j, 0) = VALUF & Entry
                DifRec(i, j, 1) = V
            Else
                DifRec(i, j, 0) = DATAF
                DifRec(i, j, 1) = QT & Entry & QT
            End If
        Next j
    Next i
    i = InStr(DifName, ".")
    DIFfile = DIFDIR & Left$(DifName, i - 1) & "." & "DIF"
    FNum = FreeFile
    Open DIFfile For Output As FNum
    Print #FNum, TTBL
    Print #FNum, TTBLS
    Print #FNum, QT & QT
    Print #FNum, TCOL
    Print #FNum, TCOLS
    Print #FNum, QT & QT
    Print #FNum, TROW
    Print #FNum, TROWS & VTOCIndx + 1
    Print #FNum, QT & QT
    Print #FNum, DESC
    Print #FNum, DESCS
    Print #FNum, QT & QT
    For i = 0 To VTOCIndx
        For j = 0 To COLS
            For k = 0 To 1
                Print #FNum, DifRec(i, j, k)
            Next k
        Next j
    Next i
    Print #FNum, HOME
    Print #FNum, EOD
    Close #FNum
End Sub
