home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / VISBASIC / DFINFO23 / SAMPLE.ARJ / 24TO12.FRM next >
Text File  |  1994-12-16  |  4KB  |  163 lines

  1. VERSION 2.00
  2. Begin Form Conv24To12 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "Convert 24hr to 12hr"
  6.    ClientHeight    =   2790
  7.    ClientLeft      =   1230
  8.    ClientTop       =   1800
  9.    ClientWidth     =   3975
  10.    Height          =   3195
  11.    Left            =   1170
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   2790
  14.    ScaleWidth      =   3975
  15.    Top             =   1455
  16.    Width           =   4095
  17.    Begin CommandButton btnExit 
  18.       Cancel          =   -1  'True
  19.       Caption         =   "Exit"
  20.       Height          =   375
  21.       Left            =   2520
  22.       TabIndex        =   6
  23.       Top             =   1440
  24.       Width           =   1215
  25.    End
  26.    Begin TextBox txt12Hour 
  27.       Height          =   285
  28.       Left            =   360
  29.       TabIndex        =   3
  30.       Text            =   "txt12Hour"
  31.       Top             =   2280
  32.       Width           =   1815
  33.    End
  34.    Begin TextBox txt24Hour 
  35.       Height          =   285
  36.       Left            =   360
  37.       TabIndex        =   1
  38.       Text            =   "txt24Hour"
  39.       Top             =   1680
  40.       Width           =   1815
  41.    End
  42.    Begin CommandButton btnConvert 
  43.       Caption         =   "Convert"
  44.       Default         =   -1  'True
  45.       Height          =   375
  46.       Left            =   2520
  47.       TabIndex        =   0
  48.       Top             =   1920
  49.       Width           =   1215
  50.    End
  51.    Begin Label Label3 
  52.       BackColor       =   &H00C0C0C0&
  53.       Caption         =   "This sample program shows how to convert from 24 hour time (as returned by DFInfo) to a 12 hour time format.  Enter times (well-formed) into the 24 Hour Time edit box and press Convert."
  54.       Height          =   1095
  55.       Left            =   240
  56.       TabIndex        =   5
  57.       Top             =   120
  58.       Width           =   3495
  59.    End
  60.    Begin Label Label2 
  61.       BackColor       =   &H00C0C0C0&
  62.       Caption         =   "12 Hour Time"
  63.       FontBold        =   0   'False
  64.       FontItalic      =   0   'False
  65.       FontName        =   "MS Sans Serif"
  66.       FontSize        =   8.25
  67.       FontStrikethru  =   0   'False
  68.       FontUnderline   =   0   'False
  69.       Height          =   255
  70.       Left            =   240
  71.       TabIndex        =   4
  72.       Top             =   2040
  73.       Width           =   1455
  74.    End
  75.    Begin Label Label1 
  76.       BackColor       =   &H00C0C0C0&
  77.       Caption         =   "24 Hour Time:"
  78.       FontBold        =   0   'False
  79.       FontItalic      =   0   'False
  80.       FontName        =   "MS Sans Serif"
  81.       FontSize        =   8.25
  82.       FontStrikethru  =   0   'False
  83.       FontUnderline   =   0   'False
  84.       Height          =   255
  85.       Left            =   240
  86.       TabIndex        =   2
  87.       Top             =   1440
  88.       Width           =   1455
  89.    End
  90. End
  91. Option Explicit
  92.  
  93. Sub btnConvert_Click ()
  94.     Dim TempStr As String
  95.     '
  96.     ' get the time the user entered and convert it
  97.     '
  98.     TempStr = txt24Hour
  99.     txt12Hour = Convert24To12(TempStr)
  100. End Sub
  101.  
  102. Sub btnExit_Click ()
  103.     '
  104.     ' get out
  105.     '
  106.     End
  107. End Sub
  108.  
  109. '
  110. ' this function requires the data is valid and in the
  111. ' format of HH:MM:SS.  It does no error checking.
  112. '
  113. Function Convert24To12 (TimeString As String) As String
  114.     Dim OutString As String
  115.     Dim TimeHour As Integer
  116.     '
  117.     ' get hour
  118.     '
  119.     TimeHour = Val(Left(TimeString, 2))
  120.     '
  121.     ' format first part of string, make sure 00:00:00
  122.     ' is formatted as 12:00:00
  123.     '
  124.     If (TimeHour Mod 12) = 0 Then
  125.         OutString = "12" & Mid(TimeString, 3)
  126.     Else
  127.         OutString = Format(TimeHour Mod 12, "00") & Mid(TimeString, 3)
  128.     End If
  129.     '
  130.     ' check for AM/PM
  131.     '
  132.     If TimeHour < 12 Then
  133.         OutString = OutString & " AM"
  134.     Else
  135.         OutString = OutString & " PM"
  136.     End If
  137.     '
  138.     ' return new time
  139.     '
  140.     Convert24To12 = OutString
  141. End Function
  142.  
  143. Sub Form_Load ()
  144.     Dim TempStr As String
  145.     '
  146.     ' initialize 24 hour text box
  147.     '
  148.     txt24Hour = Format(Now, "hh:mm:ss")
  149.     '
  150.     ' get 24 hour formatted time and convert it to 12 hour
  151.     '
  152.     TempStr = txt24Hour
  153.     txt12Hour = Convert24To12(TempStr)
  154. End Sub
  155.  
  156. Sub Form_Unload (Cancel As Integer)
  157.     '
  158.     ' make sure we get out
  159.     '
  160.     End
  161. End Sub
  162.  
  163.