TUTORIAIS DE VISUAL BASIC
 
2. Um Projecto
Página: 1 2 3 4 5 6
 

 

A segunda janela do projecto apresentará o aspecto que acabaste de ver. 7 caixas de texto com a propriedade Name alterada para os nomes que aparecem dentro delas. 5 botões chamados respectivamente cmdgravar, cmdactualizar, cmdapagar, cmdnovo e cmdsair. Nestes botões e na propriedade Caption fizemos aparecer os nomes mostrados. Um objecto SSTab com 3 separadores cujas propriedades Caption foram alteradas para Sexo, Estado Civil, Memórias.
A imagem anterior e a que se segue são as duas imagem do separador SSTab. Convem aqui referir, a existência de uma Frame em cada separador onde são inseridas os OptionButtons. No primeiro caso com a propriedade Name=Option1, para constituir um array, e no segundo caso com a propriedade Name=Option2, para constituir um segundo array.

Propriedades alteradas neste Form:

Name : frmamigos
Caption : Gestão de amigos
KeyPreview : True

O código correspondente a este Form é o que se segue:

 


Option Explicit


Sub gravarBD()
tblami![numero] = txtnumero.Text
tblami![nome] = txtnome.Text
tblami![morada] = txtmorada.Text
tblami![codpostal] = txtcodpostal.Text
tblami![tm] = txttm.Text
tblami![tel] = txttel.Text
tblami![dtnasc] = txtdatnasc.Text
If option1(0).Value = True Then
     tblami![sexo] = "M"
Else
     tblami![sexo] = "F"
End If
If Option2(0).Value = True Then
     tblami![estcivil] = "C"
ElseIf Option2(1).Value = True Then
     tblami![estcivil] = "S"
ElseIf Option2(2).Value = True Then
     tblami![estcivil] = "V"
ElseIf Option2(3).Value = True Then
     tblami![estcivil] = "X"
ElseIf Option2(4).Value = True Then
     tblami![estcivil] = "D"
ElseIf Option2(5).Value = True Then
     tblami![estcivil] = "O"
End If
tblami![relatorio] = txtmem.Text
tblami.Update
End Sub


Sub mostrarBD()
txtnumero.Text = tblami![numero]
txtnome.Text = tblami![nome]
txtmorada.Text = tblami![morada]
txtcodpostal.Text = tblami![codpostal]
txttel.Text = tblami![tel]
txttm.Text = tblami![tm]
txtdatnasc.Text = tblami![dtnasc]
txtmem.Text = tblami![relatorio]
If tblami![sexo] = "M" Then
     option1(0).Value = True
Else
     option1(1).Value = True
End If
If tblami![estcivil] = "C" Then
     Option2(0).Value = True
ElseIf tblami![estcivil] = "S" Then
     Option2(1).Value = True
ElseIf tblami![estcivil] = "V" Then
     Option2(2).Value = True
ElseIf tblami![estcivil] = "X" Then
     Option2(3).Value = True
ElseIf tblami![estcivil] = "D" Then
     Option2(4).Value = True
ElseIf tblami![estcivil] = "O" Then
     Option2(5).Value = True
End If
End Sub


Private Sub cmdactualizar_Click()
Call gravarBD
txtnumero.SetFocus
End Sub


Private Sub cmdapagar_Click()
tblami.Delete
txtnumero.SetFocus
End Sub


Private Sub cmdgravar_Click()
tblami.AddNew
Call gravarBD
txtnumero.SetFocus
End Sub


Private Sub cmdoutro_Click()
txtnumero.SetFocus
End Sub


Private Sub cmdsair_Click()
Unload Me
End Sub


Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
     SendKeys "{TAB}"
     KeyAscii = 0
End If
End Sub


Private Sub Form_Load()
Label1.Caption = etiqueta
End Sub


Private Sub Picture1_Click()
tblami.MoveLast
Call mostrarBD
End Sub


Private Sub Picture2_Click()
tblami.MoveFirst
Call mostrarBD
End Sub


Private Sub Picture3_Click()
tblami.MoveNext
If tblami.EOF Then
     tblami.MoveLast
End If
Call mostrarBD
End Sub


Private Sub Picture4_Click()
tblami.MovePrevious
     If tblami.BOF Then
tblami.MoveFirst
End If
Call mostrarBD
End Sub


Private Sub txtcodpostal_GotFocus()
txtcodpostal.SelStart = 0
txtcodpostal.SelLength = Len(txtcodpostal.Text)
End Sub


Private Sub txtcodpostal_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase$(Chr$(KeyAscii)))
End Sub


Private Sub txtdatnasc_GotFocus()
txtdatnasc.SelStart = 0
txtdatnasc.SelLength = Len(txtdatnasc.Text)
End Sub


Private Sub txtdatnasc_LostFocus()
If txtdatnasc.Text <> "" Then
     If Not IsDate(txtdatnasc.Text) Then
          MsgBox ("A Data Introduzida Não É Válida")
          txtdatnasc.SetFocus
     End If
End If
End Sub


Private Sub txtmorada_GotFocus()
txtmorada.SelStart = 0
txtmorada.SelLength = Len(txtmorada.Text)
End Sub


Private Sub txtmorada_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase$(Chr$(KeyAscii)))
End Sub


Private Sub txtnome_GotFocus()
txtnome.SelStart = 0
txtnome.SelLength = Len(txtnome.Text)
End Sub


Private Sub txtnome_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase$(Chr$(KeyAscii)))
End Sub


Private Sub txtnumero_GotFocus()
txtnumero.Text = ""
txtnome.Text = ""
txtmorada.Text = ""
txtcodpostal.Text = ""
txttel.Text = ""
txttm.Text = ""
txtdatnasc.Text = ""
txtmem.Text = ""
SSTab1.Tab = 0
Option2(0).Value = False
Option2(1).Value = True
Option2(2).Value = False
Option2(3).Value = False
Option2(4).Value = False
Option2(5).Value = False
option1(0).Value = True
option1(1).Value = False
cmdgravar.Enabled = False
cmdactualizar.Enabled = False
cmdapagar.Enabled = False
End Sub


Private Sub txtnumero_LostFocus()
tblami.Index = "chavenumero"
tblami.Seek "=", txtnumero.Text
If Not tblami.NoMatch Then
     cmdactualizar.Enabled = True
     cmdapagar.Enabled = True
     tblami.Edit
     Call mostrarBD
Else
     cmdgravar.Enabled = True
     txtnome.Text = "."
     txtmorada.Text = "."
     txtcodpostal.Text = "."
     txttel.Text = "0"
     txttm.Text = "0"
     txtdatnasc.Text = Date
     txtmem.Text = "."
End If
End Sub


Private Sub txttel_GotFocus()
txttel.SelStart = 0
txttel.SelLength = Len(txttel.Text)
End Sub


Private Sub txttel_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
     Case vbKeyDelete
     Case vbKeyBack
     Case 48 To 57
     Case Else
          Beep
          KeyAscii = 0
End Select
End Sub


Private Sub txttm_GotFocus()
txttm.SelStart = 0
txttm.SelLength = Len(txttm.Text)
End Sub


Private Sub txttm_KeyPress(KeyAscii As Integer)

Select Case KeyAscii
     Case vbKeyDelete
     Case vbKeyBack
     Case 48 To 57
     Case Else
         Beep
         KeyAscii = 0
End Select
End Sub

 

ANÚNCIOS

 



 
 
 
  Tutoriais | Fóruns de Discussão | Notícias | Jogos | Dicas | Flash | Downloads | Livros
Gifs Animados | Loja Online | Publicitar no Truques e Dicas | Contactos