Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

9 Experts available now in Live!

Get 1:1 Help Now