Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String operation with double quote in text

Status
Not open for further replies.

FoxProProgrammer

Programmer
Apr 26, 2002
967
US
This problem is driving me crazy! I have tried every combination that I can think of, and still no dice. I am trying to build a string that looks like the following:

"8252" 46","KBC16/45","1-3/4" X 16" X 4' BCI JOIST"," 2","N"

Here's where the data comes from:

8252 is contained in a string variable named PlanID.

46 is contained in an integer variable named lineNo.

KBC16/45 is contained in the part field (string type) of a recordset named rstemp.

1-3/4" X 16" X 4' BCI JOIST is contained in the descr field (string type) of a recordset named rstemp.

2 is contained in the qty field (numeric type) of a recordset named rstemp.

N is the evaluated string of the IIF function below.
IIF(rstemp!Unit = 'SF ', 'S', 'N')

The double quotes in the expression at the top of this post have to be in the expression. After the expression is built, it is written to a file using the Write # Statement. I have tried using Chr(34), """, and every combination thereof to build the correct string. I either get syntax errors or it writes the string to the file without evaluating the value of the fields and IIF function. For example, it wrote:

"PlanID" LineNo","rstemp!part","rstemp!descr","qty","IIF(rstemp!Unit = 'SF ', 'S', 'N')"

literally in the file. Please note that 1-3/4" X 16" X 4' are dimensions, where the " means inches and the ' means feet. The string must look exactly like above.

Does anyone have any earthly idea how to concatenate this string?

Thanks a lot!

dz

 
Just write it as it looks. VB allows you to represent a " inside a string by putting another " right in front of it, like this:

""

Yes, that's 2 of them in a row. So, to get you started:

S="""8252"" 46"" ... "

It looks messy, but it works.
 
dds82,

Thanks for your assistance. I tried that way before I posted. That's one of the ways that compiles ok, but it writes the field names and IIF function literally instead of evaluating them.

Here is the code:

str2Write = """ & strPlanId & Str(lnLineNo) & "","" & Trim(rstemp!cPart) & "","" & Trim(rstemp!cPartdescr) & "","" & rstemp!cQty & "","" & IIf(rstemp!cUnit = 'SF ', 'S', 'N') & """

Write #detailfile, str2Write

Assuming the following variable and field values:

strPlanId = "8252"
lnLineNo = 46
cPart = "KBC16/45"
cPartdescr = "1-3/4" X 16" X 4' BCI JOIST"
cQty = 2
cUnit is not equal to 'SF ', so the IIF should evaluate to "N"

The quotes above are to show the data type and are not part of the value.

The string should look like this:

"8252 46","KBC16/45","1-3/4" X 16" X 4' BCI JOIST"," 2","N"

This is what gets written to the file:

""" & strPlanId & Str(lnLineNo) & "","" & Trim(rstemp!cpart) & "","" & Trim(rstemp!cpartdescr) & "","" & rstemp!cqty & "","" & IIf(rstemp!cunit = 'SF ', 'S', 'N') & """

Can you see what I did wrong? Probably one " in the wrong place!

Thanks,

dz

 
You're a " short wherever you put sets of 2 or more " in a row. Just find all those sets and add a " to each one and it should be fine.

(This is one of the reasons I HATE VB. To set a string to a single quote, you need to write s=""""!)
 
I must be brain-dead after looking at this so long cause it isn't working. Would you be kind enough to cut and paste my line of code into a message and add the " where you think it needs to go.

Thanks so much,

dz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top