"A arte de programar consiste na arte de organizar e dominar a complexidade."

quarta-feira, 17 de fevereiro de 2016

Ficha nº24

1.

Código:

Private Type Funcionario
    Codigo As Integer
    Nome As String * 40
    salario As Long
    vale As Long
    Fotografia As String * 60
End Type
Dim tabela(12) As Funcionario
Dim i As Integer, j As Integer

Private Sub Command1_Click()
    If Text1.Text <> "" And Text2.Text <> "" And Text3.Text <> "" And Text4.Text <> "" And Text6.Text <> "" Then
        MsgBox "Dados inseridos", vbInformation + vbOKOnly, "Mensagem"
        Label7.Visible = False
        Text6.Visible = False
        Image1.Visible = True
        Image1.Picture = LoadPicture(Text6.Text)
        gravar_dados
        Command2.Enabled = True
        Command4.Enabled = True
        Command5.Enabled = True
        Command6.Enabled = True
        Command7.Enabled = True
    Else
        MsgBox "Preencha todos os campos", vbCritical, "Aviso"
    End If
End Sub

Private Sub Command2_Click()
    Text1.Text = ""
    Text2.Text = ""
    Text3.Text = ""
    Text4.Text = ""
    Text5.Text = ""
    Text6.Text = ""
    
    Image1.Visible = False
    Text6.Visible = True
    Label7.Visible = True
    Image1.Visible = False
End Sub

Private Sub Command3_Click()
    Dim opcao As Integer
    
    opcao = MsgBox("Deseja sair?", vbQuestion + vbYesNo, "Confirmação")
    If opcao = vbYes Then
        End
    End If
End Sub

Private Sub Command4_Click()
    If i < j - 1 Then
        i = i + 1
        ver_dados (i)
    End If
End Sub

Private Sub ver_dados(x As Integer)
    Text1.Text = tabela(x).Codigo
    Text2.Text = tabela(x).Nome
    Text3.Text = tabela(x).salario
    Text4.Text = tabela(x).vale
End Sub

Private Sub Command5_Click()
    If i > 0 Then
        i = i - 1
        ver_dados (i)
    End If
End Sub

Private Sub Command6_Click()
    Command1.Enabled = False
    Command4.Enabled = False
    Command5.Enabled = False
End Sub

Private Sub Command7_Click()
    MsgBox "As suas alterações foram guardadas", vbInformation, "Guardado!"
    
    Command1.Enabled = True
    Command4.Enabled = True
    Command5.Enabled = True
    
    tabela(i).Codigo = Text1.Text
    tabela(i).Nome = Text2.Text
    tabela(i).salario = Text3.Text
    tabela(i).vale = Text4.Text
    tabela(i).Fotografia = Text6.Text
End Sub

Private Sub gravar_dados()
    tabela(j).Codigo = Text1.Text
    tabela(j).Nome = Text2.Text
    tabela(j).salario = Text3.Text
    tabela(j).vale = Text4.Text
    tabela(j).Fotografia = Text6.Text
    
    i = j
    j = j + 1
End Sub

Private Sub Form_Load()
    i = 0
    j = 0
    
    Label6.Visible = False
    Text5.Visible = False
    
    If j = 0 Then
        Command2.Enabled = False
        Command4.Enabled = False
        Command5.Enabled = False
        Command6.Enabled = False
        Command7.Enabled = False
    End If
End Sub

Private Sub Text4_Change()
    Dim salario As Integer, vale As Integer

    Label6.Visible = True
    Text5.Visible = True
    
    salario = Text3.Text
    vale = Text4.Text
    
    Text5.Text = salario + vale & " €"
End Sub

Private Sub Timer1_Timer()
    Label1.Caption = Now()
End Sub

Sem comentários:

Enviar um comentário