Solved

How to compare two string commands against each other to see if they are the same

Posted on 2006-07-19
4
192 Views
Last Modified: 2010-04-30
Hi

I need to compare two strings to see if they are exactly the same. Previously if I could decalre theire exact elngths it worked, but here the lengths may change. I have tried the following:-

If StrComp(UCase(Trim(screen_res)), UCase(Trim(screen_res1)), vbTextCompare) = 1 Then

it doesn't work, I've also tried

UCase(Trim(screen_res)) =  UCase(Trim(screen_res1)) Then

but this sees them as different when they are the same.

The strings are screen_res and screen_res1, and they look something like

768x1024 1024x1264 in actual text

Any helpmuch appreciated
0
Comment
Question by:eneate
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
Raynard7 earned 400 total points
ID: 17136928
I have tried this - if you are not interested in case sensitivity then what you have done should work, ie

Public Sub x(x1 As String, x2 As String)

If UCase(Trim(x1)) = UCase(Trim(x2)) Then
    Debug.Print "Match"
Else
    Debug.Print "No Match"
End If

End Sub

If you submit 768x1024, 1024x1264 it returns no match
if you submit 768x1024, 768x1024 it returns match

0
 

Author Comment

by:eneate
ID: 17137135
Hi

I think this is the problem, I am using the following code to read the second string from the text file

Dim res1 As String
Dim res2 As String
Dim Buffer As String
Dim DataString As String
Const FileName As String = "C:\Program Files\dcs-3\tools.ini"
Dim tempres As String

'get the screen resolution of the current monitor.
'**************************************************

res1 = GetScreenRes

Debug.Print res1

'read the resolution from the tools.ini file

Buffer = String$(260, Chr$(13))
Call GetPrivateProfileString("screen res", "res", vbNullString, Buffer, Len(Buffer), FileName)
DataString = StripChr(Buffer)
tempres = Buffer 'buffer contains the text from the ini file

MsgBox tempres
Buffer = res2

Debug.Print res2

using the debug.print the res1 value prints with no problems, the res2 obtained from the text file, will appear in a msgbox so I know it is there but it just leaves a space where it should print with debug.print res2

I have tried various configurations but none that work, i'm guessing this is why the string match always fails. any ideas
0
 
LVL 17

Assisted Solution

by:CSecurity
CSecurity earned 100 total points
ID: 17137191
I think when you are reading data it adds a bit null strings or chr(255) or crlf charachter to it.

Try to write in a file what you read as binary and then open the file using hex editors in hex mode to see if it's same or no...

Otherwise = operator works well for strings, and specially using strcomp will work 100%!
I'm sure your strings aren't same... So check what you have EXACTLY in your variables...

0
 

Author Comment

by:eneate
ID: 17137681
Thanks for the feedback, it all helped, it's now working fine. I wrote the info from the text file into an invisible text box, from there I can do the string comparisons and they work fine. Thanks for the confirmation that the code I was using was basically OK, I just needed the strings tobe 'active' when used.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now