quinta-feira, 17 de fevereiro de 2011

ficha 25

Private Type pessoa              'tipo de dados
nome As String * 30
numero As Integer
nota1 As Integer
nota2 As Integer
End Type

Dim tabela(20) As pessoa
Dim i As Integer, j As Integer
Private Sub ver_dados(k As Integer)            'ver dados
Text1.Text = tabela(k).numero
Text2.Text = tabela(k).nome
Text3.Text = tabela(k).nota1
Text4.Text = tabela(k).nota2
Label6.Caption = Round((tabela(k).nota1 + tabela(k).nota2) / 2, 1)
End Sub

Private Sub Command1_Click()      'Botão retroceder
If i > 0 Then
 i = i - 1
 ver_dados (i)
End If
End Sub


Private Sub Command2_Click()              'Botão avançar
If i < j Then
 i = i + 1
 ver_dados (i)
End If

End Sub

Private Sub Command3_Click()        'gravar/inserir
If Text1.Text = "" Then
MsgBox "Não introduziu o seu número. Por favor coloque o seu número!", vbInformation, "ATENÇÃO!!!"
ElseIf Text1.Text = "4" Then
MsgBox "A gravar os campos do formulário!", vbInformation, "Gravar Dados!"
gravar_dados
End If
Command3.Enabled = True
Command1.Enabled = True
Command2.Enabled = True
Command4.Enabled = True
Command6.Enabled = True
End Sub
Private Sub gravar_dados()
    tabela(j).numero = Text1.Text
    tabela(j).nome = Text2.Text
    tabela(j).nota1 = Val(Text1.Text)
    tabela(j).nota2 = Val(Text2.Text)
     i = j
    j = j + 1
End Sub

Private Sub Command4_Click()                       'procurar
Dim procura As String * 30, x As Integer
procura = InputBox("Qual o nome a procurar?", "Pesquisa")
For x = 0 To j - 1
If UCase(tabela(x).nome) = UCase(procura) Then
      ver_dados (x)
      Exit For
End If
Next x
If j = x Then
MsgBox "O nome que introduziu não consta neste registo. Por favor introduza outro nome.", vbYesNo + vbInformation, "Aviso"
End If
End Sub

Private Sub Command5_Click()                    'sair
End
End Sub

Private Sub Command6_Click()                'limpar
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Label6.Caption = ""
Command3.Enabled = True
Command1.Enabled = False
Command2.Enabled = False
Command4.Enabled = False
Command6.Enabled = False
End Sub

Private Sub Form_Load()             'form load

tabela(0).numero = 1
tabela(0).nome = "Agostinho Caetano"
tabela(0).nota1 = 15
tabela(0).nota2 = 15



tabela(1).numero = 2
tabela(1).nome = "André Almeida"
tabela(1).nota1 = 14
tabela(1).nota2 = 14


tabela(2).numero = 3
tabela(2).nome = "André Amorim"
tabela(2).nota1 = 16
tabela(2).nota2 = 16


j = 3
i = 2
ver_dados (2)
End Sub



Sem comentários:

Enviar um comentário