Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

StrComp function- Limited Case sensitive string comparisons? 1

Status
Not open for further replies.

irethedo

Technical User
Feb 8, 2005
429
US
I have a question about Case sensitive string comparisons...

I have a form with a text box called OldPWD that I entered "Test" into and with the code below I am
comparing this to "test" and the result is 0 which indicates that they are equal.

If I enter "TEST" (all caps) into the OldPWD text box then I get a result of -1

I am getting the impression that the strComp function can only compare case sensitivity text
as either fully upper case versus fully lower case...

I first tried " If OldPWD <> "test" and that compare also resulted in True...

Is there a way to test for any differences in case sensitive letters between two strings.

Code:
Private Sub Command3_Click()
Dim stcmp As Integer

stcmp = StrComp(Me.OldPWD, "test", 0)

End Sub

thanks
 

Code:
If Me.OldPWD = "test" Then
    MsgBox "Your OldPWD is 'test'"
Else
    MsgBox "Your OldPWD is NOT 'test'"
End If


---- Andy

There is a great need for a sarcasm font.
 
Andrzejek (Programmer)13 Dec 17 17:45
Code:
 If Me.OldPWD = "test" Then 
MsgBox "Your OldPWD is 'test'" 
Else 
MsgBox "Your OldPWD is NOT 'test'" 
End If

Hi Andy

I just tried your code, and found that if "Test" is placed in Me.OldPWD then the Message Box= "Your OldPWD is 'test'"
and if if "TEST" is placed in Me.OldPWD then the Message Box= "Your OldPWD is 'test'"

I am looking for a way that can determine if each letter in a string matches the case...

thanks
 
I think you are interpretting -1,0 incorrectly. That is not true and false.

If StrComp returns
string1 is less than string2: -1
string1 is equal to string2: 0
string1 is greater than string2: 1
string1 or string2 is Null: Null

Test
Code:
Public Sub Compare()
  Dim x As String
  Dim y As String
  Dim z As String
  x = "Test"
  y = "TEST"
  z = "test"
  Debug.Print StrComp(x, y, vbBinaryCompare)
  Debug.Print StrComp(x, z, vbBinaryCompare)
  Debug.Print StrComp(y, z, vbBinaryCompare)
  Debug.Print StrComp(x, x, vbBinaryCompare)
End Sub
resutlts:
1 'Test > TEST
-1 'Test < test
-1 'Test < test
0 ' Test = Test
All results are correct
 
MajP, could you check my logic, please?

Works as I expected at my end....


---- Andy

There is a great need for a sarcasm font.
 
Andy. You are both right depending what is at the top of your module
Code:
option Compare Database

Public Event HelloWorld()
Public Sub Command5_Click()
  Debug.Print Me.TextOne = "Test"
End Sub
True

Option Binary or no option you get false.
You have nothing or binary and he has compare database.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top