调用目标已引发异常

发布于 2024-10-14 02:47:02 字数 1096 浏览 3 评论 0原文

我知道这是一个相对常见的错误,但我正在使用一个应用程序,该应用程序允许使用 vb.net 或 C# 进行脚本编写自定义报告。错误处理非常差,我的知识不足以添加我自己的错误处理(如果可能的话)。

我的代码只是检索存储在报告上的文本框中的值,格式为 LastName, FirstName 并截断逗号后的所有字符。该值 LastName 放置在报表上的新文本框中。这是我的代码:

Sub Detail1_Format

    Dim lastNameFirstName As String = ""
    Dim lastName As String = ""
    Dim lastNameCommaIndex As Integer=

'set lastNameFirstName value from data on report'
    lastNameFirstName = ReportUtilities.ReturnTextBoxValue(rpt,"Detail1","txtdtr_DTOOLS_CompanyName")

'find index of first comma in lastNameFirstName string'
    lastNameCommaIndex = lastNameFirstName.IndexOf(",")

'set contents of lastName using substring of lastNameFirstString'
    lastName = lastNameFirstName.SubString(0, lastNameCommaIndex)
'the error happens above when I use lastNameCommaIndex'
'to set the number of characters in my substring'

'set client name textbox value using lastName'
    ReportUtilities.SetTextBoxValue(rpt,"Detail1","txtdtr_CALC_ClientName",lastName)

End Sub

当我使用 lastNameCommaIndex 设置子字符串中的字符数时,会发生错误。如果我用数字替换它,报告就会正确发布。

I know this is a relatively common error but I am working in an application that allows custom reports to be written using vb.net or C# for scripting. Error handling is very poor and I am not knowledgable enough to add my own (if it is even possible).

My code simply retrieves a value that is stored in a textbox on the report formatted as LastName, FirstName and truncates all characters after the comma. This value LastName is placed in a new textbox on the report. Here is my code:

Sub Detail1_Format

    Dim lastNameFirstName As String = ""
    Dim lastName As String = ""
    Dim lastNameCommaIndex As Integer=

'set lastNameFirstName value from data on report'
    lastNameFirstName = ReportUtilities.ReturnTextBoxValue(rpt,"Detail1","txtdtr_DTOOLS_CompanyName")

'find index of first comma in lastNameFirstName string'
    lastNameCommaIndex = lastNameFirstName.IndexOf(",")

'set contents of lastName using substring of lastNameFirstString'
    lastName = lastNameFirstName.SubString(0, lastNameCommaIndex)
'the error happens above when I use lastNameCommaIndex'
'to set the number of characters in my substring'

'set client name textbox value using lastName'
    ReportUtilities.SetTextBoxValue(rpt,"Detail1","txtdtr_CALC_ClientName",lastName)

End Sub

The error happens when I use lastNameCommaIndex to set the number of characters in my substring. If I replace it with a number the report is published properly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花开浅夏 2024-10-21 02:47:02

您可能想使用 string.split 它将使得这更容易,

例如

   If Not String.IsNullOrWhiteSpace(lastNameFirstName) Then

        lastName = lastNameFirstName.Split(",".ToCharArray())(0)

    End If

如果您没有 .net 4.0,则以下是编写 IsNullOrWriteSpace 的方法

Function IsNullOrWhiteSpace(ByVal s As String) As Boolean

    If s Is Nothing Then
        Return True
    End If

    Return s.Trim() = String.Empty

End Function

You might want to use string.split it will make this a lot easier

e.g.

   If Not String.IsNullOrWhiteSpace(lastNameFirstName) Then

        lastName = lastNameFirstName.Split(",".ToCharArray())(0)

    End If

Here's how you write IsNullOrWriteSpace if you don't have .net 4.0

Function IsNullOrWhiteSpace(ByVal s As String) As Boolean

    If s Is Nothing Then
        Return True
    End If

    Return s.Trim() = String.Empty

End Function
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文