?
Solved

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

Posted on 2006-07-19
4
Medium Priority
?
197 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
Raynard7 earned 1600 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 400 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

800 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