Results 1 to 6 of 6

Thread: [RESOLVED] Between Two Times...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Canada
    Posts
    297

    Resolved [RESOLVED] Between Two Times...

    Hi guys..

    I'm looking to have my program have a night, and day mode.. It pulls in the almanac every time it loads, and I'd like to have it so that when the "Sunrise"'s the program will be in day mode, and when the "Sunset"'s it will go in to night mode..

    Is there a way I can say something like:

    If time now is between sunrise.Text and Sunset.Text then mode = day
    Else
    mode = night

    How do I actually write this?

  2. #2
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Between Two Times...

    Code:
    If Time >= TimeValue(Sunrise.Text) And Time <= TimeValue(Sunset.Text) Then
       mode = day
    Else
       mode = night
    End If
    Make sure Sunrise.Text and Sunset.Text have valid time format values.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Canada
    Posts
    297

    Re: Between Two Times...

    You rock! Thank you!

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Canada
    Posts
    297

    Re: [RESOLVED] Between Two Times...

    I'm getting a "Type Mismatch"

    Line:
    Code:
    If Time >= TimeValue(sunup.Caption) And Time <= TimeValue(sundown.Caption) Then

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Canada
    Posts
    297

    Re: [RESOLVED] Between Two Times...

    I think it might involve that sunup.Caption simply reads "6:45"... Can I get my time from a label instead of the generic time?

  6. #6
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: [RESOLVED] Between Two Times...

    Code:
    ?Timevalue("6:45")
    6:45:00 AM 
    ?Timevalue("17:25")
    5:25:00 PM
    An alternative way:
    Code:
    Select Case TimeValue(Label1.Caption)
        Case Is < TimeValue(sunup.Caption), Is > TimeValue(sundown.Caption)
            mode = night
        Case Else
            mode = day
    End Select
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width