【已解决】VB.Net中提示:statement cannot appear outside of a method body multiline lambda,using must end with a matching End using,character is not valid

【问题】

VB.Net中,写了几行代码:

Public Class Form1

    using System.Text.RegularExpressions;


    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load


    End Sub
End Class

结果提示错误:

statement cannot appear outside of a method body multiline lambda

statement cannot appear outside of a method body multiline lambda

【解决过程】

1.把using移动到class之外:

using System.Text.RegularExpressions;

Public Class Form1




    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load


    End Sub
End Class

结果问题依旧。

2.参考了:

10. Parameters to Procedures

大概知道含义是,该行代码,不能用在函数或过程之外,

感觉应该是要移动到此处的Form1_Load内。

结果把代码变为:

Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        using System.Text.RegularExpressions;


    End Sub
End Class

却又出现错误:

using must end with a matching End using

using must end with a matching End using

所以,还是不对。

3.最后,搞清楚此处本意是,要在VB.Net导入正则表达式的类。

然后参考了:

正则表达式在VB.NET中的应用

改为Imports:

Imports System.Text.RegularExpressions;

Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load


    End Sub
End Class

然后又提示:

character is not valid

character is not valid

4.然后再把最后的分号去掉:

Imports System.Text.RegularExpressions

Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load


    End Sub
End Class

最后就可以解决此处所有的问题了:

imports all ok

 

【总结】

VB.Net中:

  • 正则表达式的类是System.Text.RegularExpressions
  • 导入类是用Imports,最后不要加分号:
    • Imports System.Text.RegularExpressions
  • 写普通语句时,不能单独写在函数或过程之外;


发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

无觅相关文章插件,快速提升流量