vb.net 在 VB 的水晶报表中设置公式字段中的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25746346/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 18:10:11  来源:igfitidea点击:

Set values in formula fields in crystal report from VB

vb.netcrystal-reports

提问by PandaUser

I'm new in vb and crystal report so please help me from my problem. I'm assigning values using vb codes to a formula field from my crystal report. Here is my code:

我是 vb 和水晶报告的新手,所以请帮助我解决我的问题。我正在使用 vb 代码将值分配给我的水晶报告中的公式字段。这是我的代码:

 Dim report As CrystalDecisions.CrystalReports.Engine.ReportDocument
        report = New report_Student()
        report.DataDefinition.FormulaFields("student").Text = "Slone" & Chr(13) & "Thompson"
        frm_print.viewerReport.ReportSource = report
        frm_print.viewerReport.RefreshReport()
        frm_print.Show()

i place this in button click event. Now i have an error on running this, before it loads the crystal report from viewer this error shows:

我把它放在按钮点击事件中。现在我在运行它时出现错误,在它从查看器加载水晶报告之前,此错误显示:

The remaining text does not appear to be part of the formula.
Details: errorKind
Error in formula student:
'Slone
'

回答by Vadim Levkovsky

I guess as you have formula field (not text object) you should use formula there:

我猜你有公式字段(不是文本对象),你应该在那里使用公式:

    report.DataDefinition.FormulaFields("student").Text = _
        ControlChars.Quote + "Slone" + ChrW(13) + "Thompson" + ControlChars.Quote

So, in result formula will contain one text literal ("Slone\nThompson").

因此,在结果公式中将包含一个文本文字(“Slone\nThompson”)。

Not tried this, but hope it should work.

没有试过这个,但希望它应该有效。

If not, then probably you need to use CR inner function ChrW() for newline in next way:

如果没有,那么您可能需要在下一个方式中使用 CR 内部函数 ChrW() 作为换行符:

    report.DataDefinition.FormulaFields("student").Text = _
        ControlChars.Quote + "Slone" + ControlChars.Quote + _
        " + ChrW(13) + " + _
        ControlChars.Quote + "Thompson" + ControlChars.Quote

So, in result two text literals ("Slone" and "Thompson") will be concatenated with result of CR inner function ChrW().

因此,在结果中,两个文本文字(“Slone”和“Thompson”)将与 CR 内部函数 ChrW() 的结果连接。

In CR formula editor it will be shown as

在 CR 公式编辑器中,它将显示为

    "Slone" + ChrW(13) + "Thompson"

But I expect 1st way should work.

但我希望第一种方式应该有效。