There is a way of quitting a DO WHILE loop by checking for the end of the array isn't there? I'm sure I read it somewhere but I'm blowed if I can find it.
Anyway, here's the sub-routine that loops until the end of time if it doesn't find the string it's searching for (strFile is a .cvs file containing a list of usernames):
Now, I've got two odd behaviours here, firstly, the loop fails to immediately quit out after finding the string - it goes through the whole list even if it found the string on the first line - but worse is that if the string isn't found it just starts all over again.
So, what am I missing? And is my code here hopelessly complicated anyway? And how do I make it check for an exact match instead of partial matches (so that BloggsJ doesn't match against BloggsJ2, although I'm not concerned about case sensitivity)?
JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
Anyway, here's the sub-routine that loops until the end of time if it doesn't find the string it's searching for (strFile is a .cvs file containing a list of usernames):
Code:
Sub FindTheUser(strFile,strUserName)
text = strFile.ReadAll
strFile.Close '
arrText = split(text,vbCrLf)
eod = 0
Do While eod = 0
For Each elem In arrText
' wscript.echo "elem = " & elem & vbCRLF & _
' "strUserName = " & strUserName
Result = InStr(lcase(elem),lcase(strUserName))
if Result > 0 then
eod = 1
End if
' wscript.echo "Result = " & Result & vbCrLf & _
' "eod = " & eod
Next
Loop
End Sub
Now, I've got two odd behaviours here, firstly, the loop fails to immediately quit out after finding the string - it goes through the whole list even if it found the string on the first line - but worse is that if the string isn't found it just starts all over again.
So, what am I missing? And is my code here hopelessly complicated anyway? And how do I make it check for an exact match instead of partial matches (so that BloggsJ doesn't match against BloggsJ2, although I'm not concerned about case sensitivity)?
JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]