DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Case sensitive string variable?

Hello,

 

I use the following code to determine whether I am opening a DAT file or a TDM file. Some of it is complicated by a bug in 2010 but that is not relevent for this particular problem. Up until today it has worked perfectly, probably because the TDM files I have been opening were written using code from the same autosequence. Today I was opening files saved by DIAdem using the standard save as toolbar button.

 

T2 = NameSplit(T1,"E") ' extract file extension

if T2 <> "TDM" then 'case sensitive??

CallDataLoadHdFile(T1) 'Temporary fix from NI until DataFileLoadSel problem is fixed

CallDataLoadSel(DATADRVUSER&T1, ChList_, 0) 'Temporary fix from NI until DataFileLoadSel problem is fixed

' Call DataFileLoadSel(DATADRVUSER&T1,T2,"[1]/["&ChList_&"]","") ' Load selected data channels from next file 'Commented out by SA 8/6/11, as it doesn't work in 2010

else

CallDataFileLoadSel(DATADRVUSER&T1,T2,"[1]/["&ChList_&"]","") ' Load selected data channels from next file

endif

 

The code failed because the file I was opening had the extension tdm, and thus the value of T2 was "tdm". I couldn't believe it but I wondered whether the if...then loop was case sensitive to the value of T2. It was... When I changed the second line of code as follows (i.e. lower case tdm) it worked.

 

if T2 <> "tdm" then'case sensitive??

 

It seems that when DIAdem saves files it applies a lower case extension but my code has applied uppercase letters. For reasons of backwards compatability I can't really change my code to save with lower cases.

I've tried using:

 

if T2 <> "TDM" or "tdm" then'case sensitive??

 

but that doesn't work.

 

So, my question is: how do I correct the 'or' statement so that it works, or is there a function I can use to make the if...then loop and/or T2 case insensitive?

 

Thanks.

0 Kudos
Message 1 of 4
(5,083 Views)

Try InStr for comparing instead:

 

T2 = "TDM"
If InStr(1, T2, "tdm", vbTextCompare) <> 0 then
 MsgBox "Found TDM"
end if

(T2 contains capital TDM whereas Instr used lowercase tdm for comparison....)

0 Kudos
Message 2 of 4
(5,072 Views)

Thank you!

0 Kudos
Message 3 of 4
(5,062 Views)

Another way to solve this kind of problem is to upper case (or lower case) the string prior to the check.

 

if ucase(T2) <> "TDM" then

0 Kudos
Message 4 of 4
(4,945 Views)