2

早上好!

我希望有人可以帮助我解决一个可能很简单的问题,但我无法让事情按照我想要的方式工作。我目前正在处理具有“包罗万象”文本字段的报告。在此字段中,用户可以输入他们想要的任何内容,并且有时会以列格式输入信息(例如 1.1)。此字段允许用于在此字段中创建“行”的回车。问题是用户希望此字段中的“列”在报告中对齐,而不必在输入信息时计算列之间的空格(例如 1.2)。问题是即使输入了此类信息,也没有设置协议或格式指南。可能有多个“字幕”,行,由字幕分隔的行等。

我目前正在尝试将每一行分开,根据需要对每一行进行格式化,然后将其重新组合在一起,如下所示:

    Dim output As String
    Dim sections as String
    Dim returnCount as Int 
    Dim leftText as String
    Dim rightText as String
    Dim sectionTogether as String
    Dim totalText as String
    Dim textLength as Int

    output = {table.textfield}

    sections = ExtractString(output, Chr(10), Chr(10))

    If Instr(sections,"  ") > 0 Then
      leftText = Left(sections, Instr(sections, "  "))
      textLength = Length(Left(sections, Instr(sections, "  "))
      rightText = Right(sections, Instr(sections, "  "))
      Replace(sections,"  "," ")
      sectionTogether = rightText + (Space(20) - (textLength - 3)) + leftText
      totalText = totalText + sectionTogether
      formula = totalText
    else
      formula = output

这是我正在尝试做的事情的要点。几点注意事项:1)我知道我缺少某种循环来格式化每个部分,但我不知道如何在水晶中设置它 2)我有 VB 编程经验,但我对水晶及其有限的工具不熟悉所以我感到手足无措,我很难找到我将在 Visual Studio 3 中使用的方法和工具)我的语法也可能在一些地方不正确,因为我仍在学习如何设置它,我真的很想念调试器。

我希望有人可以帮助我,我已经研究了一个多星期,感觉就像我的头撞到了墙上。

先感谢您。

The output examples
ex. 1.1
"Your current charges are:
Jan          12.89
Feb         117.44
Mar          15.02
Apr        4.17"

ex. 1.2
"Your current charges are:
Jan                       12.89
Feb                      117.44
Mar                       15.02
Apr                        4.17"
4

1 回答 1

3

您要做的第一件事是通过 split() 拆分行,如下所示:

local stringvar array wallOText := split({table.textfield},chr(10));

这将为您提供一个字符串数组,其中每个数组条目都是一个“行”。现在您可以使用以下内容遍历您的行:

for i := 1 to ubound(wallOText) step 1 do <some stuff to wallOText[i]>

现在,让列右对齐有点棘手,但这里有一些代码可以帮助您入门。您可以根据需要调整列宽(在本例中为 20 个空格)。另请注意,您必须使用固定宽度的字体。

local stringvar output;
local stringvar array row;
local numbervar i;
local numbervar j;
local stringvar array wallOText := split({@some text},chr(10));
local stringvar elem;

for i := 1 to ubound(wallOText) do  //loop over lines
    (row := split(wallOText[i]," ");
     for j := 1 to ubound(row) do //loop over words
        (elem := trim(row[j]); //get current element and cut white space
         if not(elem="") then 
         output := output + space(20-len(elem)) + elem); //build output string
     output := output + chr(10));

output
于 2012-04-11T18:26:35.703 回答