Results 1 to 3 of 3

Thread: need help with Military Time conversion

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Location
    Dallas, TX
    Posts
    70

    need help with Military Time conversion

    I'm trying to get a Military Time from the user's 2 inputs
    Here is the code that works, but it's standard time.
    VB Code:
    1. Private Sub OKButton_Click()
    2.    If cboHour.Text <> "" Then
    3.       If cboMinute.Text <> "" Then
    4.          frmAlarmClock.lblSetTime.Caption = TimeSerial(Val(cboHour.Text), _
    5.          Val(cboMinute.Text), 0)
    6.          MyTime = TimeSerial(Val(cboHour.Text), Val(cboMinute.Text), 0)
    7.          frmAlarmClock.Enabled = True
    8.          frmAlarmClock.optOn.Enabled = True
    9.          frmAlarmClock.optOff.Enabled = True
    10.          Unload Me
    11.       End If
    12.    End If
    13.  
    14. End Sub

    I tried this to make it Military Time, but it gave me a Type Mismatch error. How do I take 2 numerical values (inputed by the user) and make them come out as a Military time.
    VB Code:
    1. MyTime = Format(cboHour.Text) And (cboMinute.Text), "hh:mm:ss")

    TIA

  2. #2
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    VB Code:
    1. MyTime = Format(cboHour.Text & ":" & cboMinute.Text, "hh:mm:ss")

  3. #3
    Junior Member
    Join Date
    Dec 2002
    Posts
    20
    Try using DatePart as shown below. It will give you Military Time automatically.

    Code:
        Text1.Text = DatePart("h", "3:55 PM") & ":" & DatePart("n", "3:55 PM")
    HTH
    Ancient Chinese proverb I just made up:
    Those who know the least have the most to say!

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