sábado, 30 de maio de 2015

Programação em Visual Basic - "Idade"

Olá pessoal,


Este programa pede o vosso nome e idade e devolve uma mensagem dependendo da vossa idade.





Aqui fica a programação:

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim idade As Integer
        Dim nome As String
        nome = InputBox("Qual é o seu nome?", " ")
        idade = InputBox("Qual é a sua idade?", " ")
        If idade < 0 Then
            MsgBox("Olá " & nome & "! Ainda não nasceu.", MsgBoxStyle.Information, "")
        Else
            If idade < 5 Then
                MsgBox("Olá " & nome & "! És um bebé.", MsgBoxStyle.Information, " ")
            Else
                If idade < 12 Then
                    MsgBox("Olá " & nome & "! És uma criança.", MsgBoxStyle.Information, " ")
                Else
                    If idade < 19 Then
                        MsgBox("Olá " & nome & "! És um adolescente.", MsgBoxStyle.Information, "")
                    Else
                        If idade < 32 Then
                            MsgBox("Olá " & nome & "! És um jovem.", MsgBoxStyle.Information, "")
                        Else
                            If idade < 82 Then
                                MsgBox("Olá " & nome & "! És um adulto.", MsgBoxStyle.Information, "")
                            Else
                                If idade < 101 Then
                                    MsgBox("Olá " & nome & "! És um idoso.", MsgBoxStyle.Information, "")
                                Else
                                    MsgBox("Olá " & nome & "! Tens uma idade extraordinária!", MsgBoxStyle.Information, "")
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        End If
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim idade As Integer
        Dim nome As String
        nome = InputBox("Qual é o seu nome?", " ")
        idade = InputBox("Qual é a sua idade?", " ")
        If idade < 0 Then
            MsgBox("Olá " & nome & "! Ainda não nasceu.", MsgBoxStyle.Information, "")
        Else
            If idade < 5 Then
                MsgBox("Olá " & nome & "! És um bebé.", MsgBoxStyle.Information, " ")
            Else
                If idade < 12 Then
                    MsgBox("Olá " & nome & "! És uma criança.", MsgBoxStyle.Information, " ")
                Else
                    If idade < 19 Then
                        MsgBox("Olá " & nome & "! És um adolescente.", MsgBoxStyle.Information, "")
                    Else
                        If idade < 32 Then
                            MsgBox("Olá " & nome & "! És um jovem.", MsgBoxStyle.Information, "")
                        Else
                            If idade < 82 Then
                                MsgBox("Olá " & nome & "! És um adulto.", MsgBoxStyle.Information, "")
                            Else
                                If idade < 101 Then
                                    MsgBox("Olá " & nome & "! És um idoso.", MsgBoxStyle.Information, "")
                                Else
                                    MsgBox("Olá " & nome & "! Tens uma idade extraordinária!", MsgBoxStyle.Information, "")
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        End
    End Sub
End Class

Sem comentários:

Enviar um comentário