My application allows a user to insert as ascii.txt file into a RichTextBox
Once the text file is loaded the application then tests the inputted characters for certain characters and changes the color of these to red if found. This is an attempt to alert the user to the fact that these characters are illegal and should be deleted before taking any other action with the data.
The code I use is
For i = 1 to Len(rtfTmp)
If Not IsValidString(Mid$(rtfTmp,i),"@#$%^") Then
rtfTmp.SelStart = i - 1
rtfTmp.SelLength = 1
rtfTmp.SelColor = vbRed
Function IsValidString(strToTest As String, Invalid As String) as Boolean
Dim i as Long
For i = 1 To Len(Invalid)
If Instr(1,strToTest, Mid$(Invalid, i, 1),0) Then
IsValidString = False
IsValidString = True
This routine works OK as long as the imported file is not lengthy. For example a file containing 100 characters means that there is up to 500 iterations. Some of the files I've trialled contain a lot more characters than 100 and the problem I'm faced with is that it either takes forever to iterate through the sequence or the PC has a hernia and does the old 'Not responding" trick.
My question: Is there a faster, simpler method of achieving this without any GPFs or hang ups