Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Other Programming > VBScript
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 21st, 2005, 03:56 AM
Registered User
 
Join Date: Jan 2005
Location: Garland, TX, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How can i get rid off the double quote in a text

I have the problem when coding the VBScript. It seems I can not call any function like Trim( "String") if the String value have a double quote(s). Could you help me to get around with it or replace the double quote with 2 single quote' ' before i can pass the string.

Below is the code i got error "Compilation error 1025"

stMyVariable = " My text or number " value here "
Msgbox "The string after converting is: " &Trim(stMyVariable)

Any help will be greatly appreciated. Thanks many in advance


Have a great day
Myer
Reply With Quote
  #2 (permalink)  
Old January 21st, 2005, 04:54 AM
Friend of Wrox
 
Join Date: Dec 2004
Location: Chennai, Tamil nadu, India.
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

Below code replaces double quotes with single quotes:

Dim strMyVariable As String
strMyVariable = "D""souza"
strMyVariable = Replace(strMyVariable, Chr(34), Chr(39))
MsgBox "Output :: " & Trim(strMyVariable)

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
Reply With Quote
  #3 (permalink)  
Old January 21st, 2005, 11:30 AM
Registered User
 
Join Date: Jan 2005
Location: Garland, TX, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Spell Check
Thank you so much for your help but I think I did not make myself clear.
Your code is working fine with 2 double quotes in a string but my text actually like this below with your guidance and I got the compilation error:

Dim strMyVariable
strMyVariable = "NEW Craftsman Microtork 3/8" Torque Wrench"
strMyVariable = Replace(strMyVariable, Chr(34), Chr(39))
MsgBox "Output :: " & Trim(strMyVariable)

However if I add one more double quote right after 3/8" (3/8"") then it working fine. Unfortunately my string have to be one single double quote.

So go back to the first question, How can I get rid off a single double quote in string text before and I can call a function Trim(strMyVariable), or some ways to work around it via VBScript? This is only language that I know and use now. I can't you VB.

Thank you so much in advance for helping me out since I stuck with coding and it seems I can go any further if this problem won't be solved unless I have to learn another language which is very hard for me.

Richard Myer


Note:
   "NEW Craftsman Microtork 3/8" Torque Wrench" can be any title with double quote stand for inch like this:
   "Brand New TV Sony 32" SRTVDV-Flat Panel"

Have a great day
Myer
Reply With Quote
  #4 (permalink)  
Old January 24th, 2005, 03:55 PM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Change " to inch, or in.

Like this:

"NEW Craftsman Microtork 3/8in. Torque Wrench"

or

"Brand New TV Sony 32inch SRTVDV-Flat Panel"



mmcdonal
Reply With Quote
  #5 (permalink)  
Old April 13th, 2009, 12:04 PM
Authorized User
 
Join Date: Dec 2007
Location: greaternoida, u.p, India.
Posts: 65
Thanks: 9
Thanked 2 Times in 2 Posts
Send a message via AIM to sandeepgreaternoida Send a message via MSN to sandeepgreaternoida Send a message via Yahoo to sandeepgreaternoida
Default

in php5 instead of doing "this" we do <<<this for double quote ; i don't know whether it works on vbscript or not but you just check this out.
Reply With Quote
  #6 (permalink)  
Old April 14th, 2009, 04:32 PM
Friend of Wrox
Points: 894, Level: 11
Points: 894, Level: 11 Points: 894, Level: 11 Points: 894, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: London, , United Kingdom.
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts
Default

Myer,

It is the actual syntax of your code which is causing the error. Vadivel is correct in that the actual string you are putting in the code should have double quotes escaped as two double quotes. Putting 2 double quotes in does not mean that the value of the variable now contains 2 double quotes - it tells the vbscript parser to treat them as being 1 double quote character within the string.
So if you want the double quote to be in the string of your original code, you must escape it as so:
vb Code:
Dim strMyVariable
strMyVariable = "NEW Craftsman Microtork 3/8"" Torque Wrench"
strMyVariable = Replace(strMyVariable, Chr(34), Chr(39))
MsgBox "Output ::  " & Trim(strMyVariable)

This will show the output with just a single quote:
NEW Craftsman Microtork 3/8' Torque Wrench

Phil

P.S. @Sandeep, I assume you are referring to the PHP heredoc syntax where you can spread string variables over multiple lines. This isn't available in vbscript.

Last edited by philip_cole; April 14th, 2009 at 04:35 PM..
Reply With Quote
  #7 (permalink)  
Old April 14th, 2009, 07:10 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Philip is of course right.

Your error has *NOTHING* to do with the REPLACE call.

Your error is on *THIS* line:
Code:
strMyVariable = "NEW Craftsman Microtork 3/8" Torque Wrench"
Just create an ASP page with *ONLY* that line in it. Nothing more:
Code:
<%
strMyVariable = "NEW Craftsman Microtork 3/8" Torque Wrench" 
%>
You *WILL* get a COMPILER error. And when you get a compiler error, that means the code will not even *BEGIN* to run. You must get rid of all compiler errors before a page can even start to make calls to functions like REPLACE.

So listen to the advice you have been given. *IT IS CORRECT*.

BUT...

But do *NOT* listen to the suggestions that you do
Code:
strMyVariable = Replace(strMyVariable, Chr(34), Chr(39))
If you do that, your MsgBox would then display
Quote:
NEW Craftsman Microtork 3/8' Torque Wrench
And I am SURE that you don't want a 3/8 of a FOOT torque wrench.

Last edited by Old Pedant; April 14th, 2009 at 07:14 PM..
Reply With Quote
  #8 (permalink)  
Old April 14th, 2009, 07:11 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Sandeep: No. Not even close to PHP syntax. At all.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
escape double quote inside JavaScript mister_mister XSLT 5 January 23rd, 2008 01:56 PM
converting double to text in editbox rupali_mb Visual C++ 1 February 11th, 2007 12:14 PM
Showing single and double quote in text field. ggriffit SQL Server ASP 4 January 5th, 2004 11:19 AM
Storing single and double quotes in text roniestein Access 4 December 30th, 2003 05:09 PM
Double search using an input text box Karel Access VBA 2 October 25th, 2003 10:29 PM



All times are GMT -4. The time now is 03:46 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.