Im trying for a message box to pop up but this code gives me always "Absent".How can i fix this.

Dim time As Date
Dim CurrHour As Integer
Dim CurrMinute As Integer
time = DateTime.Now
CurrHour = time.Hour ' Get current hour value
CurrMinute = time.Minute ' Get current minute value

If (CurrHour = 6 AndAlso CurrMinute > 14 And CurrHour = 7 AndAlso CurrMinute < 0) Or (CurrHour = 12 AndAlso CurrMinute > 14 And CurrHour = 13 AndAlso CurrMinute < 0) Then
                        MsgBox("Late")
ElseIf (CurrHour = 4 AndAlso CurrMinute > 0 And CurrHour = 6 AndAlso CurrMinute < 15) Or (CurrHour = 11 AndAlso CurrMinute > 0 And CurrHour = 12 AndAlso CurrMinute < 15) Then
                        MsgBox("Present")
Else
                        MsgBox("Absent")
End If

How can CurrHour = 6 AND = 7 (line 8)?
How can CurrHour = 4 AND = 6 (line 10)?

These lines will always be false since you require mutually exclusive conditions to both be true for the if to be true.

Can you explain (in words) what the conditions you are trying to match? Is it something like "if the time is between x and y do this"?

i got this new method of my code.
let me know if this code is good.thanks

Dim time As Date
        Dim CurrHour As Integer
        Dim CurrMinute As Integer
        time = DateTime.Now
        CurrHour = time.Hour ' Get current hour value
        CurrMinute = time.Minute ' Get current minute value
        Dim min = CurrMinute.ToString
        Dim timeClock As String
        If CurrMinute.ToString = 0 Then
            min = "00"
            timeClock = CurrHour.ToString + "" + min
        ElseIf CurrMinute.ToString = 1 Or CurrMinute.ToString = 2 Or CurrMinute.ToString = 3 Or CurrMinute.ToString = 4 Or CurrMinute.ToString = 5 Or CurrMinute.ToString = 6 Or CurrMinute.ToString = 7 Or CurrMinute.ToString = 8 Or CurrMinute.ToString = 9 Then
            timeClock = CurrHour.ToString + "0" + min
        Else
            timeClock = CurrHour.ToString + "" + min
        End If
        If (timeClock >= 615 And timeClock <= 659) Or (timeClock >= 1215 And timeClock <= 1259) Then
            MsgBox("Late")
        ElseIf (timeClock >= 400 And timeClock <= 614) Or (timeClock >= 1100 And timeClock <= 1214) Then
            MsgBox("Present")
        Else
            MsgBox("Absent")
        End If

Time is a number and best compared as a number. Converting them to strings is going to run into problems (which comes first: "123" or "1123"?).

should i convert it to integer,instead of string?
thanks for helping :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.