# Visual Basic > Visual Basic 6 and Earlier >  INSTR Function and letter case

## daveyk021

A program written years ago in Windows 7 worked fine and now revamping it under windows 11, I have run in to an interesting issue. Well, it's not really much of an issue, but I am not sure why it ever worked before:

If InStr(tmpName, "PHASOR") = 0 Then Exit Sub

If tmpName = "Phasor", in the old program, execution would exit the sub.  Under Windows 11, execution continues.  That is because "PHASOR" is not in "Phasor".  The letter case matters.

I found this in several modules and numerous subs and functions. I guess a lot of sloppy programming in the past.

My interest is why did the program ever work before?  It never care about capitalization, or lack thereof, before.

I made a lot of other changes to the program, adapting it to serve multiple instrument test verses specialize on one instrument.  Who knows what changes I made to have it all of a sudden care about case.  Maybe some subs where missing Option Explicit that now have it?  I don't think so.  The main difference that I see is VB6 under Windows 7 verses under Windows 11.

I am still cleaning up capitalization within instr functions.  I used INST a lot.

----------


## dilettante

Look up Option Compare in the manual.

----------


## Elroy

Did you put an "Option Compare" directive at the top of any module, or remove it?

It's my understanding that that's going to come out of the VB6 runtimes, and it's hard to believe that those got changed at anytime in the last several years.  So something has to have changed about your incoming data in tmpName.

It's my understanding that InStr is always case sensitive, particularly if you never specify third argument and have Option Compare set to binary (the default if no Option Compare is specified).  You can make it slightly alphabet independent by specifying the Option Compare Text (or use vbTextCompare for the last argument), but that's still not case insensitive.

----------


## baka

if tmpName is not "HUGE", u could always do

Instr(ucase(tmpName), "PHASOR") = 0 

lcase and ucase are good when u are not sure. since different OS could return different.
this of course can be done somewhere earlier.
like if I use FindFirstFile, I could store the filename using ucase (I prefer lcase)

----------


## Eduardo-

Check the last optional parameter of the InStr function:



```
Function InStr([Start], [String1], [String2], [Compare As VbCompareMethod = vbBinaryCompare])
```

----------


## daveyk021

""Option Compare"""

I've searched for it and can not find that.  I've never used it before.  Not sure, what is going on.  When I get this version done, I will bring it on the Win7 machine and experiment.

----------


## daveyk021

> if tmpName is not "HUGE", u could always do
> 
> Instr(ucase(tmpName), "PHASOR") = 0 
> 
> lcase and ucase are good when u are not sure. since different OS could return different.
> this of course can be done somewhere earlier.
> like if I use FindFirstFile, I could store the filename using ucase (I prefer lcase)


Interesting idea.  I do think it might have been a Win7 thing.  It just never popped up before and took me by surprise a little; no big deal, but I said "It never did that before!" - lol

----------


## DataMiser

> Interesting idea.  I do think it might have been a Win7 thing.  It just never popped up before and took me by surprise a little; no big deal, but I said "It never did that before!" - lol


 Well it is not a Windows 7 thing. Been using VB for years and the default is to be case sensitive. I can't say if anythign may have changed under Windows 11 but I would find it unlikely. It has definitely been case sensitive under older versions of Windows and there is no reason why it should have changed, that could break a lot of programs.

----------


## Eduardo-

> If InStr(tmpName, "PHASOR") = 0 Then Exit Sub
> 
> If tmpName = "Phasor", in the old program, execution would exit the sub.


Not true. InStr without specifying the 'Compare' parameter is case sensitive and it has always been case sensitive from Windows 95 to Windows 11, since it is a VB6 thing and independent of the OS version.

What could have happened is that in Windows 7 tmpName had "PHASOR" instead of "Phasor".

----------

