Jump to content
Sign in to follow this  
bioshock

TimeOfDay (resolvido)

Recommended Posts

bioshock

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

Share this post


Link to post
Share on other sites
Weasel

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


Share this post


Link to post
Share on other sites
jpaulino

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • 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.