Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Location
    U.S.
    Posts
    12

    Unanswered: Create a time value from two integers

    I want to take two integers representing hours and minutes, and create a formatted time. For example, given 5 and 7, I want to display "5:07 AM"

    What's wrong with this code?
    Code:
    Dim H, M as Integer
    Dim S as String
    Dim D as Date
    S = "#" & Str(H) & ":" & Str(M) & "#"
    D = Format (S,"Medium Time")
    I get a type mismatch error.

    In reality, the values of H and M are not explicitly declared as integers, but instead are the .Value properties of two ComboBoxes whose .RowSourceType is set to ValueList and whose .Rowsource is a list of integers (00-23 for the hours, 00-59 for the minutes).

    Thanks --Andy

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713

    Re: Create a time value from two integers

    Originally posted by AJS
    I want to take two integers representing hours and minutes, and create a formatted time. For example, given 5 and 7, I want to display "5:07 AM"

    What's wrong with this code?
    Code:
    Dim H, M as Integer
    Dim S as String
    Dim D as Date
    S = "#" & Str(H) & ":" & Str(M) & "#"
    D = Format (S,"Medium Time")
    I get a type mismatch error.

    In reality, the values of H and M are not explicitly declared as integers, but instead are the .Value properties of two ComboBoxes whose .RowSourceType is set to ValueList and whose .Rowsource is a list of integers (00-23 for the hours, 00-59 for the minutes).

    Thanks --Andy
    Combobox values are strings... Even if the combobox is based on a table or query with numeric columns the value returned from the combobox is a string. So, you error is trying to convert a string into a string which is verboten.

  3. #3
    Join Date
    Feb 2004
    Location
    U.S.
    Posts
    12

    Re: Create a time value from two integers

    Originally posted by M Owen
    Combobox values are strings... Even if the combobox is based on a table or query with numeric columns the value returned from the combobox is a string. So, you error is trying to convert a string into a string which is verboten.
    Okay, my bad. I got rid of the str() functions. But I'm still confused...
    Now I've got a string containing a date/time format set between pound signs, so how do I "unstring" the string in order to assign the expression #05:07# to a variable of type date, so that I can manipulate it as a date/time?

    In other words:
    Code:
    Dim MyStr as String
    Dim MyTime as Date
    Dim ResultStr as String
    
    MyStr = "#05:07#"
    MyTime = WhatFunction?( MyStr )
    ResultStr = Format (MyTime, "Medium Time")
    How do I make the conversion in the next to last line?

  4. #4
    Join Date
    Feb 2004
    Location
    U.S.
    Posts
    12

    Re: Create a time value from two integers

    I figured it out on my own after playing around with it for a while.

    The answer is, don't use the pound signs. Like this:
    Code:
    Dim MyTime as Date
    MyTime = HoursCombobox.Value & ":" & MinutesCombobox.Value
    But thanks, M Owen, for replying and setting me straight on the .Value property always being a string. Cheers.

    --Andy

Posting Permissions

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