這樣編譯失敗, 是因為If 裡面含有 Switch嗎?
if year(getfieldDate("存貨", "Q")) = year(getfieldDate("月營收", "M"))
then if month(getfieldDate("存貨", "Q")) = 03
then Switch (04)
Case 04: x2=3;
 
        
        這樣編譯失敗, 是因為If 裡面含有 Switch嗎?
if year(getfieldDate("存貨", "Q")) = year(getfieldDate("月營收", "M"))
then if month(getfieldDate("存貨", "Q")) = 03
then Switch (04)
Case 04: x2=3;
不是放在IF裡面的問題,而是你的Switch語法錯誤。
Switch (month(getfieldDate("存貨", "Q")))
Case 04:
x2=3
Hello 凡恩大叔,
switch 需要有 begin 和 end 來框住case。
另外,if year(getfieldDate("存貨", "Q")) = year(getfieldDate("月營收", "M")) then if month(getfieldDate("存貨", "Q")) = 03
其實就跟 if year(getfieldDate("存貨", "Q")) = year(getfieldDate("月營收", "M")) and month(getfieldDate("存貨", "Q")) = 03 相同,不需要寫兩個if。
小編會這樣寫比較容易閱讀:
if year(getfieldDate("存貨", "Q")) = year(getfieldDate("月營收", "M")) and month(getfieldDate("存貨", "Q")) = 03 then begin
switch(04) begin
case 1 : x2 = 3;
end;
end;
感謝 虎科大許教授 的熱心回覆。
2 評論