Re: Replace function doesn't work properly



Co wrote:
On 20 okt, 15:16, "Jeff Johnson" <i....@xxxxxxxxxxx> wrote:
"Co" <vonclausow...@xxxxxxxxx> wrote in message

news:649f8e98-e803-4639-9e69-0f82df0e6754@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I use the Replace function in a vb project but found out that it ain't
working properly.
I try to remove a space from a string using:
sStr = Replace(sStr, " ", "",1, -1)
I tried this, and with Chr(32) and also vbBinaryCompare.
The space stays in.
Any ideas what causes this?
Chr$(160) instead of a normal space.

All,

I created a function to check all the characters in the string and it
definitely comes up with a Chr(32).
Still the Replace function won't remove it.
Does it have to do with the fact that I use this in VBA Word office
2003?

sFinalName = Replace(sFinalName, Chr(46) & Chr(32) & Chr(46), ".",
1, -1, vbTextCompare)
findchrs (sFinalName)


Public Function findchrs(str As String)

Dim i As Integer
Dim j As Integer
Dim sResult As String

i = 1
j = Len(str)
Do While i < j
sResult = sResult & Asc(Mid(str, i, 1)) & ","
i = i + 1
Loop
Debug.Print str
Debug.Print sResult

End Function

Everything looks good in your code as far as I can see. Can you cut & paste the string you're using for sFinalName, just so we can all be 100% sure of what's going on? Or better yet, the output from findchrs?

Oh and to answer your question, while it's conceivable that the VBA in Word 2003 is different, it's rather unlikely, as VB6 and VBA are both ultimately based on the same thing, with relatively minor variations for the most part, and I'm 99.999% (add a few more 9's for good measure) sure that Replace isn't one of them. Therefore, it seems most likely that either there's a problem with your source string, or there's a problem with the code that nobody's seeing (like if you used a hard space in the code, as opposed to the original string).



Rob
.



Relevant Pages

  • Re: My Selected print in the list box does not work
    ... Public Function BuildWhereCondition(strField As String, ... Dim strWhereLst As String ... This is my command button VBA: ...
    (microsoft.public.access.formscoding)
  • Re: My Selected print in the list box does not work
    ... Public Function BuildWhereCondition(strControl As String) As String ... Dim strWhereLst As String ... HERE IS THE VBA OF A COMMAND: ...
    (microsoft.public.access.formscoding)
  • Search pattern
    ... Dim strfile As String ... Dim bAddressFound As Boolean ... Dim strCurrentChar As String ...
    (comp.databases.ms-access)
  • Auto Write Name and Merge across
    ... Dim Sheetname01 As String ... Dim WeekName01 As String ...
    (microsoft.public.excel.misc)
  • Re: ChangeFileOpenDirectory
    ... VBA should inherently wait when calling one it's own subroutines. ... Private Declare Function GetExitCodeProcess Lib "kernel32" (_ ... ByVal PathName As String, _ ... Dim ProcHnd As Long ...
    (microsoft.public.word.vba.general)

Loading