Code not working as expected

I have an output that is calculated via a look up table. But, I want to add a line or two of code so that this is skipped if a variable != a specific string.

what I have:

if (Inputs.CH_Location.Value == “US” || Inputs.CH_Location.Value == “CA” || Inputs.CH_Location.Value == “QC”)

Inputs.CH_JetSpare.Value = PCLookUp.DataLookup(“GAS_JET_HIGH_ALTITUDE”, Inputs.CO_Elevation.Value, Inputs.CH_JetInstalled.Value);
Inputs.CH_JetSparePN.Value = PCLookUp.DataLookup(“GAS_JET_PART_NUMBER”, “Hardt Part Number”, Inputs.CH_JetSpare.Value);

switch (Inputs.CO_Elevation.Value)

case “1000”: Inputs.CH_JetSpare.Value = “Not Required”; Inputs.CH_JetSparePN.Value = “Not Required”;

(Inputs.CH_JetSpare.Value = "Not Required ");

If I leave out the ‘else’ statement, it works, but I want to be able to display either the value from the table, or “Not required” if CH_Locations.Value != CA, US or QC.

To me, the conditions of the ‘If’ statement should set the Inputs.CH_JetSpare.Value if inputs.location.Value == CA, US or QC. And continue with the switch statement…

It should not return a value if the ‘if’ statement is not met, but I can’t figure out how to add the ‘else’ part… I keep getting an error, that either { and } are missing, and/or that the ‘else’ statement is invalid / wrong…

(And, what do the numbers in the ( ) mean in the error message?)

you’re missing braces to indicate the block of things that are part of the if()

Assuming you want everything between the if(..) and the else to only happen when the if is true …

if (Inputs.CH_Location.Value == "US" || Inputs.CH_Location.Value == "CA" || Inputs.CH_Location.Value == "QC")
	Inputs.CH_JetSpare.Value = PCLookUp.DataLookup("GAS_JET_HIGH_ALTITUDE", Inputs.CO_Elevation.Value, Inputs.CH_JetInstalled.Value);
	Inputs.CH_JetSparePN.Value = PCLookUp.DataLookup("GAS_JET_PART_NUMBER", "Hardt Part Number", Inputs.CH_JetSpare.Value);

	switch (Inputs.CO_Elevation.Value)
		case "1000": 
			Inputs.CH_JetSpare.Value = "Not Required"; Inputs.CH_JetSparePN.Value = "Not Required";

	(Inputs.CH_JetSpare.Value = "Not Required ");

edited - to fix “fancy” quotes, missing braces in switch function, and a default on the case

edit #2 - fixed bad semi-colon after “default”

1 Like

Thanks, but still dosen’t work. I thought I had the right curly brackets, and I’ve tried a few different combinations. But I still get 4 errors per your example:

Make sure your quotes are the straight quotes (like the last line) and not the “smart” quotes as I see in the first few lines.

1 Like

So, getting the invalid error for the ‘else’ and I seem to be missing the curly brackets… somewhere.

I’m also assuming the numbers in the brackets (63, 17) are indicators for where the error is [likely] occurring. But how do you navigate / know what they are point at?

Looks like a missing ‘{’ at the beginning of your switch - well, and end. The whole switch should be in braces.

And the file you can look at is listed in the error message. Don’t close the dialog and open up that filename. The line numbers are for that file.

Nope. just added a { in front of / on top of the ‘switch’ and a } after the last one after the switch code & before the { on top of the ‘else’…

same error messages…

Did you check the file in your AppData\Local\Temp\ConfigDump\Client folder?

My bad for not fixing the text I copied from the original post :frowning:

Maybe we blame Josh for not having a filter on code blocks? :smirk:

1 Like

OK, got the error file. Not too sure what I’m looking at. I guess maybe this is better opened in something other that ‘notepad’?

OK, also opened it up in visual studio. the numbers in the brackets don’t corollate to any of the lines of code… (I have 1-42 lines…)

Ok, thanks for the update.

OK, missing the “default” (what does that do?)

and I’m still getting an error message, missing a " : " at (69, 10)

Default catches when nothing matches your cases.

Sorry for including yet another typo …


Change the ; after default to a :.

The default: ... break; might not be necessary in a switch case. it’s like the else condition if non of the prior case conditions were met.

Thanks Calvin! Much appreciated!

But I still get an error. this time something about "Only assignment, call, increment … can be used as a statement…

Where is that code being used?

Don’t know what you mean…

In a configurator… trying to assign values based on the “if” statement being true, then do the ‘else’ if the ‘if’ is false…

I have two combo boxes, one links off the other. and this is what I’m trying to turn off with the ‘if’ statement…

It’s code on the combo box, on the ‘on field validation’ expression

You may want to investigate the Enabled* property expression to do this.

  • Going from memory, but there’s an expression that you can do that enables or disables a control. Enter an expression that returns true or false.