简体   繁体   中英

VBA string comparison failure

i met interesting issue when im comparing two strings. Im reading data from file and everything works well. But then co-worker send me input file, which is just CTRL+C and CTRL+V of working file. And then miracle happend! VBA is so confused, that cant compare two simple strings and i fell of chair.

If you take a look at image you can see that comparison passed if condition where are two same strings, but it should not. Im a bit confused how this can happen.

在此处输入图片说明

So met someone something like this? Im realy start thinking about something like machine revolution from Terminator. (files are both saved in notepad++ and there are no strange characters or something like that)

Progress update
So i tried hints from guys in comments below. and ended with something like this

If CStr(Trim(rowArray(4))) <> (CStr("N/A")) Then

Contentent of rowArray(4) is still "N/A" string as on picture above and excel still thinks this strings arent same. I also saved file in pspad, netbeans, and normal notepad and issue is still same.

Use the immediate window to test the contents of the variable:

For i = 1 To Len(rowArray(4)): Print Asc(Mid(rowArray(4), i, 1)): Next

This will print the ASCII value of each character in the string - you can use this to determine what the extra character(s) are causing the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM