VBscript“预期声明"错误 [英] VBscript "Expected Statement" Error

查看:49
本文介绍了VBscript“预期声明"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 vbscript 程序,但出现了预期语句"错误.我找不到错误.我已经看到了此错误的一些示例,但它们对我没有帮助.

我是 vbscript 的新手.

这是代码.

Sub SetText(tx, lw)昏暗 t, l, r, at = -1l = Len(tx)r = ""一 = 0当 t <升t = t + 1a = Asc(Mid(tx,t,1))如果 a >= 160 或 a=60 或 a=62 或 a=38 或 a=34 或 a=39 或 a=32 然后如果 a = 32 那么r = r + " "别的r = r + "&#" + Cstr(a) + ";"万一别的r = r + Mid(tx,t,1)万一End While '错误发生在该语句的开头.如果不是 lw 那么r = "

"+ r + "</pre>"万一r = "

"+ r + "</div>"objExplorer.document.body.innerHTML = r结束子

解决方案

While ... End While ?我认为这不太对.

我认为语法是:

While counter >0...温德

试试这个,它还有其他一些改进(我很确定 Mid 使用基数 1,而不是基数 0 - 如果不将 For t = 1 更改为 Len (tx) to For t = 0 to Len (tx) - 1):

Sub SetText (tx, lw)昏暗 t, r, c, a'标准前缀和可选的预标签.'r = "

"如果不是 lw 那么r = r + "

"万一'处理字符串中的每个字符.'对于 t = 1 到 Len (tx)'获取字符和代码.'c = 中 (tx,t,1)a = 升序 (c)'如果它是特殊字符之一,请更改它.'如果 a = 32 那么c = "&nbsp;"别的如果 a >= 160 或 a = 60 或 a = 62 或 a = 38 或 a = 34 或 a = 39 然后c = "&#" + Cstr (a) + ";"万一万一'在结果中添加字符"(此时它可能是一个字符串).'r = r + c下一个'可选的前置标签和标准后缀.如果不是 lw 那么r = r + "</pre>"万一r = r + "</div>"'注入页面.objExplorer.document.body.innerHTML = r结束子

我还没有彻底测试过(好吧,真的)所以让我知道是否有问题(或者只是恢复到您的原始解决方案,将 End While 替换为 Wend,并可能改变 base-1 Midt 范围).

I'm working on a vbscript program and I have got and "Expected Statement" Error. I cannot find the error. I've seen some samples of this error but they didn't help me.

I am new to vbscript.

Here is the code.

Sub SetText(tx, lw)
    Dim t, l, r, a

    t = -1
    l = Len(tx)
    r = ""
    a = 0

    While t < l
        t = t + 1
        a = Asc(Mid(tx,t,1))

        If a >= 160 or a=60 or a=62 or a=38 or a=34 or a=39 or a=32 Then
            If a = 32 Then
                r = r + "&nbsp;"
            Else
                r = r + "&#" + Cstr(a) + ";"
            End If
        Else
            r = r + Mid(tx,t,1)
        End If

    End While 'The error occurs at the beginning of this statement.'

    If Not lw Then
        r = "<pre>" + r + "</pre>"
    End If

    r = "<div style='width:auto; height:auto;'>" + r + "</div>"        
    objExplorer.document.body.innerHTML = r
End Sub

解决方案

While ... End While ? I don't think that's quite right.

I think the syntax is:

While counter > 0
    ...
Wend

Try this instead, it has some other improvements (I'm pretty certain Mid uses base 1, not base 0 - if not change the For t = 1 to Len (tx) to For t = 0 to Len (tx) - 1):

Sub SetText (tx, lw)
    Dim t, r, c, a

    'Standard prefix and optional pre tag.'
    r = "<div style='width:auto; height:auto;'>"
    If Not lw Then
        r = r + "<pre>"
    End If

    'Process each character in string.'
    For t = 1 to Len (tx)
        'Get character and code.'
        c = Mid (tx,t,1)
        a = Asc (c)

        'Change "character" if it is one of the special ones.'
        If a = 32 Then
            c = "&nbsp;"
        Else
            If a >= 160 or a = 60 or a = 62 or a = 38 or a = 34 or a = 39 Then
                c = "&#" + Cstr (a) + ";"
            End If
        End If

        'Add "character" to result (it may be a string at this point).'
        r = r + c
    Next

    'Optional pre tag and standard suffix.'
    If Not lw Then
        r = r + "</pre>"
    End If
    r = r + "</div>"

    'Inject into page.'
    objExplorer.document.body.innerHTML = r
End Sub

I haven't tested this thoroughly (well, at all, really) so let me know if there's a problem (or just revert to your original solution, replacing End While with Wend, and possibly changing the range of t for base-1 Mid).

这篇关于VBscript“预期声明"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆