Link to home
Start Free TrialLog in
Avatar of gjpitt
gjpitt

asked on

Morning, Afternoon and Evening using VB.net

I must have lost hte plot this morning 'cos I can't remember how to do this simple task:)

A web page using vb.net needs to welcome the user with Good Morning, Good Afternoon or Good Evening and place it in Label1.text

Please help

Graham
Avatar of cyberdevil67
cyberdevil67

Hi gjpitt,

   Hmmm, would check now() > 12.000am < 12:00pm then good morning...

   Or if now() >12:00pm and less than 6:00 pm then good afternooon
   or if now() > 6:00 pm and less than 12:00 am then good evening

   not work?

Cheers!
Avatar of gjpitt

ASKER

That is roughly what I began with but the If statement doesn't like the format of the times

I've tried...

"00:00", "#00:00", "#00:00#"
"00:00:00", "#00:00:00", "#00:00:00#"

             Dim strDaySection As String
            Dim tmpTime As DateTime

            tmpTime = Now()
            If (tmpTime > "00:00" And tmpTime < "18:00") Then
                strDaySection = "Good Morning"
            Else
                If (tmpTime > "12:00" And tmpTime < "18:00") Then
                    strDaySection = "Good Afternoon"
                Else
                    If (tmpTime > "18:00" And tmpTime < "23:59:59") Then
                        strDaySection = "Good Evening"
                    End If
                End If
            End If
            Label1.Text = strDaySection
SOLUTION
Avatar of jong3
jong3

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gjpitt

ASKER

jong3: Valid point and helpful towards solution

Rejojohny: helpful but always produce Good Morning

cyberdevil67:
        Dim tmpTime As DateTime
        tmpTime = Now()

        Select Case tmpTime.Hour
            Case Is > "00"
                Label1.Text = "Good Morning"
            Case Is > "12"
                Label1.Text = "Good Afternoon"
            Case Is > "18"
                Label1.Text = "Good Evening"

        End Select

All: Using Select always chooses Good Morning I think because it is not working through the list of cases but just choosing the first match.  Going to try if..theen..else to se what happens

No you need to checif its between certain times

 if tmptime > 00 and < 12 then good morning
if timtime >12 and < 6 then good afternoon

etc.
Avatar of gjpitt

ASKER

This is the solution that works:)  

     Dim tmpTime As Integer
        tmpTime = Now().Hour

        If tmpTime > 0 And tmpTime < 12 Then
            Label1.Text = "Good Morning"
        Else
            If tmpTime > 12 And tmpTime < 18 Then
                Label1.Text = "Good Afternoon"
            Else
                If tmpTime > 18 And tmpTime < 0 Then
                    Label1.Text = "Good Evening"
                End If
            End If
        End If

and as you all contributed I'll splits the points accordingly.

Thanks everyone
Graham
did u change the system time?? else it will always showing good morning .. based on the current system time ... i have tried it and it worked ...
Avatar of gjpitt

ASKER

My system time should have produced Good Afternoon - it didn't sorry.
So if you do
MessageBox.Show(tmpTime)

What does this say?
Guys,

btw - You do Not Have to have to check between certain times.
All you have to do is reverse order the checking that you had:

Case Is > 18
       'good evening
Case Is > 12
     'good afternoon
Case Else
    'good morning