 |
| VB How-To Ask your "How do I do this with VB?" questions in this forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 4th, 2005, 04:14 AM
|
|
Friend of Wrox
|
|
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Replace
I have four functions:
Code:
''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace Ampersand character with 'AND'
'''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function fix_ampersand(ByVal strValue As String) As String
fix_ampersand = Replace(strValue, "&", "AND")
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace Apostrophe character with "" (empty)
'''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function fix_apostrophe(ByVal strValue As String) As String
fix_apostrophe = Replace(strValue, "'", "")
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace Colon character with "" (empty)
'''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function fix_colon(ByVal strValue As String) As String
fix_colon = Replace(strValue, ":", "")
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace Comma character with "" (empty)
'''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function fix_comma(ByVal strValue As String) As String
fix_comma = Replace(strValue, ",", "")
End Function
how can i add them all into one function and just replace each character i.e. comma, apostrophe, etc with "" (blank).
is there a 'strip' command?
www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
|
|

May 4th, 2005, 04:36 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Put the three replace statements inside one function.This will replace with ""
Public Function fix_characters(ByVal strValue As String) As String
fix_apostrophe = Replace(strValue, "'", "")
fix_colon = Replace(strValue, ":", "")
fix_comma = Replace(strValue, ",", "")
End Function
|
|

May 4th, 2005, 04:52 AM
|
|
Friend of Wrox
|
|
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
with that code i get a Compile Error:
Function call on left side of assignment must return Variant or Object
heres my code:
Code:
''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace Ampersand character with 'AND'
'''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function fix_ampersand(ByVal strValue As String) As String
fix_ampersand = Replace(strValue, "&", "AND")
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace Apostrophe character with 'AND'
'''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function fix_apostrophe(ByVal strValue As String) As String
fix_apostrophe = Replace(strValue, "'", "")
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace Colon character with ''
'''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function fix_colon(ByVal strValue As String) As String
fix_colon = Replace(strValue, ":", "")
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace Comma character with ''
'''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function fix_comma(ByVal strValue As String) As String
fix_comma = Replace(strValue, ",", "")
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace all characters with ""
'''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function fix_characters(ByVal strValue As String) As String
fix_apostrophe = Replace(strValue, "'", "")
fix_colon = Replace(strValue, ":", "")
fix_comma = Replace(strValue, ",", "")
End Function
and where i call it:
Code:
fix_characters(Trim(the_Content))
www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
|
|

May 4th, 2005, 04:55 AM
|
|
Friend of Wrox
|
|
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
change to:
Code:
''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace all characters with ""
'''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function fix_characters(ByVal strValue As String) As String
fix_characters = Replace(strValue, "'", "")
fix_characters = Replace(strValue, ":", "")
fix_characters = Replace(strValue, ",", "")
End Function
www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
|
|

May 4th, 2005, 05:07 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Cool.
|
|

May 4th, 2005, 07:43 AM
|
|
Registered User
|
|
Join Date: May 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Replace(strSting,CHR(34),"'")
Say Hi to Paul & David for me.
|
|

May 4th, 2005, 07:55 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
When you say "this won't work", you might want to be a little bit more specific
In fact, if you're using the VB editor, your example
Code:
Replace(strString,""","'")
won't even compile and the editor will highlight it straight away with a warning dialog
Basically you need to escape the double-quote character [Chr$(34)] as it's a special character for the VB compiler
You need to type
Code:
Replace(strString,"""","'")
ie. 4 instances of the double-quote character
|
|

May 17th, 2005, 09:35 AM
|
|
Friend of Wrox
|
|
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Is this correct VB code:
Code:
''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace all problematic characters with ""
'''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function fix_characters(ByVal strValue As String) As String
fix_characters = Replace(strValue, "'", "")
fix_characters = Replace(strValue, ":", "")
fix_characters = Replace(strValue, ",", "")
fix_characters = Replace(strValue, """", "")
End Function
I'm not sure if its working....
www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
|
|

May 17th, 2005, 09:45 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
mmm you have to replace that chars with nothing or with "" (double quote)...
also.. you will only replace the """" b/c you are using always the same destination...
do something like this¨
Code:
Public Function fix_characters(ByVal strValue As String) As String
[TAB]dim sStrTemp as string
sStrTemp = Replace(strValue, "'", "")
sStrTemp = Replace(sStrTemp , ":", "")
sStrTemp = Replace(sStrTemp , ",", "")
sStrTemp = Replace(sStrTemp , """", "")
fix_characters = sStrTemp
End Function
HTH
Gonzalo
|
|
 |