1

I want to write rows of data from Excel to an XML file. However, I need to validate the data before I commit to file. I know that WriteLine() has its own end of line but I need to add it in the string. So I want to do something like this:

strXML = "<BOM>" & {??} _
 & "<BOM_NBR>" & p_typBomValues.strParentPNbr & "</BOM_NBR>" & {??} _
 & "<DESC>" & p_typBomValues.strParentDesc & "</DESC>" & {??} _
 & "<ECO_NBR>" & p_typBomValues.strEcoNbr & "</ECO_NBR>" & {??} _
 & "<REV>" & p_typBomValues.strRevision & "</REV>"" & {??}
 .WriteLine(strXML)

...not this:

    .WriteLine ("<BOM>")
    .WriteLine ("<BOM_NBR>" & p_typBomValues.strParentPNbr & "</BOM_NBR>")
    .WriteLine ("<DESC>" & p_typBomValues.strParentDesc & "</DESC>")
    .WriteLine ("<ECO_NBR>" & p_typBomValues.strEcoNbr & "</ECO_NBR>")
    .WriteLine ("<REV>" & p_typBomValues.strRevision & "</REV>")

...where {??} is the end of line character. I've seen Chr(10) & Chr(13) mentioned as an option but nothing definitive.

pnuts
  • 58,317
  • 11
  • 87
  • 139
CarloC
  • 155
  • 12
  • 1
    What the "end of line character" is depends on which OS you're on. On Windows it's typically `vbCrLf`: on Mac I think it's `vbLf`. If you use `vbNewLine` it will use whatever is the system-appropriate one. https://en.wikipedia.org/wiki/Newline – Tim Williams Oct 09 '15 at 19:07

1 Answers1

1

FSO is poorly documented about what it considers line breaks on reading and writing. But you will probably be safe putting out either a return-and-linefeed (vbCrLf) or a bare linefeed (vbLf). On Windows, the former is safest.

strXML = "<BOM>" & vbCrLf _
         & "<BOM_NBR>" & p_typBomValues.strParentPNbr & "</BOM_NBR>" & vbCrLf _
         & . . .
Paul Kienitz
  • 878
  • 6
  • 25