调用目标已引发异常
我知道这是一个相对常见的错误,但我正在使用一个应用程序,该应用程序允许使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想使用 string.split 它将使得这更容易,
例如
如果您没有 .net 4.0,则以下是编写 IsNullOrWriteSpace 的方法
You might want to use string.split it will make this a lot easier
e.g.
Here's how you write IsNullOrWriteSpace if you don't have .net 4.0