+ Reply to Thread
Results 1 to 11 of 11

Insufficient Time Error Handling

  1. #1
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Insufficient Time Error Handling

    I have a userform textbox ("wo_lts_time" in which the user is to enter a valid time. The event exit code is below:

    Please Login or Register  to view this content.
    I use this custom function to determine the appropriateness of the value entered by the user:
    Please Login or Register  to view this content.
    In my testing, I'm discovering that if a user enters gibberish ... "fdjfhdsgfdf" in this textbox, the function identifies an inappropriate date value entered and displays the error message. However, the code proceeds and errs in the line in red. "type mismatch".

    Type mismatch indeed ... the line is looking for a timevalue (which can't happen with the text value submitted) to compare. I've already built in a check to detour the code when this procedure carries with it a blank value.

    I am weak in my coding skills. Can someone suggest how I can identify and react appropriately to any value encountered that isn't a time value?

    Jenn

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Insufficient Time Error Handling

    Maybe ...

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Insufficient Time Error Handling

    Just as guess, but why don't you re-write your functions as so:

    Please Login or Register  to view this content.
    Then with:

    Please Login or Register  to view this content.
    You can add something like:

    Please Login or Register  to view this content.
    Or whatever you need.

  4. #4
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Insufficient Time Error Handling

    Thank you kindly SHG for making the necessary repair with my code. I struggled for quite some time with this. I appreciate your support.
    With this same code, when it errs with "Lights unnecessary..." , the wo_lts_time.SetFocus is intented to take the user back to that textbox to reenter another time. Do you have any suggestion as to why it's not?

    Jenn

  5. #5
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Insufficient Time Error Handling

    Hey StevenM, I acknowledge your suggestion, and extend my thanks to you as well for your contribution. Every suggestion, whether applied or not, is a valuable learning opportunity for me. Thanks again!

    Jenn

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Insufficient Time Error Handling

    Dunno. Maybe ...

    Please Login or Register  to view this content.
    Last edited by shg; 05-06-2012 at 02:59 PM.

  7. #7
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Insufficient Time Error Handling

    Once again, thank you SHG.

    I'm run into a problem with the arithmetic of the time.

    Consider the final code revision you provided. As we step through the code and gather the values of the different variables.

    sunset = 0.8500000000000
    lghtson = 0.82959 (0.8500000000000(sunset) - 0.02041(30 minutes))
    wo_lts_time = "7:54 pm" (lghtson)
    varhold.range("A12") = .82959

    From your code:
    dtime = 0.829166666666667

    An IF then statement compares dtime (0.829166666666667) to the value of varhold.range("A12") ... .82959. The h:mm am/pm value theoretically are equal ... 7:54PM.

    However, with this code, the IF/THEN statement triggers the "Lights unnecessary before 30mins prior to sunset." error as dtime is less than 0.82959.

    Despite the h:mm am/pm value being the same, it has two different numerical values causing undesireable results.

    How best I overcome this?
    Last edited by Jenn68; 05-06-2012 at 04:50 PM.

  8. #8
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Insufficient Time Error Handling

    I'm run into a problem with the arithmetic of the time.

    Consider the final code revision you provided. As we step through the code and gather the values of the different variables.

    sunset = 0.8500000000000
    lghtson = 0.82959 (0.8500000000000(sunset) - 0.02041(30 minutes))
    wo_lts_time = "7:54 pm" (lghtson)
    varhold.range("A12") = .82959

    From your code:
    dtime = 0.829166666666667

    An IF then statement compares dtime (0.829166666666667) to the value of varhold.range("A12") ... .82959. The h:mm am/pm value theoretically are equal ... 7:54PM.

    However, with this code, the IF/THEN statement triggers the "Lights unnecessary before 30mins prior to sunset." error as dtime is less than 0.82959.

    Despite the h:mm am/pm value being the same, it has two different numerical values causing undesireable results.

    How best I overcome this?

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Insufficient Time Error Handling

    Round both times to the nearest minute or second?

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Insufficient Time Error Handling

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Insufficient Time Error Handling

    Yeah! I think that did the trick. I didn't think you could do that ...
    I think it works.

    Please Login or Register  to view this content.
    Thank you SHG!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1