Case Sensitive Comparison

G

Guest

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
 
A

Armin Zingler

Elena said:
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
 
G

Guest

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
 
G

Guest

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
 
A

Armin Zingler

Elena said:
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
 
H

Herfried K. Wagner [MVP]

Elena said:
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'?
 
G

Guest

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
 
C

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
 
G

Guest

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
 
A

Armin Zingler

Elena said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top