vb.netif-statement

VB6 and VB.net has different outcomes with the same IF statements


I have the below IF statements tried on both VB6 and VB.net

Dim str As String = ","

If str = "," Or str = "," Or str = """" Then
   'execute A
End If

When the str value is "," (a full-width comma), on VB6 A does not get executed while on VB.net it goes into the IF statement and executes A.

The weird thing here is when I put this statement on watch when str = ",", 「 str = "," Or str = "," Or str = """" 」 it returns false, but still goes in the IF statement to execute A.

Does anyone has a clue to as to why this is happening?

I have tried changing from Or to orElse, and made sure the Option Explicit On is there but its still the same result. Im still new to VB.net so i might lack some foundation, so any help is greatly appreciated.

Edit : I added the str value on the code sample


Solution

  • Option Compare Text will cause this.

    Option Compare Text
    
    Imports System
                    
    Public Module Demo
        Public Sub Main()
            Console.WriteLine("," = ",")
        End Sub
    End Module
    

    True

    (see demo)

    You should unset it at the project level.