×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

StrComp function- Limited Case sensitive string comparisons?

StrComp function- Limited Case sensitive string comparisons?

StrComp function- Limited Case sensitive string comparisons?

(OP)
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

RE: StrComp function- Limited Case sensitive string comparisons?


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.

RE: StrComp function- Limited Case sensitive string comparisons?

(OP)

Quote:

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

RE: StrComp function- Limited Case sensitive string comparisons?

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

RE: StrComp function- Limited Case sensitive string comparisons?

MajP, could you check my logic, please?

Works as I expected at my end....


---- Andy

There is a great need for a sarcasm font.

RE: StrComp function- Limited Case sensitive string comparisons?

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.

https://msdn.microsoft.com/en-us/library/aa266181(...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close