Attribute VB_Name = "modImportACad"
Public FileACad As String
Public FileACadN As Integer
Public ACadXRef As String
Public ACadYRef As String
Public FileACadInit As Integer

Public Type RecordACad
    ACadIndex As String
    ACadXProbeA As String
    ACadYProbeA As String
    ACadXProbeB As String
    ACadYProbeB As String
    ACadXStart As String
    ACadYStart As String
End Type

Public Function ACadFileOpen() As Integer
    On Error GoTo ErrOpenACAD
    ACadFileOpen = 0
    '0 = NessunErrore
    '1 = File Non Trovato o Errore Apertura File
    '2 = Linea Riferimento Non Trovata
    '3 = Errore Coordinata Asse X
    '4 = Errore Coordinata Asse Y
    
    Dim TmpInputString As String
    Dim TmpInputChr As Integer
    Dim TmpInputIndex As String
    
    FileACadN = FreeFile
    Open FileACad For Input Lock Read As #FileACadN
    If Not EOF(FileACadN) Then
        Line Input #FileACadN, TmpInputString
        TmpInputChr = InStr(1, TmpInputString, ";")
        If TmpInputChr <> 0 Then
            TmpInputIndex = Left(TmpInputString, TmpInputChr - 1)
            If TmpInputIndex = 0 Then
                TmpInputString = Right(TmpInputString, Len(TmpInputString) - TmpInputChr)
                TmpInputString = Left(TmpInputString, Len(TmpInputString) - 1)
                TmpInputChr = InStr(1, TmpInputString, ";")
                ACadXRef = Left(TmpInputString, TmpInputChr - 1)
                ACadYRef = Right(TmpInputString, TmpInputChr - 1)
                If ACadXRef = 0 Then
                    ACadFileOpen = 3
                    Exit Function
                End If
                If ACadYRef = 0 Then
                    ACadFileOpen = 4
                    Exit Function
                End If
            Else
                ACadFileOpen = 2
                Exit Function
            End If
        Else
            ACadFileOpen = 2
            Exit Function
        End If
    Else
        ACadFileOpen = 1
        Exit Function
    End If
    FileACadInit = 1
    Close #FileACadN
    Exit Function
    
ErrOpenACAD:
    ACadFileOpen = 1
    MsgBox "Errore", vbOKOnly
End Function

Public Function ACadRecordImport(ACadRec As Integer) As RecordACad
    Dim TmpRecImp As String
    Dim TmpRecImpChr As Integer
    Dim TmpIIIRecImp As Integer
    
    ACadRecordImport.ACadIndex = ""
    ACadRecordImport.ACadXProbeA = ""
    ACadRecordImport.ACadXProbeB = ""
    ACadRecordImport.ACadXStart = ""
    ACadRecordImport.ACadYProbeA = ""
    ACadRecordImport.ACadYProbeB = ""
    ACadRecordImport.ACadYStart = ""
    
    If ACadRec = 0 Then Exit Function
    
    FileACadN = FreeFile
    Open FileACad For Input Lock Read As #FileACadN
    
    Do While Not EOF(FileACadN)
        Line Input #FileACadN, TmpRecImp
        If TmpRecImp <> "" Then
            TmpRecImpChr = InStr(1, TmpRecImp, ";")
            ACadRecordImport.ACadIndex = Left(TmpRecImp, TmpRecImpChr - 1)
            If Val(ACadRecordImport.ACadIndex) = ACadRec Then
                TmpRecImpChr = InStr(1, TmpRecImp, ";")
                TmpRecImp = Right(TmpRecImp, Len(TmpRecImp) - TmpRecImpChr)
                For TmpIIIRecImp = 1 To 6
                    Select Case TmpIIIRecImp
                        Case 1
                            TmpRecImpChr = InStr(1, TmpRecImp, ";")
                            ACadRecordImport.ACadXProbeA = Left(TmpRecImp, TmpRecImpChr - 1)
                            TmpRecImp = Right(TmpRecImp, Len(TmpRecImp) - TmpRecImpChr)
                        Case 2
                            TmpRecImpChr = InStr(1, TmpRecImp, ";")
                            ACadRecordImport.ACadYProbeA = Left(TmpRecImp, TmpRecImpChr - 1)
                            TmpRecImp = Right(TmpRecImp, Len(TmpRecImp) - TmpRecImpChr)
                        Case 3
                            TmpRecImpChr = InStr(1, TmpRecImp, ";")
                            ACadRecordImport.ACadXProbeB = Left(TmpRecImp, TmpRecImpChr - 1)
                            TmpRecImp = Right(TmpRecImp, Len(TmpRecImp) - TmpRecImpChr)
                        Case 4
                            TmpRecImpChr = InStr(1, TmpRecImp, ";")
                            ACadRecordImport.ACadYProbeB = Left(TmpRecImp, TmpRecImpChr - 1)
                            TmpRecImp = Right(TmpRecImp, Len(TmpRecImp) - TmpRecImpChr)
                        Case 5
                            TmpRecImpChr = InStr(1, TmpRecImp, ";")
                            ACadRecordImport.ACadXStart = Left(TmpRecImp, TmpRecImpChr - 1)
                            TmpRecImp = Right(TmpRecImp, Len(TmpRecImp) - TmpRecImpChr)
                        Case 6
                            TmpRecImpChr = InStr(1, TmpRecImp, ";")
                            ACadRecordImport.ACadYStart = Left(TmpRecImp, TmpRecImpChr - 1)
                            TmpRecImp = Right(TmpRecImp, Len(TmpRecImp) - TmpRecImpChr)
                    End Select
                Next TmpIIIRecImp
            End If
        End If
    Loop
    Close #FileACadN
End Function
