2 Replies - 722 Views - Last Post: 09 April 2012 - 11:07 AM Rate Topic: -----

#1 mattdahack  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 24-June 11

HELP can't write html code to a text file :-)

Posted 05 April 2012 - 12:19 AM

Hi there, I am using the free file code to write html code to a .html file.
I can't figure out how to make VB6 let my program write these strings to the .html file

<td width="150" bgcolor="#CCCCCC"><div align="center"><strong>Item</strong></div></td>
<td width="500" bgcolor="#CCCCCC"><div align="center"><strong>Item Description </strong></div></td>

'open the file for writing
Open CommonDialog1.FileName For Output As #newfile
'Warning, if this file already exists it will be overwritten!
'Start writing parts list to .html file now
Print #newfile, "    <td width="150" bgcolor="#CCCCCC"><div align="center"><strong>Part</strong></div></td>"



VB keeps throwing an compile error, expected expression on the first "#" sign in front of bgcolor color code #cccccc.
Any line that should be written to the text file won't write when it has a # in it. It keeps saying expected expression. When there isn't any. Please give me your suggestions.

Thanks,
matt

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: HELP can't write html code to a text file :-)

#2 DimitriV  Icon User is offline

  • Don't try to save yourself… the circle is complete
  • member icon

Reputation: 544
  • View blog
  • Posts: 2,632
  • Joined: 24-July 11

Re: HELP can't write html code to a text file :-)

Posted 05 April 2012 - 12:27 AM

The quotes within the string are finishing each other off, meaning the # is outside of a quote pair.
Was This Post Helpful? 0
  • +
  • -

#3 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 547
  • View blog
  • Posts: 2,904
  • Joined: 19-May 09

Re: HELP can't write html code to a text file :-)

Posted 09 April 2012 - 11:07 AM

The point is that VB uses " as a string delimiter, as in
myName = "Bob Rodes"
Now, suppose I had written that sentence without using code blocks: The point is that VB uses " as a string delimiter as in "myName = "Bob Rodes"". VB will get mixed messages about which quotes have to do with the beginning and end of the string value, and which ones are to be taken as part of the string value itself.

You can either use Chr(34) in place of literal quotes, e. g. "<td width=" & chr(34) & "150" & chr(34) & " bgColor=" and so on, or you can double the quotes (double the double quotes) that are to be taken literally, so: "<tl width=""150"" bgColor=""#CCCCC"">" and so on. That can get a little strange if the last character of the string is a quote, because there will be three in a row. But if you stick carefully to the idea that you put two double quotes for every quote that's included in your string, and enclose the string in double quotes, you shouldn't go wrong. If that's a pain for you, then use Chr(34) for the literal quotes instead.

This post has been edited by BobRodes: 09 April 2012 - 11:08 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1