quarta-feira, 17 de fevereiro de 2010
Ficha 22 - Em base de Dados
Private Sub Sair_Click()
If MsgBox("Deseja sair?", vbYesNo + vbQuestion, " Aviso") = vbYes Then End
End Sub
Private Sub cmdPrimeiro_Click()
If Data1.Recordset.BOF Then
MsgBox " Base de dados vazia"
Else
Data1.Recordset.MoveFirst
End If
End Sub
Private Sub cmdSeguinte_Click()
If Data1.Recordset.EOF Then
If Data1.Recordset.BOF Then
MsgBox "Base de Dados vazia!"
End If
Else
Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then
Data1.Recordset.MoveLast
End If
End If
End Sub
Private Sub cmdAnterior_Click()
If Data1.Recordset.BOF Then
If Data1.Recordset.EOF Then
MsgBox "Base de Dados vazia!"
End If
Else
Data1.Recordset.MovePrevious
If Data1.Recordset.BOF Then
Data1.Recordset.MoveFirst
End If
End If
End Sub
Private Sub cmdUltimo_Click()
If Data1.Recordset.EOF Then
MsgBox " Base de dados vazia"
Else
Data1.Recordset.MoveLast
End If
End Sub
Private Sub Form_Load()
cmdGuardar.Enabled = False
End Sub
Private Sub cmdAdicionar_Click()
If cmdAdicionar.Caption = "Adicionar" Then
Data1.Recordset.AddNew
txtcodigo.SetFocus
txtfuncionario.SetFocus
txtsalario.SetFocus
txtvale.SetFocus
cmdEliminar.Enabled = False
cmdGuardar.Enabled = True
cmdAdicionar.Caption = "Cancelar"
Else
cmdEliminar.Enabled = True
cmdGuardar.Enabled = False
cmdAdicionar.Caption = "Adicionar"
End If
End Sub
Private Sub cmdGuardar_Click()
Dim Resp As Integer, Mens As String
If txtcodigo.Text = Empty Then
MsgBox "Preencha o campo Código", vbOKOnly + vbExclamation, " Aviso"
ElseIf txtfuncionario.Text = Empty Then
MsgBox "Preencha o campo Funcionário", vbOKOnly + vbExclamation, " Aviso"
ElseIf txtsalario.Text = Empty Then
MsgBox "Preencha o campo Salário", vbOKOnly + vbExclamation, " Aviso"
ElseIf txtvale.Text = Empty Then
MsgBox "Preencha o campo Vale", vbOKOnly + vbExclamation, " Aviso"
Else
Mens = "Deseja guardar os novos dados?"
Resp = MsgBox(Mens, vbYesNo + vbQuestion, "Question")
If Resp = vbYes Then
txttotal.Text = Val(txtsalario.Text) + Val(txtvale.Text)
Data1.Recordset.Update
cmdEliminar.Enabled = True
cmdGuardar.Enabled = False
cmdAdicionar.Caption = "Adicionar"
End If
End If
End Sub
Private Sub cmdEliminar_click()
If MsgBox("Deseja eliminar este registo?", vbYesNo + vbQuestion, "Question") = vbNo Then
MsgBox "Registo não eliminado"
Else
Data1.Recordset.Delete
Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then
Data1.Recordset.MovePrevious
If Data1.Recordset.BOF Then
MsgBox "Não há registos"
cmdEliminar.Enabled = False
End If
End If
MsgBox "Registo Eliminado"
End If
End Sub
Private Sub Retroceder_Click()
End Sub
Private Sub Timer1_Timer()
Hora_Data = Now
End Sub
Private Sub txtcodigo_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
Private Sub txtfuncionario_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case vbKeyDelete
Case vbKeyBack
Case 65 To 90
Case 97 To 122
Case 32
Case Else
Beep
KeyAscii = 0
End Select
End Sub
Private Sub txtsalario_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
Private Sub txtvale_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
domingo, 7 de fevereiro de 2010
Ficha 23
Private Type Folha
matricula As Long
nome As String * 40
nota1 As Long
nota2 As Long
media As Single
End Type
Dim tabela(19) As Folha
Dim i As Integer, j As Integer
Private Sub Avancar2_Click()
mensagem.Enabled = False
Limpar.Enabled = True
retroceder.Enabled = True
Retroceder2.Enabled = True
If j < i - 1 Then
j = j + 1
ver_dados (j)
End If
If j = i - 1 Then
avancar.Enabled = False
Avancar2.Enabled = False
End If
End Sub
Private Sub retroceder_Click()
mensagem.Enabled = False
Limpar.Enabled = True
avancar.Enabled = True
Avancar2.Enabled = True
If j > 0 Then
j = j - 1
ver_dados (j)
End If
If j = 0 Then
retroceder.Enabled = False
Retroceder2.Enabled = False
End If
End Sub
Private Sub avancar_Click()
mensagem.Enabled = False
Limpar.Enabled = True
retroceder.Enabled = True
Retroceder2.Enabled = True
If j < i - 1 Then
j = j + 1
ver_dados (j)
End If
If j = i - 1 Then
avancar.Enabled = False
Avancar2.Enabled = False
End If
End Sub
Private Sub Form_Load()
i = 0
End Sub
Private Sub mensagem_Click()
If txtmatricula.Text = Empty Then
MsgBox "Preencha o campo Matrícula", vbOKOnly + vbExclamation, " Aviso"
ElseIf txtnome.Text = Empty Then
MsgBox "Preencha o campo Nome", vbOKOnly + vbExclamation, " Aviso"
ElseIf txtnota1.Text = Empty Then
MsgBox "Preencha o campo Nota 1", vbOKOnly + vbExclamation, " Aviso"
ElseIf txtnota2.Text = Empty Then
MsgBox "Preencha o campo Nota 2", vbOKOnly + vbExclamation, " Aviso"
ElseIf txtnota1.Text < 0 Or txtnota1.Text > 20 Then
MsgBox "Nota 1 excedida", vbOKOnly + vbCritical, " Aviso"
ElseIf txtnota2.Text < 0 Or txtnota2.Text > 20 Then
MsgBox "Nota 2 excedida", vbOKOnly + vbCritical, " Aviso"
Else
tabela(i).matricula = txtmatricula.Text
tabela(i).nome = txtnome.Text
tabela(i).nota1 = txtnota1.Text
tabela(i).nota2 = txtnota2.Text
MsgBox "Dados Inseridos", vbOKOnly + vbInformation, " Mensagem"
txtmedia.Text = (Val(txtnota1.Text) + Val(txtnota2.Text)) / 2
tabela(i).media = (Val(txtnota1.Text) + Val(txtnota2.Text)) / 2
i = i + 1
j = i
mensagem.Enabled = False
retroceder.Enabled = False
Retroceder2.Enabled = False
avancar.Enabled = False
Avancar2.Enabled = False
Limpar.Enabled = True
End If
End Sub
Private Sub Limpar_Click()
txtmatricula.Text = ""
txtnome.Text = ""
txtnota1.Text = ""
txtnota2.Text = ""
txtmedia.Text = ""
mensagem.Enabled = True
retroceder.Enabled = True
Retroceder2.Enabled = True
avancar.Enabled = True
Avancar2.Enabled = True
Limpar.Enabled = False
End Sub
Private Sub Retroceder2_Click()
mensagem.Enabled = False
Limpar.Enabled = True
avancar.Enabled = True
Avancar2.Enabled = True
If j > 0 Then
j = j - 1
ver_dados (j)
End If
If j = 0 Then
retroceder.Enabled = False
Retroceder2.Enabled = False
End If
End Sub
Private Sub Sair_Click()
If MsgBox("Deseja sair?", vbYesNo + vbQuestion, " Aviso") = vbYes Then End
End Sub
Private Sub Timer1_Timer()
Hora_Data = Now
End Sub
Private Sub ver_dados(k As Integer)
txtmatricula.Text = tabela(k).matricula
txtnome.Text = tabela(k).nome
txtnota1.Text = tabela(k).nota1
txtnota2.Text = tabela(k).nota2
txtmedia.Text = tabela(k).media
End Sub
Private Sub txtmatricula_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
Private Sub txtnome_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case vbKeyDelete
Case vbKeyBack
Case 65 To 90
Case 97 To 122
Case 128 To 154
Case 159 To 165
Case 32
Case Else
Beep
KeyAscii = 0
End Select
End Sub
Private Sub txtnota1_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
Private Sub txtnota2_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
quinta-feira, 4 de fevereiro de 2010
Ficha 22
~Private Type Folha
codigo As Long
funcionario As String * 40
salario As Long
vale As Long
total As Long
End Type
Dim tabela(11) As Folha
Dim i As Integer, j As Integer
Private Sub Avancar2_Click()
Incluir.Enabled = False
Limpar.Enabled = True
Retroceder.Enabled = True
Retroceder2.Enabled = True
If j < i - 1 Then
j = j + 1
ver_dados (j)
End If
If j = i - 1 Then
Avancar.Enabled = False
Avancar2.Enabled = False
End If
End Sub
Private Sub retroceder_Click()
Incluir.Enabled = False
Limpar.Enabled = True
Avancar.Enabled = True
Avancar2.Enabled = True
If j > 0 Then
j = j - 1
ver_dados (j)
End If
If j = 0 Then
Retroceder.Enabled = False
Retroceder2.Enabled = False
End If
End Sub
Private Sub avancar_Click()
Incluir.Enabled = False
Limpar.Enabled = True
Retroceder.Enabled = True
Retroceder2.Enabled = True
If j < i - 1 Then
j = j + 1
ver_dados (j)
End If
If j = i - 1 Then
Avancar.Enabled = False
Avancar2.Enabled = False
End If
End Sub
Private Sub Form_Load()
i = 0
End Sub
Private Sub Incluir_Click()
If txtcodigo.Text = Empty Then
MsgBox "Preencha o campo Código", vbOKOnly + vbExclamation, " Aviso"
ElseIf txtfuncionario.Text = Empty Then
MsgBox "Preencha o campo Funcionário", vbOKOnly + vbExclamation, " Aviso"
ElseIf txtsalario.Text = Empty Then
MsgBox "Preencha o campo Salário", vbOKOnly + vbExclamation, " Aviso"
ElseIf txtvale.Text = Empty Then
MsgBox "Preencha o campo Vale", vbOKOnly + vbExclamation, " Aviso"
Else
tabela(i).codigo = txtcodigo.Text
tabela(i).funcionario = txtfuncionario.Text
tabela(i).salario = txtsalario.Text
tabela(i).vale = txtvale.Text
MsgBox "Dados Inseridos", vbOKOnly + vbInformation, " Mensagem"
txttotal.Text = Val(txtsalario) + Val(txtvale.Text)
tabela(i).total = Val(txtsalario) + Val(txtvale.Text)
i = i + 1
j = i
Incluir.Enabled = False
Retroceder.Enabled = False
Retroceder2.Enabled = False
Avancar.Enabled = False
Avancar2.Enabled = False
Limpar.Enabled = True
End If
End Sub
Private Sub Limpar_Click()
txtcodigo.Text = ""
txtfuncionario.Text = ""
txtsalario.Text = ""
txtvale.Text = ""
txttotal.Text = ""
Incluir.Enabled = True
Retroceder.Enabled = True
Retroceder2.Enabled = True
Avancar.Enabled = True
Avancar2.Enabled = True
Limpar.Enabled = False
End Sub
Private Sub Retroceder2_Click()
Incluir.Enabled = False
Limpar.Enabled = True
Avancar.Enabled = True
Avancar2.Enabled = True
If j > 0 Then
j = j - 1
ver_dados (j)
End If
If j = 0 Then
Retroceder.Enabled = False
Retroceder2.Enabled = False
End If
End Sub
Private Sub Sair_Click()
If MsgBox("Deseja sair?", vbYesNo + vbQuestion, " Aviso") = vbYes Then End
End Sub
Private Sub Timer1_Timer()
Hora_Data = Now
End Sub
Private Sub ver_dados(k As Integer)
txtcodigo.Text = tabela(k).codigo
txtfuncionario.Text = tabela(k).funcionario
txtsalario.Text = tabela(k).salario
txtvale.Text = tabela(k).vale
txttotal.Text = tabela(k).total
End Sub
Private Sub txtcodigo_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
Private Sub txtfuncionario_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case vbKeyDelete
Case vbKeyBack
Case 65 To 90
Case 97 To 122
Case 32
Case Else
Beep
KeyAscii = 0
End Select
End Sub
Private Sub txtsalario_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
Private Sub txtvale_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
Subscrever:
Mensagens (Atom)