I really do not believe I'm doing this wrong, but that could be the case here.

I have a collection of files that all have the same setup: a series of attributes followed by = and then their values.

because of the way I've designed these files, some of the attributes are duplicated. In this case, startcontact and endcontact are listed twice in each file. It's a long story I'd rather not get into now.

What I'm trying to do is remove the second listing from these files as the file is loaded into my program. The attributes are duplicated, which means in both locations they have the same values. So, I don't need the second listings. Here's the code I'm trying to use:

    Dim sD As String
    Dim lFirst As Long
    Dim lSecond As Long

    'sD contains the contents of a file I'm trying to load...

    'find the first startcontact
    lFirst = InStr(sD, "startcontact=")

    'find the second startcontact
    lSecond = InStr(lFirst + 3, sD, "startcontact=")

    'find the line break that follows the second startcontact
    'rather than make a third Long variable, re-use lFirst...
    lFirst = InStr(lSecond + 3, sD, vbCrLf)

    'record this string (should be the same as the first one)
    s = Mid$(sD, lSecond, lFirst - lSecond) & vbCrLf

    'blank out that string
    sD = Replace(sD, s, "", lSecond)

    txtTest.Text = sD
Now, the results I get are horrible! I lose all data from the first half of the file. The Replace Function is listed to be...

Replace(expression, find, replacewith[, start[, count[, compare]]])
which means I have the expresion = sD, find = s, replacewith = "", and start = lSecond. Start is supposed to be where Replace STARTS looking in "expression" for "find", correct? If I takeout the start value, then all listings of startcontact are removed.

I've tried it again, leaving out the start value and include 1 for number of replacements. It removes the first instance of startcontact in the text and leaves all the rest as it should. I'm just very confused why I cannot get it to remove the second instance with the original code. ANY help/advice is welcome.