borderAndreaVB free resources for Visual Basic developersborder

AndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2014 Andrea Tincani
:: How to Replicate the Replace Function found in Visual Basic 6.0

Author  

David Costelloe, fixed by Irving Thomas

Language  

VB5, VB6

Operating Systems  

Windows 95, 98 and NT
Module

Public Function Replace(ByVal strString As String, ByVal _
strReplaceWith As String, ByVal strReplace As String) As String
'*************************************************************
'* Replicates the Replace Function found in Visual Basic 6.0
'* Usage: For VBA programming Word Macro etc
'* MyVar = Replace("Greg Hello World Greg", "David", "Greg")
'*************************************************************

    Dim i As Long
    Dim strTemp As String

    i = 1
    Do While InStr(i, strString, strReplace, vbTextCompare) <> 0
        strTemp = strTemp & Mid(strString, i, InStr(i, _
            strString, strReplace, vbTextCompare) - i) & strReplaceWith
        i = InStr(i, strString, strReplace, vbTextCompare) + Len(strReplace)
    Loop
    strTemp = strTemp & Right(strString, Len(strString) - i + 1)
    Replace = strTemp
End Function

:: Navigation

Home

VB and VBA for Word and Access

Previous Tip

Next Tip

:: Search this site
Google
:: Related Topics
icon 18-03-2008 VB code generation TSQL scripts for SQL2k by stickleprojects
icon 31-03-2007 Re: How to Convert an Acess DB to MS SQL Server DB ? by yronium
borderAndreaVB free resources for Visual Basic developersborder
borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2014 Andrea Tincaniborder