0

I don't get what's going on. The method equals doesn't work, and neither comparing the strings with the '=' operator or with 'string.compare'. thetruth is always set as "false".

Public Function ProcessLabel(myValue As Object) As String
    If ((myValue Is DBNull.Value) = False) Then
        Dim thetruth As Boolean
        Dim myValueStr As String
        myValueStr = CStr(myValue)
        thetruth = String.Equals(myValueStr, "01/01/1900")
    End If
    Return myValue.ToString
End Function

I cannot attach images but I assure you, in myValueStr I have "01/01/1900".

1
  • Provide an example about how you call this function, and take a look at your return line .. it is not logical. Commented May 12, 2015 at 7:36

1 Answer 1

1

I'm pretty sure that myValue is a Date object and not a string and that a database is involved where the minimum value is 01/01/1900, for example the SMALLDATETIME datatype. If you look at it in debugger you see it like 01/01/1900. But if you execute ToString( internally used on CStr(myValue)) you get the localized representation including the time portion, so something like 01.01.1900 00:00:00 (f.e. in germany).

Instead compare the right types:

If Not myValue Is DBNull.Value AndAlso Not myValue Is Nothing Then
    Dim date = DirectCast(myValue, Date)
    If date = New Date(1900, 01, 01) Then 

    End If
End If
Sign up to request clarification or add additional context in comments.

2 Comments

I'm pretty sure that the problem is with the time as you say, still the solution you've proposed doesn't work. I've also tried to convert the date with ToShortDateString(), but again it fails when comparing with the string "01/01/1900".
@NicolaNonnis: ToShortDateString also converts the date to a LOCALIZED string representation. And you can use ToShortDateString on dates only not on strings. So you have to cast or convert it to Date before you can use that method. But don't compare strings but the real type. What doesn't work, can you cast it to Date? Have you used the debugger? What is the value of date at the line If date = New Date(1900, 01, 01) Then? Set a breakpoint there and expect the value in the quick watch window.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.