Click here to Skip to main content
15,905,232 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following as an example:

01 Aug 2016 @ 14:16 as a text string in a text box. It is not formatted as a datetime field but simply as a text string. This is because of the way the users enter data into a PDF (as shown above) and that is imported as a text string...

1st thing I am trying to do is strip off the date and only have the time (14:16) and will call that "result1". I believe I have conquered that (see code below).

Then I want to take that result (14:16) and compare it to an actual formatted datetime field which contains only a time with no date, 14:00 as an example, and will call that "result3". I am looking to see if "result3" is greater (or after) "result1".

My major issue is properly getting the time only field (result3) to show just the time. It is returning the following when running via debug:
VB.NET
System.Windows.Forms.TextBox, Text: 14:00
and I need it to return only "14:00" without the "System.Windows.Forms.TextBox, Text:".

One of the two results is formatted incorrectly, I suspect, but not sure which. Should I convert result1 to a datetime string after extracting the portion I need or should I convert result3 to a text string? My thinking is both should be datetime since I am looking to see if result3 is after result1.

I'm certain this is a formatting issue but unsure how to get the datetime box (result3) to read properly and/or converting a text field (result1) to a datetime (time only) result for comparison.

Man, I hope that makes sense...

Last Request: Am I doing the CASE comparison properly?

What I have tried:

VB
Private Sub tb01Time_TextChanged(sender As Object, e As EventArgs) Handles tb01Time.TextChanged
        Dim result1 As String = tb01Time.ToString
        Dim result2 As String = LoadRight(result1, 5)

        Dim result3 As String = tbShipArriveTime.ToString

        Dim late As String

        If result3 > result2 Then
            late = "True"
        Else
            late = "False"
        End If

        Select Case tbShipArriveTime.ToString
            Case = "True" : tb01Time.BackColor = Color.Red
                tb01Time.ForeColor = Color.White
            Case Else : tb01Time.BackColor = Color.White
                tb01Time.ForeColor = Color.Black
        End Select

    End Sub
Posted
Updated 28-Aug-16 10:38am
v2

1 solution

Resolved my own problem....

I was using the wrong variable in my case - needed to put in late as my variable instead of tbShipArriveTime.
 
Share this answer
 
Comments
Patrice T 28-Aug-16 16:44pm    
Accept your own Solution to close the question.
Use Accept answer to close the question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900