quarta-feira, 23 de fevereiro de 2011

ficha de trabalho 27

Private Sub Bloquear_Formulario()
    Text1.Enabled = False
    Text2.Enabled = False
    Text3.Enabled = False
    Text4.Enabled = False
End Sub
Private Sub Desbloquear_Formulario()
    Text1.Enabled = True
    Text2.Enabled = True
    Text3.Enabled = True
    Text4.Enabled = True
End Sub
Private Sub Command1_Click()
If Command1.Caption = "Adicionar" Then
          Data1.Recordset.AddNew
          Desbloquear_Formulario
          Text1.SetFocus
          Command3.Enabled = False
          Command2.Enabled = True
          Command1.Caption = "Cancelar"
     Else
          Data1.Recordset.CancelUpdate
          Bloquear_Formulario
          Command3.Enabled = True
          Command2.Enabled = False
          Command1.Caption = "Adicionar"
     End If
End Sub

Private Sub Command2_Click()
 If IsNumeric(Text1.Text) = False Then
        MsgBox "Inseriu letras em vez de valores numericos por favor corrija.", vbOKOnly + vbCritical, "AVISO"
       
ElseIf IsNumeric(Text2.Text) = True Then
    MsgBox "Inseriu valores numericos em vez de letras por favor corrija.", vbOKOnly + vbCritical, "AVISO"
   
    ElseIf IsNumeric(Text3.Text) = False Then
    MsgBox "Inseriu letras em vez de valores numericos por favor corrija.", vbOKOnly + vbCritical, "AVISO"
   
    ElseIf IsNumeric(Text4.Text) = False Then
    MsgBox "Inseriu letras em vez de valores numericos por favor corrija.", vbOKOnly + vbCritical, "AVISO"
   
    ElseIf IsNumeric(Text1.Text) = True And IsNumeric(Text2.Text) = False And IsNumeric(Text3.Text) = True And IsNumeric(Text4.Text) = True Then
    MsgBox "Deseja guardar os novos dados?", vbYesNo + vbQuestion, "Question"
         
          Data1.Recordset.Update
          Bloquear_Formulario
          Command3.Enabled = True
          Command2.Enabled = False
          Command1.Caption = "Adicionar"
      
       
     End If
End Sub

Private Sub Command3_Click()
     If MsgBox("Deseja eliminar este registo?", vbYesNo + vbQuestion, "Question") = vbNo Then
          MsgBox "Registo não eliminado!"
          Else
          Data1.Recordset.Delete
          MsgBox "Registo Eliminado."
          Data1.Recordset.MoveNext
          If Data1.Recordset.EOF Then
               Data1.Recordset.MovePrevious
                If Data1.Recordset.BOF Then
                    MsgBox "Não há registos!"
                    Command3.Enabled = False
                    Command4.Enabled = False
                    Command5.Enabled = False
                    Command6.Enabled = False
                    Command7.Enabled = False
                End If
          End If
     End If
End Sub

Private Sub Command4_Click()
Data1.Recordset.MoveFirst
End Sub

Private Sub Command5_Click()
Data1.Recordset.MovePrevious
     If Data1.Recordset.BOF Then
          Data1.Recordset.MoveFirst
     End If
End Sub

Private Sub Command6_Click()
Data1.Recordset.MoveNext
     If Data1.Recordset.EOF Then
          Data1.Recordset.MoveLast
     End If
End Sub

Private Sub Command7_Click()
Data1.Recordset.MoveLast
End Sub


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



quinta-feira, 16 de dezembro de 2010

ficha de trabalho numero 19 exercicio 1

Private Sub Command1_Click()
Dim x As Integer, a As Integer, b As Integer
a = Text2.Text
b = Text3.Text
List1.AddItem Text1.Text
List2.AddItem Text2.Text
List3.AddItem Text3.Text
x = (a * b)
Label5.Caption = x
List4.AddItem x
Text1.Text = " "
Text2.Text = " "
Text3.Text = " "
End Sub

Private Sub Command2_Click()
Text1.Text = " "
Text2.Text = " "
Text3.Text = " "
Label5.Caption = " "
End Sub

Private Sub Command3_Click()
Dim x As Integer
x = List1.ListIndex
List1.RemoveItem x
List2.RemoveItem x
List3.RemoveItem x
List4.RemoveItem x
End Sub

Private Sub Command4_Click()
Dim x As Integer
For x = 0 To List4.ListCount
soma = soma + Val(List4.List(x))
Next x
Label11.Caption = Round(soma, 2) & " € "
Label5.Caption = ""
End Sub