For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > January 2006 > Strange 'Replace' problems









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Strange 'Replace' problems
Elmo Watson

2006-01-28, 3:55 am

Ok here it is - I've got this code, converting tabs to spaces :
mSelText = ActiveForm.txtEdit.SelText '<---richtextbox/mSelText
is a global string variable
mSelText = Replace(mSelText, vbTab, " ")

I've used 'Replace' for years....but now, for some reason, I'm getting a
Compile Error:
"Wrong Number of Arguments or invalid property assignment"

So - I moved the code to the TxtEdit form (this is a MDI app, if you haven't
figured it out)
removed all the ActiveForm stuff - it goes through the code - but nothing
happens - I can see it highlight the text, but no replacement happens
Code:
(Do with statment[With frmMain.ActiveForm] - define start and end points)
.txtEdit.SelStart = SelStart
.txtEdit.selLength = SelEnd - SelStart
mSelText = .txtEdit.SelText
mSelText = Replace(mSelText, Chr(9), "")
.txtEdit.SelStart = SelStart
.txtEdit.selLength = 0
.txtEdit.SetFocus
End With

I've tried it with and without the With frmMain (pure txtedit.seltext) - -
same problem

Any ideas?


Fatih Argun

2006-01-28, 3:55 am

are you sure you don't have any function or procedure that named "replace" ?


mayayana

2006-01-28, 6:55 pm

According to the code snippet you posted,
the processed string was never put into
the RTB. You have: mSelText = .txtEdit.SelText
Then you ran Replace on that string. But you
never used: .txtEdit.SelText = mSelText


> Ok here it is - I've got this code, converting tabs to spaces :
> mSelText = ActiveForm.txtEdit.SelText '<---richtextbox/mSelText
> is a global string variable
> mSelText = Replace(mSelText, vbTab, " ")
>
> I've used 'Replace' for years....but now, for some reason, I'm getting a
> Compile Error:
> "Wrong Number of Arguments or invalid property assignment"
>
> So - I moved the code to the TxtEdit form (this is a MDI app, if you

haven't
> figured it out)
> removed all the ActiveForm stuff - it goes through the code - but nothing
> happens - I can see it highlight the text, but no replacement happens
> Code:
> (Do with statment[With frmMain.ActiveForm] - define start and end points)
> .txtEdit.SelStart = SelStart
> .txtEdit.selLength = SelEnd - SelStart
> mSelText = .txtEdit.SelText
> mSelText = Replace(mSelText, Chr(9), "")
> .txtEdit.SelStart = SelStart
> .txtEdit.selLength = 0
> .txtEdit.SetFocus
> End With
>
> I've tried it with and without the With frmMain (pure txtedit.seltext) - -
> same problem
>
> Any ideas?
>
>



Mike L

2006-01-28, 6:55 pm

"Elmo Watson" <sputnik@nospam.yahoo.com> wrote in message
news:OR6dlB9IGHA.2040@TK2MSFTNGP14.phx.gbl...
> Ok here it is - I've got this code, converting tabs to spaces :
> mSelText = ActiveForm.txtEdit.SelText '<---richtextbox/mSelText
> is a global string variable
> mSelText = Replace(mSelText, vbTab, " ")
>
> I've used 'Replace' for years....but now, for some reason, I'm getting a
> Compile Error:
> "Wrong Number of Arguments or invalid property assignment"
>
> So - I moved the code to the TxtEdit form (this is a MDI app, if you

haven't
> figured it out)
> removed all the ActiveForm stuff - it goes through the code - but nothing
> happens - I can see it highlight the text, but no replacement happens
> Code:
> (Do with statment[With frmMain.ActiveForm] - define start and end points)
> .txtEdit.SelStart = SelStart
> .txtEdit.selLength = SelEnd - SelStart
> mSelText = .txtEdit.SelText
> mSelText = Replace(mSelText, Chr(9), "")
> .txtEdit.SelStart = SelStart
> .txtEdit.selLength = 0
> .txtEdit.SetFocus
> End With
>
> I've tried it with and without the With frmMain (pure txtedit.seltext) - -
> same problem
>
> Any ideas?


Like Fatih said, you probably have a control or function named Replace.
Change your Replace line above with

mSelText = VBA.Replace(mSelText, Chr(9), "")


TedF

2006-01-28, 6:55 pm

You could be running VB5 project, it doesn't support Replace.
Or maybe the .vbp project file is corrupted, missing the last few lines
that makes it run as VB6.


"Elmo Watson" <sputnik@nospam.yahoo.com> wrote in message
news:OR6dlB9IGHA.2040@TK2MSFTNGP14.phx.gbl...
> Ok here it is - I've got this code, converting tabs to spaces :
> mSelText = ActiveForm.txtEdit.SelText '<---richtextbox/mSelText
> is a global string variable
> mSelText = Replace(mSelText, vbTab, " ")
>
> I've used 'Replace' for years....but now, for some reason, I'm getting a
> Compile Error:
> "Wrong Number of Arguments or invalid property assignment"
>
> So - I moved the code to the TxtEdit form (this is a MDI app, if you
> haven't figured it out)
> removed all the ActiveForm stuff - it goes through the code - but nothing
> happens - I can see it highlight the text, but no replacement happens
> Code:
> (Do with statment[With frmMain.ActiveForm] - define start and end points)
> .txtEdit.SelStart = SelStart
> .txtEdit.selLength = SelEnd - SelStart
> mSelText = .txtEdit.SelText
> mSelText = Replace(mSelText, Chr(9), "")
> .txtEdit.SelStart = SelStart
> .txtEdit.selLength = 0
> .txtEdit.SetFocus
> End With
>
> I've tried it with and without the With frmMain (pure txtedit.seltext) - -
> same problem
>
> Any ideas?
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com