Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding strings with tilde in the first character

Status
Not open for further replies.

phudgens

Technical User
Jul 8, 2004
117
US
I am having difficulty getting my Excel VBA program to recognize a tilde. I search for the string "~Ascii" in the first 6 characters of a line, but VBA won't find it, even though I am certain the line exists. My code is:

Do While Not EOF(1) ' Loop until end of file.
Line Input #1, LineString ' Read line into variable.

iLoc1 = (InStr(LineString, ".")) + 1
iLoc2 = (InStr(LineString, ":")) - 1
iLoc3 = iLoc2 - iLoc1
If iLoc3 <= 0 Then GoTo NextLoop

NewLine = Mid(LineString, iLoc1, iLoc3)
NewLine = Trim(NewLine)

If Mid(LineString, 1, 6) = "~Ascii" Then
MsgBox (LineString)
End If

I never get anything echoed to the screen. Is there some secret about searching for the tilde?

Thanks,
Paul H.
Denver
 
Have you tried to debug your code step by step (F8) ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I think you meant this:
If Mid([!]NewLine[/!], 1, 6) = "~Ascii" Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Actually, it's shown the way I intended. VBA needs to refer to the entire LineString, not just the NewLine portion of it, to try and find "~Ascii". I ended up using:

LineString = Replace(LineString, "~", " ")

to get rid of the tilde, and then split the line into individual words (space delimited) to find the word "Ascii". That is working. Regardless of what I tried, VBA would skip any lines that had a "~" as the first character.

Thanks for the help,

Paul H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top