VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "TABCTL32.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Object = "{65E121D4-0C60-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCHRT20.OCX"
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   7365
   ClientLeft      =   165
   ClientTop       =   855
   ClientWidth     =   9585
   LinkTopic       =   "Form1"
   ScaleHeight     =   7365
   ScaleWidth      =   9585
   StartUpPosition =   3  'Windows Default
   Begin MSComDlg.CommonDialog CD1 
      Left            =   7680
      Top             =   6600
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin TabDlg.SSTab SSTab1 
      Height          =   6375
      Left            =   120
      TabIndex        =   9
      Top             =   120
      Width           =   9405
      _ExtentX        =   16589
      _ExtentY        =   11245
      _Version        =   393216
      Tabs            =   2
      TabsPerRow      =   2
      TabHeight       =   520
      TabCaption(0)   =   "Manutenção de Contactos"
      TabPicture(0)   =   "Form1.frx":0000
      Tab(0).ControlEnabled=   -1  'True
      Tab(0).Control(0)=   "Frame1"
      Tab(0).Control(0).Enabled=   0   'False
      Tab(0).Control(1)=   "Command5"
      Tab(0).Control(1).Enabled=   0   'False
      Tab(0).ControlCount=   2
      TabCaption(1)   =   "Pesquisa"
      TabPicture(1)   =   "Form1.frx":001C
      Tab(1).ControlEnabled=   0   'False
      Tab(1).Control(0)=   "MSChart1"
      Tab(1).Control(1)=   "Command4"
      Tab(1).ControlCount=   2
      Begin VB.CommandButton Command5 
         Caption         =   "Gráfico"
         Height          =   495
         Left            =   8040
         TabIndex        =   36
         Top             =   5640
         Width           =   1215
      End
      Begin VB.CommandButton Command4 
         Caption         =   "Command4"
         Height          =   495
         Left            =   -67080
         TabIndex        =   33
         Top             =   480
         Width           =   1215
      End
      Begin VB.Frame Frame1 
         Caption         =   "Contacto nrº"
         Height          =   5775
         Left            =   360
         TabIndex        =   10
         Top             =   480
         Width           =   8655
         Begin VB.CommandButton Command1 
            Caption         =   "Adicionar"
            Height          =   375
            Left            =   5040
            TabIndex        =   32
            Top             =   3120
            Width           =   1215
         End
         Begin VB.CommandButton Command2 
            Caption         =   "Eliminar"
            Height          =   375
            Left            =   6360
            TabIndex        =   31
            Top             =   3120
            Width           =   1215
         End
         Begin VB.ListBox List1 
            Height          =   840
            Left            =   1680
            TabIndex        =   30
            Top             =   3600
            Width           =   4935
         End
         Begin VB.TextBox Text1 
            Height          =   285
            Index           =   0
            Left            =   1680
            TabIndex        =   19
            Top             =   600
            Width           =   5895
         End
         Begin VB.TextBox Text1 
            Height          =   285
            Index           =   1
            Left            =   1680
            TabIndex        =   18
            Top             =   1080
            Width           =   5895
         End
         Begin VB.TextBox Text1 
            Height          =   285
            Index           =   2
            Left            =   1680
            TabIndex        =   17
            Top             =   1560
            Width           =   975
         End
         Begin VB.TextBox Text1 
            Height          =   285
            Index           =   3
            Left            =   3840
            TabIndex        =   16
            Top             =   1560
            Width           =   3735
         End
         Begin VB.TextBox Text1 
            Height          =   285
            Index           =   4
            Left            =   3480
            TabIndex        =   15
            Top             =   1920
            Visible         =   0   'False
            Width           =   855
         End
         Begin VB.TextBox Text1 
            Height          =   285
            Index           =   5
            Left            =   4320
            TabIndex        =   14
            Top             =   2160
            Width           =   3255
         End
         Begin VB.TextBox Text1 
            Height          =   285
            Index           =   6
            Left            =   1680
            TabIndex        =   13
            Top             =   2760
            Width           =   5895
         End
         Begin VB.TextBox Text1 
            Height          =   285
            Index           =   7
            Left            =   1680
            TabIndex        =   12
            Top             =   3240
            Width           =   3255
         End
         Begin VB.TextBox Text1 
            Height          =   645
            Index           =   8
            Left            =   1320
            TabIndex        =   11
            Top             =   4920
            Width           =   6255
         End
         Begin MSComCtl2.DTPicker DTP1 
            Height          =   285
            Left            =   1920
            TabIndex        =   34
            Top             =   2160
            Width           =   1455
            _ExtentX        =   2566
            _ExtentY        =   503
            _Version        =   393216
            Format          =   20971521
            CurrentDate     =   39245
         End
         Begin VB.Label Label1 
            Appearance      =   0  'Flat
            BackColor       =   &H80000005&
            BorderStyle     =   1  'Fixed Single
            ForeColor       =   &H80000008&
            Height          =   255
            Left            =   1200
            TabIndex        =   29
            Top             =   0
            Width           =   855
         End
         Begin VB.Label Label2 
            Caption         =   "Nome:"
            Height          =   255
            Left            =   240
            TabIndex        =   28
            Top             =   600
            Width           =   735
         End
         Begin VB.Label Label3 
            Caption         =   "Morada"
            Height          =   255
            Left            =   240
            TabIndex        =   27
            Top             =   1080
            Width           =   735
         End
         Begin VB.Label Label4 
            Caption         =   "Cod Postal"
            Height          =   255
            Left            =   240
            TabIndex        =   26
            Top             =   1560
            Width           =   855
         End
         Begin VB.Label Label5 
            Caption         =   "Localidade"
            Height          =   255
            Left            =   2880
            TabIndex        =   25
            Top             =   1560
            Width           =   1215
         End
         Begin VB.Label Label6 
            Caption         =   "Data Nascimento"
            Height          =   375
            Left            =   240
            TabIndex        =   24
            Top             =   2160
            Width           =   1335
         End
         Begin VB.Label Label7 
            Caption         =   "Telefone"
            Height          =   255
            Left            =   3600
            TabIndex        =   23
            Top             =   2160
            Width           =   975
         End
         Begin VB.Label Label8 
            Caption         =   "Nick Msn"
            Height          =   375
            Left            =   240
            TabIndex        =   22
            Top             =   2760
            Width           =   975
         End
         Begin VB.Label Label9 
            Caption         =   "E-Mails"
            Height          =   375
            Left            =   240
            TabIndex        =   21
            Top             =   3240
            Width           =   855
         End
         Begin VB.Label Label10 
            Caption         =   "Observações"
            Height          =   375
            Left            =   240
            TabIndex        =   20
            Top             =   3600
            Width           =   1095
         End
      End
      Begin MSChart20Lib.MSChart MSChart1 
         Height          =   5055
         Left            =   -74760
         OleObjectBlob   =   "Form1.frx":0038
         TabIndex        =   35
         Top             =   1080
         Width           =   9015
      End
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Sair"
      Height          =   495
      Index           =   8
      Left            =   8280
      TabIndex        =   8
      Top             =   6720
      Width           =   1095
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Guardar"
      Height          =   495
      Index           =   7
      Left            =   6600
      TabIndex        =   7
      Top             =   6720
      Width           =   975
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Novo"
      Height          =   495
      Index           =   6
      Left            =   5400
      TabIndex        =   6
      Top             =   6720
      Width           =   1095
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Eliminar"
      Height          =   495
      Index           =   5
      Left            =   4320
      TabIndex        =   5
      Top             =   6720
      Width           =   975
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Alterar"
      Height          =   495
      Index           =   4
      Left            =   3240
      TabIndex        =   4
      Top             =   6720
      Width           =   975
   End
   Begin VB.CommandButton Command3 
      Caption         =   "seguinte"
      Height          =   495
      Index           =   3
      Left            =   2280
      TabIndex        =   3
      Top             =   6720
      Width           =   855
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Ultimo"
      Height          =   495
      Index           =   2
      Left            =   1560
      TabIndex        =   2
      Top             =   6720
      Width           =   735
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Prim"
      Height          =   495
      Index           =   1
      Left            =   840
      TabIndex        =   1
      Top             =   6720
      Width           =   735
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Anterior"
      Height          =   495
      Index           =   0
      Left            =   120
      TabIndex        =   0
      Top             =   6720
      Width           =   735
   End
   Begin VB.Menu mnuficheiro 
      Caption         =   "Ficheiro"
      Begin VB.Menu itemabrir 
         Caption         =   "Abrir"
      End
      Begin VB.Menu itemguardar 
         Caption         =   "Guardar"
      End
      Begin VB.Menu itemsair 
         Caption         =   "Sair"
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
    
    List1.AddItem (Text1(7).Text)
    
End Sub

Private Sub Command3_Click(Index As Integer)

On Error GoTo trata_erro

Select Case Index
    Case Is = 0:
         Dim v As Integer
    
        If Label1.Caption = 1 Then
            MsgBox "Nao e possivel retroceder"
            Command3(0).Enabled = False
        Else

            Open "e:\registos.dat" For Random As #1 Len = Len(registos)
                v = Val(Label1.Caption)
                If v > 1 Then
                    Get #1, v - 1, registos
                    Label1.Caption = registos.cod
                    Text1(0).Text = Trim$(registos.nome)
                    Text1(1).Text = registos.morada
                    Text1(2).Text = registos.codpostal
                    Text1(3).Text = Trim$(registos.localidade)
                    Text1(4).Text = registos.datanascimento
                    Text1(5).Text = registos.telefone
                    Text1(6).Text = Trim$(registos.nick)
                    Text1(8).Text = Trim$(registos.observacoes)
                End If
            Close #1
             Open "E:\mails.dat" For Random As #1 Len = Len(mails)
                    v = Val(Label1.Caption)
                    If v > 1 Then
                        Get #1, v - 1, registos
                       'For i = 1 To Tot
                        'List1.Clear
                        List1.AddItem (mails.mail)
                    'Next i
                    End If
                Close #1
            Command3(3).Enabled = True
        End If
    Case Is = 3:
        Open "e:\registos.dat" For Random As #1 Len = Len(registos)
                v = Val(Label1.Caption)
                If v > 1 Then
                    Get #1, v - 1, registos
                    Label1.Caption = registos.cod
                    Text1(0).Text = Trim$(registos.nome)
                    Text1(1).Text = registos.morada
                    Text1(2).Text = registos.codpostal
                    Text1(3).Text = Trim$(registos.localidade)
                    Text1(4).Text = registos.datanascimento
                    Text1(5).Text = registos.telefone
                    Text1(6).Text = Trim$(registos.nick)
                    Text1(8).Text = Trim$(registos.observacoes)
                End If
            Close #1
        Open "E:\registos.dat" For Random As #1 Len = Len(registos)
                    v = Val(Label1.Caption)
                    If v < Tot Then
                        Get #1, v + 1, registos
                       For i = 1 To Tot
                        Get #2, , mails
                        'List1.Clear
                        List1.AddItem (mails.mail)
                    Next i
                    End If
                Close #1
                Command3(0).Enabled = True
    Case Is = 4:
        For i = 0 To 8
            Text1(i).Locked = False
        Next i
    Case Is = 5:
        For i = 0 To 8
            Text1(i).Text = ""
        Next i
        List1.Clear
    Case Is = 6:
             Dim a As Integer
        
        For i = 0 To 8
            Text1(i).Text = ""
            Text1(i).Locked = False
        Next i
        codigo = Tot + 1
        Tot = Tot + 1
        Label1.Caption = Val(Label1.Caption) + 1
        Text1(0).SetFocus
    Case Is = 7:
        For i = 0 To 8
            Text1(i).Locked = True
        Next i
             Open "e:\registos.dat" For Random As #1 Len = Len(registos)
        For i = 0 To Tot
            registos.cod = Label1.Caption
            registos.nome = Trim$(Text1(0).Text)
            registos.morada = Trim$(Text1(1).Text)
            registos.codpostal = Text1(2).Text
            registos.localidade = Trim$(Text1(3).Text)
            registos.datanascimento = Text1(4).Text
            registos.telefone = Text1(5).Text
            registos.nick = Trim$(Text1(6).Text)
            registos.observacoes = Trim$(Text1(8).Text)
            Put #1, , registos
         Next i
        Close #1
         Open "e:\mails.dat" For Random As #1 Len = Len(mails)
            'List1.Clear
        For i = 0 To List1.ListCount - 1
            mails.cod = Label1.Caption
            mails.mail = List1.List(i)
            Put #1, , mails
        Next i
        Close #1
        reg = Val(Label1.Caption)
    Case Is = 8:
        End
End Select

Exit Sub

trata_erro:
    Beep
    MsgBox "Erro inesperado nrº " & Err.Number & " - " & Err.Description, vbCritical, "qq coisa"
    Resume Next

End Sub

Private Sub Command4_Click()

    SSTab1.Tab = 0
    
End Sub

Private Sub Command5_Click()

    SSTab1.Tab = 1
    MSChart1.RowCount = 2
    MSChart1.ColumnCount = 1
    MSChart1.Column = 1
    MSChart1.Row = 1
    MSChart1.Data = 100
    MSChart1.Row = 2
    MSChart1.Data = 0
    
End Sub

Private Sub DTP1_KeyDown(KeyCode As Integer, Shift As Integer)

    If KeyCode = 13 Then
        Text1(5).SetFocus
    End If
    
End Sub

Private Sub DTP1_LostFocus()

    If CDate(DTP1.Value) > CDate(Date) Then
        Beep
        MsgBox "Data inválida"
        DTP1.Value = Date
        DTP1.SetFocus
    End If
    
End Sub


Private Sub Form_Load()

 Dim i As Integer
    
    Tot = 0
    For i = 0 To 8
        Text1(i).Locked = True
    Next i
    Open "f:\registos.dat" For Random As #1 Len = Len(registos)
    Tot = LOF(1) / Len(registos)
    'MsgBox "A estrutura de dados tem " & Tot & " registos..."
    For i = 1 To Tot
        Get #1, , registos
        Label1.Caption = registos.cod
        Text1(0).Text = Trim$(registos.nome)
        Text1(1).Text = registos.morada
        Text1(2).Text = registos.codpostal
        Text1(3).Text = Trim$(registos.localidade)
        Text1(4).Text = registos.datanascimento
        Text1(5).Text = registos.telefone
        Text1(6).Text = Trim$(registos.nick)
        Text1(8).Text = Trim$(registos.observacoes)
    Next i
    Close #1
     Open "f:\mails.dat" For Random As #2 Len = Len(mails)
    Tot = LOF(2) / Len(mails)
    'MsgBox "A estrutura de dados tem " & Tot & " registos..."
    For i = 1 To Tot
        Get #2, , mails
        'List1.Clear
        List1.AddItem (mails.mail)
    Next i
    Close #2
    reg = Val(Label1.Caption)
    SSTab1.Tab = 0
    
End Sub


Private Sub itemabrir_Click()

    CD1.CancelError = False
    CD1.DialogTitle = "Abertura da lista de contactos..."
    CD1.Filter = "Ficheiro de dados (*.dat)|*.dat|Todos os ficheiros (*.*)|*.*"
    CD1.FilterIndex = 2
    CD1.ShowSave
    
    If Right(CD1.FileName, 3) <> "dat" Then
        MsgBox "Tipo de ficheiro inválido...."
    End If
        'open cd1.FileName for lksjdnfkjsdf
    
End Sub

Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)

    Select Case Index
        Case Is = 3:
            If KeyAscii = 13 Then
                DTP1.SetFocus
            End If
    End Select
    
End Sub
