[RESOLVED] Ignoring Case in String Comparison
It's been a long time since I've done any coding, and I feel like an idiot for having to ask this and not being able to just figure it out but I'm being kind of lazy and I promised work that I'd have this report run for them. Is there a simple way to ignore case in a string, or is there a simple way to convert a string to all lowercase? The method I've thought of is splitting the string into a variant, going through the variant and figuring out of the ASCII code for each letter was cap or lowercase, making it all lowercase, and then re-assembling the string but this will add significant time to the time it will take me to run this report as I'm comparing a list of about 300 names to a list of about 6000 names and would need to do this for each one in addition to some other code that ultimately writes several values for each name on a spreadsheet.
Any help would be appreciated :)
Re: Ignoring Case in String Comparison
You can use LCase$() or UCase$() to convert a String to lower/upper case. Also, you can use 'Option Compare Text' in Module's Declaration level. E.g.:
Code:
Option Explicit
Option Compare Text 'ignores case
Private Sub Form_Load()
Dim x As String
Dim y As String
x = "Visual Basic"
y = "visual basic"
Debug.Print LCase$(x) = y
Debug.Print x = y 'only returns True if 'Option Compare Text' is used
End Sub
Re: Ignoring Case in String Comparison
Another way
Code:
If StrComp(x, y, vbTextCompare) = 0 Then
MsgBox "equal"
End If
Re: Ignoring Case in String Comparison
The best way:
At the top of your form/module/class if you are not doing any binary compares...
Re: Ignoring Case in String Comparison
Thanks a lot guys, the help is greatly appreciated :)