Jump to content

TimeOfDay (resolvido)


bioshock
 Share

Recommended Posts

O exemplo abaixo que vos mostro, é facilmente compreensível, o problema é que não consigo fazer o que digo no código..alguma solução??

   

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = TimeOfDay.Hour
        If Label1.Text >= "6:00:00" Or Label1.Text <= "11:59:59" Then
            Label2.Text = "Boa dia"
        Else
            If Label1.Text >= "12:00:00" Or Label1.Text <= "19:59:59" Then
                Label2.Text = "Boa tarde"
            Else
                If Label1.Text >= "20:00:00" Or Label1.Text <= "5:59:59" Then
                    Label2.Text = "Boa noite"
                End If
            End If
        End If
    End Sub

Obrigado

Link to comment
Share on other sites

Aqui funciona...

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = TimeOfDay.Hour
        If Label1.Text >= "6" Or Label1.Text <= "11" Then
            Label2.Text = "Bom dia"
        Else
            If Label1.Text >= "12" Or Label1.Text <= "19" Then
                Label2.Text = "Boa tarde"
            Else
                If Label1.Text >= "20" Or Label1.Text <= "5" Then
                    Label2.Text = "Boa noite"
                End If
            End If
        End If
    End Sub

Knowledge to the masses


Link to comment
Share on other sites

Não será AND em vez de OR ?

E depois o pessoal tem de se habituar a trabalhar como deve ser. Converter horas para uma string para depois comparar com string não é uma boa prática.

Tenta assim:

        Dim tspan As TimeSpan = Now.TimeOfDay
        If tspan >= New TimeSpan(6, 0, 0) AndAlso tspan <= New TimeSpan(11, 0, 0) Then
            Label1.Text = "Bom Dia"
        ElseIf tspan >= New TimeSpan(12, 0, 0) AndAlso tspan <= New TimeSpan(19, 0, 0) Then
            Label1.Text = "Boa Tarde"
        Else
            Label1.Text = "Boa Noite"
        End If
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.