Erik Borghouts

Erik Borghouts

  • NA
  • 11
  • 32.7k

Switch Case, a constant value is expected

Nov 30 2013 11:43 AM
The switch doesn't work, any help is welcome


using System;
using System.Windows.Forms;
using System.IO;
using Valor.Core;
using Valor.Core.Plugins;
using Valor.Utils;
using Valor.Utils.Templates;
using Valor.Boms;
using Valor.Assemblies;
using Valor.Boards;

namespace nsOFD
{
    public class Script
    {
        [InitLibrary("Opportunities for Defect", "Generate OFD Report")]
        public static void InitLibrary()
        {
        }
       
        [Script("Report oveview OFD", ScriptCategory.Misc)]

        public static ExecutionResult OFD(string[] Args)
        {
            ExecutionResult functionReturnValue = default(ExecutionResult);
            Board board = default(Board);
            Bom bom = default(Bom);
            Pca pca = default(Pca);
            //Enter customer name that will appear in sheet headers
            string custName = "Test";


            //Find out what the active object is
            switch (true)
            {
                case ValorApplication.ActiveObject is Bom:
                    bom = (Bom)ValorApplication.ActiveObject;
                    pca = (Pca)bom.Pca;
                    board = pca.Board;
                    if (board == null)
                    {
                        MessageBox.Show("The selected PCA does not have a Board attached!","No PCA", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                        return functionReturnValue;
                    }
                    break;
                case ValorApplication.ActiveObject is Pca:
                    pca = (Pca)ValorApplication.ActiveObject;
                    board = pca.Board;
                    bom = (Bom)pca.Bom;
                    if (bom == null)
                    {
                        MessageBox.Show("The selected PCA does not have a Bom attached!", "No BOM", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                        return functionReturnValue;
                    }
                    if (board == null)
                    {
                        MessageBox.Show("The selected PCA does not have a Board attached!", "No Board", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                        return functionReturnValue;
                    }
                    break;
                default:
                    MessageBox.Show("Please select a PCA!", "Select PCA", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                    return functionReturnValue;
            }
        }
    }
}

Answers (2)