By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,676 Members | 1,236 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,676 IT Pros & Developers. It's quick & easy.

Case Sensitive Comparison

P: n/a
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
Mar 17 '06 #1
Share this Question
Share on Google+
12 Replies


P: n/a
"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

Mar 17 '06 #2

P: n/a
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

Mar 17 '06 #3

P: n/a
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
"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

Mar 17 '06 #4

P: n/a
"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

Mar 17 '06 #5

P: n/a
Ok, I removed the = True, but it's still not working. Any other suggestions?


"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

Mar 17 '06 #6

P: n/a
> 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

Mar 18 '06 #7

P: n/a
"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/>

Mar 18 '06 #8

P: n/a
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

"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/>

Mar 20 '06 #9

P: n/a

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


Mar 20 '06 #10

P: n/a
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:C6**********************************@microsof t.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
>>
>>


Mar 20 '06 #11

P: n/a
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
"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:C6**********************************@microsof t.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
>>
>>


Mar 20 '06 #12

P: n/a
"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

Mar 20 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.