Solved

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

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 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