1

我正在尝试将此 HTML 保存到 HTML 文件中。这段代码有两个问题。

1.它认为“刷新”部分不是字符串的一部分

我已尝试使用 Chr(34) 而不是 " 来修复此购买,但它仍然使我陷入错误 2

2. 当我打开 HTML 文件时,它的所有文本都有引号,看起来很垃圾

我将如何解决这些错误?谢谢。

  Dim nFileNum as Integer

    nFileNum = 4

    Open "WebWindow.html" For Output As #nFileNum 'Open the file to put information into

        Write #nFileNum, "<meta http-equiv="refresh" content="1" />" 'Refresh Script
        Write #nFileNum, "<P>10% Through the current test:</p>"
        Write #nFileNum, "<p>Invoices 1/20 (processing)</p>"
        Write #nFileNum, "<p>POs 0/20 (waiting)</p>"

    Close #nFileNum 'Close the File

编辑:

使用双引号是可行的,但 Web 窗口中的输出现在如下所示:

"" "
10% Through the current test:

" "
Invoices 1/20 (processing)

" "
POs 0/20 (waiting)

"

在 HTML 文件中,它看起来像这样:

"<meta http-equiv=""refresh"" content=""1"" />"
"<P>10% Through the current test:</p>"
"<p>Invoices 1/20 (processing)</p>"
"<p>POs 0/20 (waiting)</p>"

所以我仍然必须处理问题2....


*编辑编辑!固定的 *

我用双引号解决了问题 1(谢谢你们)并自己解决了问题 2。我没有使用 Write,而是使用了 Print。Print 与 write 执行相同的操作,但不会将引号与字符串一起放入文件中。

我的新工作代码:

Function WebOutput()

Dim nFileNum As Integer
Dim Line2 As String

Line2 = "<P>10% Through the current test:</p>"

nFileNum = 4

Open "C:\TestPartner\Config\WebWindow.html" For Output As #nFileNum 'Open the file to put information into

    Print #nFileNum, "<meta http-equiv=""refresh"" content=""1"" />" 'Refresh Script
    Print #nFileNum, Line2
    Print #nFileNum, "<p>Invoices 1/20 (processing)</p>"
    Print #nFileNum, "<p>POs 0/20 (waiting)</p>"

Close #nFileNum 'Close the File
4

2 回答 2

1

要在 VB 中转义引号,请""尝试"<meta http-equiv=""refresh"" content=""1"" />"

于 2013-09-10T12:35:56.770 回答
0

在编写之前修改您的函数以将字符串中的任何引号替换为双引号。

string = replace(string, Chr(34), Chr(34) & Chr(34))

类似的东西。应该工作。如果两个不起作用,请尝试使用多少 Chr(34) & chr(34) & chr(34)。

您将不得不修改现有代码,您无法绕过它,但这是最简单的方法。

于 2013-09-13T12:57:38.790 回答