[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

Reading strings with double quotes

avi

1/5/2012 8:45:00 AM

Hello,

I have procedure that reads strings from a file
LayerC = Chr(34) & Layer & Chr(34)
Then Evaluate a count

CountIn = _
xlApp.Evaluate("SUMPRODUCT((" &
MainDataRange.Address & "=" & TvahC & ")*(" & RangeLayers.Address &
"=" & LayerC & "))")

The problem is if the variable Layer contains double quotes (For
Example N"Y) , the new variable LayerC is now "N"Y", which the 2nd
statement does not accept

Any idea?
Thanks
Avi
3 Answers

Jason Keats

1/5/2012 3:04:00 PM

0

avi wrote:
> Hello,
>
> I have procedure that reads strings from a file
> LayerC = Chr(34)& Layer& Chr(34)
> Then Evaluate a count
>
> CountIn = _
> xlApp.Evaluate("SUMPRODUCT(("&
> MainDataRange.Address& "="& TvahC& ")*("& RangeLayers.Address&
> "="& LayerC& "))")
>
> The problem is if the variable Layer contains double quotes (For
> Example N"Y) , the new variable LayerC is now "N"Y", which the 2nd
> statement does not accept
>
> Any idea?
> Thanks
> Avi

Try something like

LayerC = Quote(Layer)

where

Public Function Quote(ByVal sValue As String) As String
sValue = Replace(sValue, Chr$(34), Chr$(34) & Chr$(34))
Quote = Chr$(34) & sValue & Chr$(34)
End Function

The above is untested.

ralph

1/5/2012 3:41:00 PM

0

On Thu, 5 Jan 2012 00:44:44 -0800 (PST), avi <aviben@bezeqint.net.il>
wrote:

>Hello,
>
>I have procedure that reads strings from a file
>LayerC = Chr(34) & Layer & Chr(34)
>Then Evaluate a count
>
> CountIn = _
> xlApp.Evaluate("SUMPRODUCT((" &
>MainDataRange.Address & "=" & TvahC & ")*(" & RangeLayers.Address &
>"=" & LayerC & "))")
>
>The problem is if the variable Layer contains double quotes (For
>Example N"Y) , the new variable LayerC is now "N"Y", which the 2nd
>statement does not accept
>
>Any idea?

As Jason pointed out you can "escape" the embedded quotes in "Layer".

If you add a double quote to the quote in the string it will mark the
quote as a 'literal' double quote and not be parsed as an argument
delimiter.

This is a problem that shows up frequently whenever an argument or
value contains characters that are also used as delimiters. (Double
quotes, single quotes, occasionally spaces, tabs, etc. - with such
things as command line processors, search/find routines, argument
lists, etc.)

I suggest you take a look at the many articles online that address
these kinds of problems and the various ways to manage them, as you
will run into the issue again and again in your programming career.
<bg>

-ralph

avi

1/5/2012 5:30:00 PM

0

On 5 jan, 17:40, ralph <nt_consultin...@yahoo.net> wrote:
> On Thu, 5 Jan 2012 00:44:44 -0800 (PST), avi <avi...@bezeqint.net.il>
> wrote:
>
>
>
>
>
>
>
>
>
> >Hello,
>
> >I have procedure that reads  strings from a file
> >LayerC =  Chr(34) & Layer & Chr(34)
> >Then Evaluate a count
>
> > CountIn = _
> >                   xlApp.Evaluate("SUMPRODUCT((" &
> >MainDataRange.Address & "=" & TvahC & ")*(" & RangeLayers.Address &
> >"=" & LayerC & "))")
>
> >The problem is if the variable Layer contains double quotes (For
> >Example N"Y) , the new variable LayerC is now "N"Y", which the 2nd
> >statement does not accept
>
> >Any idea?
>
> As Jason pointed out you can "escape" the embedded quotes in "Layer".
>
> If you add a double quote to the quote in the string it will mark the
> quote as a 'literal' double quote and not be parsed as an argument
> delimiter.
>
> This is a problem that shows up frequently whenever an argument or
> value contains characters that are also used as delimiters. (Double
> quotes, single quotes, occasionally spaces, tabs, etc. - with such
> things as command line processors, search/find routines, argument
> lists, etc.)
>
> I suggest you take a look at the many articles online that address
> these kinds of problems and the various ways to manage them, as you
> will run into the issue again and again in your programming career.
> <bg>
>
> -ralph

It works very well!

Thanks for the wise advice also

Avi