an you please help me optimize the code structure?
I have a piece of code as shown below. The entire code contains three 'switch' statements, but the 'alert' reminder no longer works after running. Is it not possible to have 'switch' statements nested within other 'switch' statements? Can you please help me optimize the code structure? Thank you.
if ZM = 0 and LM = 0 then
alert(---
"No!"
---)
else
switch 'L&Z' do
case 1:
(
let ;
if ZM < 'quantity' then
alert(---
"No!"
---)
else
if ZM >= 'quantity' then
switch '1' = '2' do
case true:
(
let;
let;
);
alert(---
"Yes!"
---);
end
)
case false:
(
alert(---
"No!"
---);
)
end
end
end
end
)
case 2:
if ZM = 0 and LM < 'quantity' then
alert(---
"No!"
---)
else
if LM >= 'quantity' then
let;
switch '1' = '2' do
case true:
(
let;
let;
);
alert(---
"Yes!"
---);
end
)
case false:
(
alert(---
"No!"
---);
)
end
end
else
if LM < 'quantity' and ZM != 0 then
let;
let;
let;
if then
let;
let;
alert(---
"Ok!"
---)
);
end
end
end
end
end
end
end
end
10 replies
-
Let me see if I read you code properly:
check if ZM = 0 and LM = 0
if true than show NO in an alert box.
if false switch on field 'L&Z'.
if the value of L&Z = 1 then check if ZM is less than the value of quantity
if true then show NO in an alert box.
if false than check if the value of ZM is greater than or equal to value of quantity
if true then do a switch when field '1' equals field '2'. (side note, you don't need this if statement since you in the else part of the one above. So if it fails ZM less than the value of quantity, then it must be greater than or equal to the value of quantity.)
if true then show YES in an alert box.
if false then show NO in an alert box.
if the value of L&Z = 2 then check if ZM = 0 and LM is less than the value of quantity.
if true then show NO in an alert box.
if false then check if LM is greater than or equal to the value of quantity. (side note, again not needed since you are in the else part)
if true then run a switch that checks if the value of field '1' equals to field '2'
if true then show YES in an alert box.
if false then show NO in an alert box.
then you have a loose else statement (that checks if LM is less than the value of quantity and ZM does not equal 0) that I can't seem to find an if statement to go with.
Does this code work?
Are you copying this out of the code editor in Ninox? Does this code give no errors in the editor? In addition you have let statements that are empty.
-
Try something like this
let cr := " "; let a := switch true do case ZM + LM = 0: "No1!" case ZM + LM != 0 and 出库零整' = 1 and ZM < quantity: "No2!" case ZM + LM != 0 and 出库零整' = 1 and ZM >= quantity and cnt(split(text(code), cr)) = quantity: "Yes1!" case ZM + LM != 0 and 出库零整' = 1 and ZM >= quantity and cnt(split(text(code), cr)) != quantity: "No3!" case ZM + LM != 0 and 出库零整' = 2 andZM = 0 and LM < quantity: "No4!" case ZM + LM != 0 and 出库零整' = 2 andZM = 0 and LM >= quantity and cnt(split(text(code), cr)) = quantity: "Yes2!" case ZM + LM != 0 and 出库零整' = 2 andZM = 0 and LM >= quantity and cnt(split(text(code), cr)) != quantity: "Yes3!" case ZM + LM != 0 and 出库零整' = 2 andZM = 0 and LM < quantity and ZM != 0: "Yes4!" end; alert(--- a ---)
I am sure it can be massively simplified with a bit of thought.
Content aside
- Status Answered
- 5 mths agoLast active
- 10Replies
- 94Views
-
3
Following