Attribute VB_Name = "Modulo1"
DefInt A-Z
Type Port
    Nome    As String * 3
    prog    As Byte
    Colore  As Byte
End Type
Public NomeFile     As String
Public NomeFileOut  As String
Public Dati()       As String
Public Porta(42)    As Byte
Public Porte()      As Port
Public Porte2()     As Port
Public Puntatore    As Byte
Public NumPorte     As Integer
Public NumDat       As Integer
Public Titolo       As String

'  Comandi da passare a WinHelp()
Public HelpPath As String           'Posizione del file di Help


Public Function SoloNome$(Nome$)
For X = Len(Nome$) To 1 Step -1
    If Mid(Nome$, X, 1) = "\" Then Exit For
Next
If X = 1 Then
    SoloNome$ = Nome$
Else
    SoloNome$ = Mid(Nome$, X + 1)
End If
End Function


Public Sub Apri()
FPro.VScroll1.Visible = True
NumPorte = -1
NumDat = 0
For i = 0 To 7
    FPro.Text1(i).Text = ""
    FPro.Text2(i).Text = ""
Next
Tx$ = UCase(Right(NomeFile, 3))
FPro.Label3(0).Caption = Tx$
Titolo = "Conversione " + Tx$ + " -> CMD"
FPro.Caption = Titolo
For i = 0 To 42
    Porta(i) = 0
Next
Erase Porte
Open NomeFile For Input As #1
i = 0
While Not EOF(1)
    ReDim Preserve Dati(i) As String
    Input #1, Rec$
    If Len(Rec$) > 8 Then
        Mid(Rec$, 5, 1) = "I"
        Dati(i) = Rec$
        Rec$ = Left(Rec$, 3)     'solo porta
        GoSub LeggiPorta
        If Porta(Num) = 0 Then
            NumPorte = NumPorte + 1
            Porta(Num) = 1
            ReDim Preserve Porte(NumPorte) As Port
            Porte(NumPorte).Nome = Rec$
            Porte(NumPorte).prog = Num
        End If
        i = i + 1
    End If
Wend
Close
If NumPorte >= 0 Then
    ReDim Porte2(NumPorte) As Port
    NumDat = i - 1
    FPro.Label2.Caption = SoloNome(NomeFile)
    If NumPorte > 7 Then
        FPro.VScroll1.Visible = True
        FPro.VScroll1.Max = NumPorte - 7
    Else
        FPro.VScroll1.Visible = False
    End If
    Puntatore = 0
    j = 0
    For i = 0 To 7
        If i <= NumPorte Then
            FPro.Text1(i).Text = Porte(i).Nome
            FPro.Text1(i).Enabled = True
        Else
            FPro.Text1(i).Enabled = False
        End If
    Next
    'FPro.Frame1.Visible = True
    FPro.FileItem(1).Enabled = True
Else
    Beep
    MsgBox "File Non valido", 16
End If
Exit Sub
LeggiPorta:
Select Case Rec$
    Case "TIM": Num = 40
    Case "NMI": Num = 41
    Case "RES": Num = 42
    Case Else
        Num = (Asc(Mid(Rec$, 2, 1)) - 65) * 8
        Num = Num + Val(Mid(Rec$, 3, 1))
End Select
Return


End Sub


Public Sub Salva()
Open NomeFileOut For Output As 1
For i = 0 To NumPorte
    Port$ = Porte(i).Nome
    Port2$ = Trim(Porte2(i).Nome)
    a$ = Left(Port2$, 1)
    If a$ = "P" Or a$ = "N" Or a$ = "R" Or a$ = "T" Then
        For z = 0 To NumDat
            Rec$ = Dati(z)
            If Mid(Rec$, 1, 3) = Port$ Then
                Mid(Rec$, 1, 3) = Port2$
                'Toglie Tempo totale
                ii = 1
                For j = 1 To 4
                    jj = InStr(ii, Rec$, " ")
                    If jj = 0 Then      'Finiti gli spaszi
                        jj = Len(Rec$) + 1
                        Exit For
                    End If
                    ii = jj + 1
                Next
                Rec$ = Left(Rec$, jj - 1)
                Print #1, Rec$
            End If
        Next
    End If
Next
Close
MsgBox "   Il File e' Stato salvato   ", 0
End Sub

Public Sub Riscrivi()
Incremento = -1
If FPro.VScroll1.Value > Puntatore Then
    Incremento = 1
End If
Puntatore = Puntatore + Incremento
For i = 0 To 7
    FPro.Text1(i).Text = Porte(Puntatore + i).Nome
    FPro.Text2(i).Text = Porte2(Puntatore + i).Nome
    If Porte(Puntatore + i).Colore Then
        FPro.Text1(i).BackColor = QBColor(14)
        'FPro.Text2(i).SetFocus
    Else
        FPro.Text1(i).BackColor = QBColor(15)
    End If
Next
End Sub
