Solved

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

Posted on 2006-07-19
4
194 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

830 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