title: vb6 Compare times in list with current time
body: <p>I'm making form where i need to enter the time's for each period like.</p>
  <ol>
  <li>Start time - End time</li>
  <li>Start time - End time</li>
  <li>Start time - End time</li>
  </ol>
  <p>Those record's could be saved in listbox as in my example. On another form i have 3 labels
  CurrentTime, TimePassed, TimeLeft, and a Timer which ticks in interval 1second. So the time in timepassed ticking up, time left ticking down, and current time show correct time while application is opened.</p>
  <p>In final it looks like this</p>
  <p><img src="https://i.stack.imgur.com/uNMwh.jpg" alt="enter image description here" /></p>
  <pre><code>Private Sub cmdAdd_Click()
  Call addp
  End Sub
  
  Function addp(Optional ByVal t As String)
  Dim s As String, e As String
  If t = &quot;&quot; Then s = Trim(InputBox(&quot;Start time (hh:mm AM/PM):&quot;)) Else: s = Trim(Split(t, &quot;-&quot;)(0))
  If s = &quot;&quot; Or InStr(1, s, &quot; AM&quot;) = 0 And InStr(1, s, &quot; PM&quot;) = 0 Then Exit Function
  If chk(s) = False Then Exit Function
  If t = &quot;&quot; Then e = Trim(InputBox(s &amp; &quot;-?&quot; &amp; vbCrLf &amp; &quot;End time:&quot;)) Else: e = Trim(Split(t, &quot;-&quot;)(1))
  If e = &quot;&quot; Or InStr(1, e, &quot; AM&quot;) = 0 And InStr(1, e, &quot; PM&quot;) = 0 Then Exit Function
  If e = s Then Exit Function
  If chk(e) = False Then Exit Function
  If Format$(Split(s, &quot;-&quot;)(0), &quot;hh:mm AM/PM&quot;) &gt; Format$(Split(e, &quot;-&quot;)(0), &quot;hh:mm AM/PM&quot;) Then Exit Function
  If lstPeriods.List(0) &lt;&gt; &quot;&quot; Then
  If Format$(Split(lstPeriods.List(lstPeriods.ListCount - 1), &quot;-&quot;)(1), &quot;hh:mm AM/PM&quot;) &gt; Format$(Split(s, &quot;-&quot;)(0), &quot;hh:mm AM/PM&quot;) Then Exit Function
  End If
  lstPeriods.AddItem lstPeriods.ListCount + 1 &amp; &quot;. &quot; &amp; s &amp; &quot;-&quot; &amp; e
  If frmMain.lblPeriod.Caption = &quot;&quot; Then Call snd(s &amp; &quot;-&quot; &amp; e, lstPeriods.ListCount)
  End Function
  </code></pre>
  <p>For check</p>
  <pre><code>Function chk(ByVal st As String) As Boolean
  st = Replace$(Replace$(st, &quot; AM&quot;, &quot;&quot;), &quot; PM&quot;, &quot;&quot;)
  If UBound(Split(st, &quot;:&quot;)) &lt;&gt; 1 Then Exit Function
  For i = 0 To 1
  If IsNumeric(Split(st, &quot;:&quot;)(i)) = False Then Exit Function
  If Len(Split(st, &quot;:&quot;)(i)) &lt;&gt; 2 Then Exit Function
  If Split(st, &quot;:&quot;)(i) &lt; 0 Then Exit Function
  Next
  If Split(st, &quot;:&quot;)(0) &gt; 12 Then Exit Function
  If Split(st, &quot;:&quot;)(1) &gt; 59 Then Exit Function
  chk = True
  End Function
  </code></pre>
  <p>The solution i gave is the only solution which beginner as i I had. And i know it's confusing and very slow. There is no way this can be finished by using trim/split/format because it require for a lot of modification.</p>
  <p>Searching for easier solution.</p>
  <p>Sp i need to compare the current time on computer with the time person enetered in textbox/listbox how can i do that .</p>