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

segunda-feira, 26 de outubro de 2015

Ficha nº5 Continuação

1.

Código:

Private Sub Command1_Click()
    
    Dim dia As Integer
    
    dia = Val(Text1.Text)
    
    Select Case dia
    
    Case Is > 31
        Label2.Caption = "Dia inválido"
    Case Is <= 0
        Label2.Caption = "Dia inválido"
    Case 1, 7, 8, 14, 15, 21, 22, 28, 29
        Label2.Caption = "Fim-de-semana"
    Case Else
        Label2.Caption = "Dia útil"
    End Select
    
End Sub

Private Sub Command2_Click()

    End
    
End Sub

2.

Código:

Private Sub Command1_Click()
    Dim ano As Integer, mes As Integer
    
    ano = Val(Text1.Text)
    mes = Val(Text2.Text)
    
    If mes > 12 Then
        Label3.Caption = "Mês inválido"
    ElseIf mes <= 0 Then
        Label3.Caption = "Mês inválido"
    ElseIf ano Mod 4 = 0 And ano Mod 100 <> 0 Then
        Select Case mes
        
        Case 1, 3, 5, 7, 8, 10, 12
            Label3.Caption = "O mês tem 31 dias"
        Case 4, 6, 9, 11
            Label3.Caption = "O mês tem 30 dias"
        Case Else
            Label3.Caption = "O mês tem 29 dias"
        End Select
    Else
        Select Case mes
        
        Case 1, 3, 5, 7, 8, 10, 12
            Label3.Caption = "O mês tem 31 dias"
        Case 4, 6, 9, 11
            Label3.Caption = "O mês tem 30 dias"
        Case Else
            Label3.Caption = "O mês tem 28 dias"
        End Select
    End If
        
        
End Sub

Private Sub Command2_Click()

    End
    
End Sub

3.

Código:

Private Sub Command1_Click()
    Dim mes As Integer
    
    mes = Val(Text1.Text)
    
    Select Case mes
    
    Case Is > 12
        Label2.Caption = "Mês inválido"
    Case Is <= 0
        Label2.Caption = "Mês inválido"
    Case 12, 7, 6, 2
        Label2.Caption = "Mês de alta temporada"
    Case Else
        Label2.Caption = "Mês de baixa temporada"
    End Select

End Sub

Private Sub Command2_Click()
    
    End

End Sub

4.

Código:

Private Sub Command1_Click()
    Dim num As Integer
    
    num = Val(Text1.Text)
    
    Select Case num
    
    Case 1
        Label3.Caption = "Auditório 1"
        Label5.Caption = "8h às 9h"
    Case 2
        Label3.Caption = "Auditório 2"
        Label5.Caption = "9h às 10h"
    Case 3
        Label3.Caption = "Auditório 3"
        Label5.Caption = "13h às 14h"
    Case 4
        Label3.Caption = "Auditório 4"
        Label5.Caption = "15h às 17h"
    Case Else
        Label3.Caption = "Palestra inválida"
        Label5.Caption = "Palestra inválida"
    
    End Select
    
End Sub

Private Sub Command2_Click()

    End
    
End Sub

5.

Código:

Private Sub Command1_Click()
    Dim num As Integer, desconto As Single, opcao As Integer
    Const DESC As Single = 0.1
    
    num = Val(Text1.Text)
    
    opcao = MsgBox("Aceita pagar a gorjeta do empregado?", vbOKCancel + vbQuestion, "Gorjeta")
    
    Select Case num
    
    Case 1
        Label3.Caption = "Picanha"
        If opcao = vbOK Then
            desconto = 25 * DESC
            Label5.Caption = 25 + desconto & "€"
        Else
            Label5.Caption = 25 & "€"
        End If
    Case 2
        Label3.Caption = "Lasanha"
        If opcao = vbOK Then
            desconto = 20 * DESC
            Label5.Caption = 20 + desconto & "€"
        Else
            Label5.Caption = 20 & "€"
        End If
    Case 3
        Label3.Caption = "Strogonoff"
        If opcao = vbOK Then
            desconto = 18 * DESC
            Label5.Caption = 18 + desconto & "€"
        Else
            Label5.Caption = 18 & "€"
        End If
    Case 4
        Label3.Caption = "Bife à casa"
        If opcao = vbOK Then
            desconto = 15 * DESC
            Label5.Caption = 15 + desconto & "€"
        Else
            Label5.Caption = 15 & "€"
        End If
    Case 5
        Label3.Caption = "Pão com ovo"
        If opcao = vbOK Then
            desconto = 5 * DESC
            Label5.Caption = 5 + desconto & "€"
        Else
            Label5.Caption = 5 & "€"
        End If
    Case Else
        Label3.Caption = "Prato inválido"
        Label5.Caption = "Prato inválido"
    
    End Select
End Sub

Private Sub Command2_Click()

    End
    
End Sub


Sem comentários:

Enviar um comentário