0

與我的第一個問題類似。我想告訴我的地址在包含字段的文本框,如下所示當某些字段爲空時,公式將不會顯示

{Company} 
{AddLine1} 
{AddLine2} 
{ZIP}{State}{City} 
{Country} 

與我相關的線(希望你們中的一些人)是{ZIP} {城市} {}國。我想生成的是一致的尋址格式,即使ZIP,城市或州字段在數據庫中留空,也不會有空白區域或縮進。這行應該仍然與其餘的行對齊,而不是縮進。我也希望在zip,state,city之間插入逗號,並將它們留在不相關的地方。爲此我寫了一個公式。下面:

If isnull({BILL_TO.ZIP}) or trim({BILL_TO.ZIP})= "" Then "" else {BILL_TO.ZIP} 
+ 
(If isnull({BILL_TO.State}) or trim({BILL_TO.State})= "" Then "" 
    else(If not isnull({BILL_TO.ZIP}) and length(trim({BILL_TO.ZIP})) <> 0 Then ", "  else "") + {BILL_TO.State}) 
+ 
(If isnull({BILL_TO.CITY}) or length(trim({BILL_TO.CITY})) = 0 Then "" 
    else(

      If (not isnull({BILL_TO.State}) and length(trim({BILL_TO.State})) <> 0) 
       or 
       (not isnull({BILL_TO.Zip}) and length(trim({BILL_TO.Zip})) <> 0) 

      Then ", " else "")+ {BILL_TO.CITY})) 

問題是,當只有一個城市(沒有州或拉鍊輸入)公式本身不會顯示。但是,當其他人出席時,它會顯示。

任何人都可以在此代碼中看到一個錯誤?它殺了我

感謝您的幫助。

期待您的迴音!

回答

0

爲每個數據庫字段創建一個公式字段。例如:

// {@CITY} 
If Isnull({BILL_TO.CITY}) Then 
    "" 
Else 
    Trim({BILL_TO.CITY}) 

// {@STATE} 
If Isnull({BILL_TO.STATE}) Then 
    Space(2) 
Else 
    Trim({BILL_TO.STATE}) 

// {@ZIP} 
If Isnull({BILL_TO.ZIP}) Then 
    Space(5) //adjust to meet your needs 
Else 
    Trim({BILL_TO.ZIP}) 

將每個公式字段嵌入到文本對象中。

設置文本對象及其字段的格式以滿足您的需要。

**編輯**

我你有數據質量問題,在國家和ZIP公式解決這些問題(因爲他們將是一個常數長度)。我會添加逗號和文本對象的間距。

+0

這並沒有解決在ZIP,City和State之間有條件地添加空格和逗號的問題。 – Ryan

1

在這個公式中有很多if-then-elses,所以很難說,但是如果它沒有顯示任何可能意味着你在某個地方使用某個字段而沒有首先處理其空條件的地方。更簡單一些可能是你最好的選擇:

local stringvar output; 
if not(isnull({Customer.Postal Code})) then output:=trim({Customer.Postal Code}) + ', '; 
if not(isnull({Customer.Region})) then output:=output + trim({Customer.Region}) + ', '; 
if not(isnull({Customer.City})) then output:=output + trim({Customer.City}) + ', '; 

left(output,length(output)-2) 
相關問題