Home All Groups Group Topic Archive Search About

Case Sensitive Comparison

Author
17 Mar 2006 7:18 PM
Elena
I'm trying to compare two pieces of text.  If the cases are different, I want
it to be the same as if the text were different.  I tried doing a binary
compare, but it's not working.

Does anyone have any suggestions?  My code is below.

Thanks in Advanced,
Elena

Option Compare Binary

Imports System.Data.OleDb
Public Class CDRLValidation
    Inherits System.Windows.Forms.Form
    Dim strsql As String

    'connection for debugging
    Public Shared conStr As String = "Provider=Microsoft.JET.OLEDB.4.0;data
source=C:\CDRL.mdb"
    ' Create connection object
    Public Shared conn As OleDbConnection = New OleDbConnection(conStr)

    Private Sub CDRLValidation_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
        Call Clearform()

    End Sub
    Private Sub Clearform()
        TextBox1.Text = ""
        TextBox2.Text = ""
        ' The password character is an asterisk.
        TextBox2.PasswordChar = "*"


    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        strsql = "Select * from Login where user_name  = '" & TextBox1.Text
& "' and user_pass = '" & TextBox2.Text & "'"
        Debug.Write(strsql)
        Dim cmd1 As New OleDbCommand(strsql, conn)
        conn.Open()
        Dim daUser As New OleDbDataAdapter(cmd1)
        Dim dsUser As New DataSet
        daUser.Fill(dsUser, "Login")
        conn.Close()

        Dim intCount As Integer = dsUser.Tables(0).Rows.Count
        If intCount = 0 Then
            MsgBox("User Name/Password does not exisist. Please, try again.")
            Call Clearform()
        End If
        If intCount = 1 Then
            Dim strChange As String =
dsUser.Tables(0).Rows(0)("user_pass").ToString
            If strChange = "userPass" = True Then
                Debug.Write(strChange)
                Dim ChangePrompt As New ChangePrompt
                ChangePrompt.ShowDialog()

            Else
                Dim CDRLSelect As New CDRLSelect
                CDRLSelect.ShowDialog()
            End If


        End If

    End Sub
End Class

Author
17 Mar 2006 7:32 PM
Armin Zingler
"Elena" <El***@discussions.microsoft.com> schrieb
> I'm trying to compare two pieces of text.  If the cases are
> different, I want it to be the same as if the text were different.
> I tried doing a binary compare, but it's not working.
>
> Does anyone have any suggestions?  My code is below.

I have no clue where you are comparing and I can not know what the values of
the variables are. So, it's impossible to say from here.


Armin
Author
17 Mar 2006 7:46 PM
Elena
ok, let me change the code a little.

If strChange = "userPass" = True Then
msgbox("True.")
Else
msgbox("False.")
End if

let's pretend that strChange = USERPASS

So, i'm comparing USERPASS to userPass.  The message box that pops up should
say "False."  Unfortunately, it doesn't.  It says true.  So, I'd like to know
how to compare these two things and when the case is different that it reads
it as false.

Elena

Show quoteHide quote
"Armin Zingler" wrote:

> "Elena" <El***@discussions.microsoft.com> schrieb
> > I'm trying to compare two pieces of text.  If the cases are
> > different, I want it to be the same as if the text were different.
> > I tried doing a binary compare, but it's not working.
> >
> > Does anyone have any suggestions?  My code is below.
>
> I have no clue where you are comparing and I can not know what the values of
> the variables are. So, it's impossible to say from here.
>
>
> Armin
>
>
Author
17 Mar 2006 8:36 PM
VHD50
You need to remove the part "= True" in your If statement, otherwise it
always returns true (because you intentionally set it to True).
So this should work as you expect:
If strChange = "userPass" Then
msgbox("True.")
Else
msgbox("False.")
End if

Hope this helps.
VHD50


Show quoteHide quote
"Elena" wrote:

> ok, let me change the code a little.
>
> If strChange = "userPass" = True Then
> msgbox("True.")
> Else
> msgbox("False.")
> End if
>
> let's pretend that strChange = USERPASS
>
> So, i'm comparing USERPASS to userPass.  The message box that pops up should
> say "False."  Unfortunately, it doesn't.  It says true.  So, I'd like to know
> how to compare these two things and when the case is different that it reads
> it as false.
>
> Elena
>
> "Armin Zingler" wrote:
>
> > "Elena" <El***@discussions.microsoft.com> schrieb
> > > I'm trying to compare two pieces of text.  If the cases are
> > > different, I want it to be the same as if the text were different.
> > > I tried doing a binary compare, but it's not working.
> > >
> > > Does anyone have any suggestions?  My code is below.
> >
> > I have no clue where you are comparing and I can not know what the values of
> > the variables are. So, it's impossible to say from here.
> >
> >
> > Armin
> >
> >
Author
17 Mar 2006 9:09 PM
Armin Zingler
Show quote Hide quote
"Elena" <El***@discussions.microsoft.com> schrieb
> ok, let me change the code a little.
>
> If strChange = "userPass" = True Then
> msgbox("True.")
> Else
> msgbox("False.")
> End if
>
> let's pretend that strChange = USERPASS
>
> So, i'm comparing USERPASS to userPass.  The message box that pops
> up should say "False."  Unfortunately, it doesn't.  It says true.
> So, I'd like to know how to compare these two things and when the
> case is different that it reads it as false.
>
> Elena


I tried it and it says "False.":

      Dim strChange As String = "USERPASS"

      If strChange = "userPass" = True Then
         MsgBox("True.")
      Else
         MsgBox("False.")
      End If


The "= True" is not necessary but it doesn't change anything in this case.
It's like saying "if it is true that it is true then".


Armin
Author
17 Mar 2006 9:18 PM
Elena
Ok, I removed the = True, but it's still not working.  Any other suggestions?




Show quoteHide quote
"Armin Zingler" wrote:

> "Elena" <El***@discussions.microsoft.com> schrieb
> > ok, let me change the code a little.
> >
> > If strChange = "userPass" = True Then
> > msgbox("True.")
> > Else
> > msgbox("False.")
> > End if
> >
> > let's pretend that strChange = USERPASS
> >
> > So, i'm comparing USERPASS to userPass.  The message box that pops
> > up should say "False."  Unfortunately, it doesn't.  It says true.
> > So, I'd like to know how to compare these two things and when the
> > case is different that it reads it as false.
> >
> > Elena
>
>
> I tried it and it says "False.":
>
>       Dim strChange As String = "USERPASS"
>
>       If strChange = "userPass" = True Then
>          MsgBox("True.")
>       Else
>          MsgBox("False.")
>       End If
>
>
> The "= True" is not necessary but it doesn't change anything in this case.
> It's like saying "if it is true that it is true then".
>
>
> Armin
>
>
Author
18 Mar 2006 8:00 AM
Cor Ligthert [MVP]
> Ok, I removed the = True, but it's still not working.  Any other
> suggestions?
>
Read the answer from Armin

Cor


Show quoteHide quote
>
>
>
> "Armin Zingler" wrote:
>
>> "Elena" <El***@discussions.microsoft.com> schrieb
>> > ok, let me change the code a little.
>> >
>> > If strChange = "userPass" = True Then
>> > msgbox("True.")
>> > Else
>> > msgbox("False.")
>> > End if
>> >
>> > let's pretend that strChange = USERPASS
>> >
>> > So, i'm comparing USERPASS to userPass.  The message box that pops
>> > up should say "False."  Unfortunately, it doesn't.  It says true.
>> > So, I'd like to know how to compare these two things and when the
>> > case is different that it reads it as false.
>> >
>> > Elena
>>
>>
>> I tried it and it says "False.":
>>
>>       Dim strChange As String = "USERPASS"
>>
>>       If strChange = "userPass" = True Then
>>          MsgBox("True.")
>>       Else
>>          MsgBox("False.")
>>       End If
>>
>>
>> The "= True" is not necessary but it doesn't change anything in this
>> case.
>> It's like saying "if it is true that it is true then".
>>
>>
>> Armin
>>
>>
Author
20 Mar 2006 3:06 PM
Elena
I did read it, and it's not working for me.

Show quoteHide quote
"Cor Ligthert [MVP]" wrote:

> > Ok, I removed the = True, but it's still not working.  Any other
> > suggestions?
> >
> Read the answer from Armin
>
> Cor
>
>
> >
> >
> >
> > "Armin Zingler" wrote:
> >
> >> "Elena" <El***@discussions.microsoft.com> schrieb
> >> > ok, let me change the code a little.
> >> >
> >> > If strChange = "userPass" = True Then
> >> > msgbox("True.")
> >> > Else
> >> > msgbox("False.")
> >> > End if
> >> >
> >> > let's pretend that strChange = USERPASS
> >> >
> >> > So, i'm comparing USERPASS to userPass.  The message box that pops
> >> > up should say "False."  Unfortunately, it doesn't.  It says true.
> >> > So, I'd like to know how to compare these two things and when the
> >> > case is different that it reads it as false.
> >> >
> >> > Elena
> >>
> >>
> >> I tried it and it says "False.":
> >>
> >>       Dim strChange As String = "USERPASS"
> >>
> >>       If strChange = "userPass" = True Then
> >>          MsgBox("True.")
> >>       Else
> >>          MsgBox("False.")
> >>       End If
> >>
> >>
> >> The "= True" is not necessary but it doesn't change anything in this
> >> case.
> >> It's like saying "if it is true that it is true then".
> >>
> >>
> >> Armin
> >>
> >>
>
>
>
Author
20 Mar 2006 3:50 PM
Cor Ligthert [MVP]
Elena,

Can you make a simple project with only those simple statements in the form
load event of it.
Than if it does not work, show it to us

Cor


Show quoteHide quote
"Elena" <El***@discussions.microsoft.com> schreef in bericht
news:C6E0D052-992F-4D5A-9986-A7AD33D3EF16@microsoft.com...
>
> I did read it, and it's not working for me.
>
> "Cor Ligthert [MVP]" wrote:
>
>> > Ok, I removed the = True, but it's still not working.  Any other
>> > suggestions?
>> >
>> Read the answer from Armin
>>
>> Cor
>>
>>
>> >
>> >
>> >
>> > "Armin Zingler" wrote:
>> >
>> >> "Elena" <El***@discussions.microsoft.com> schrieb
>> >> > ok, let me change the code a little.
>> >> >
>> >> > If strChange = "userPass" = True Then
>> >> > msgbox("True.")
>> >> > Else
>> >> > msgbox("False.")
>> >> > End if
>> >> >
>> >> > let's pretend that strChange = USERPASS
>> >> >
>> >> > So, i'm comparing USERPASS to userPass.  The message box that pops
>> >> > up should say "False."  Unfortunately, it doesn't.  It says true.
>> >> > So, I'd like to know how to compare these two things and when the
>> >> > case is different that it reads it as false.
>> >> >
>> >> > Elena
>> >>
>> >>
>> >> I tried it and it says "False.":
>> >>
>> >>       Dim strChange As String = "USERPASS"
>> >>
>> >>       If strChange = "userPass" = True Then
>> >>          MsgBox("True.")
>> >>       Else
>> >>          MsgBox("False.")
>> >>       End If
>> >>
>> >>
>> >> The "= True" is not necessary but it doesn't change anything in this
>> >> case.
>> >> It's like saying "if it is true that it is true then".
>> >>
>> >>
>> >> Armin
>> >>
>> >>
>>
>>
>>
Author
20 Mar 2006 6:45 PM
Elena
I figured out the problem.  The binary compare works.  You were right, Armin.
Yet, now I need to do a string comparison of the same two variables.  Is it
possible to do a string and binary compare in the same form?  If so, how do i
differentiate the two?


Thanks in Advance,
Elena


Show quoteHide quote
"Cor Ligthert [MVP]" wrote:

> Elena,
>
> Can you make a simple project with only those simple statements in the form
> load event of it.
> Than if it does not work, show it to us
>
> Cor
>
>
> "Elena" <El***@discussions.microsoft.com> schreef in bericht
> news:C6E0D052-992F-4D5A-9986-A7AD33D3EF16@microsoft.com...
> >
> > I did read it, and it's not working for me.
> >
> > "Cor Ligthert [MVP]" wrote:
> >
> >> > Ok, I removed the = True, but it's still not working.  Any other
> >> > suggestions?
> >> >
> >> Read the answer from Armin
> >>
> >> Cor
> >>
> >>
> >> >
> >> >
> >> >
> >> > "Armin Zingler" wrote:
> >> >
> >> >> "Elena" <El***@discussions.microsoft.com> schrieb
> >> >> > ok, let me change the code a little.
> >> >> >
> >> >> > If strChange = "userPass" = True Then
> >> >> > msgbox("True.")
> >> >> > Else
> >> >> > msgbox("False.")
> >> >> > End if
> >> >> >
> >> >> > let's pretend that strChange = USERPASS
> >> >> >
> >> >> > So, i'm comparing USERPASS to userPass.  The message box that pops
> >> >> > up should say "False."  Unfortunately, it doesn't.  It says true.
> >> >> > So, I'd like to know how to compare these two things and when the
> >> >> > case is different that it reads it as false.
> >> >> >
> >> >> > Elena
> >> >>
> >> >>
> >> >> I tried it and it says "False.":
> >> >>
> >> >>       Dim strChange As String = "USERPASS"
> >> >>
> >> >>       If strChange = "userPass" = True Then
> >> >>          MsgBox("True.")
> >> >>       Else
> >> >>          MsgBox("False.")
> >> >>       End If
> >> >>
> >> >>
> >> >> The "= True" is not necessary but it doesn't change anything in this
> >> >> case.
> >> >> It's like saying "if it is true that it is true then".
> >> >>
> >> >>
> >> >> Armin
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>
Author
20 Mar 2006 7:07 PM
Armin Zingler
"Elena" <El***@discussions.microsoft.com> schrieb
> I figured out the problem.  The binary compare works.  You were
> right, Armin. Yet, now I need to do a string comparison of the same
> two variables.  Is it possible to do a string and binary compare in
> the same form?  If so, how do i differentiate the two?


Sorry, I don't understand. You mean Option Compare Text and Option Comapre
Binary within the same file? I don't know, I've never used Option Compare
Text.



Armin
Author
18 Mar 2006 12:58 PM
Herfried K. Wagner [MVP]
"Elena" <El***@discussions.microsoft.com> schrieb:
> I'm trying to compare two pieces of text.  If the cases are different, I
> want
> it to be the same as if the text were different.  I tried doing a binary
> compare, but it's not working.

Did you try 'Option Compare Binary', 'StrCmp'/'String.Compare'?

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
20 Mar 2006 2:55 PM
Elena
It's set to Option Compar Binary, but I have not used the string.compare. 
Let me see if I can figure out that code.

Thanks,
Elena

Show quoteHide quote
"Herfried K. Wagner [MVP]" wrote:

> "Elena" <El***@discussions.microsoft.com> schrieb:
> > I'm trying to compare two pieces of text.  If the cases are different, I
> > want
> > it to be the same as if the text were different.  I tried doing a binary
> > compare, but it's not working.
>
> Did you try 'Option Compare Binary', 'StrCmp'/'String.Compare'?
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://classicvb.org/petition/>
>
>