CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #1
    Join Date
    Jul 2011
    Posts
    6

    Shrink a whole bunch of IF statements.

    I really hate to join a forum and start asking questions, but I'm developing a program which contains a command line where you can enter commands in one window, and get the output from another (see attachment if you will). It accepts commands which I've created, and instructions from the assembly language. In total, I would expect to have somewhere around 300 commands and instructions.

    The current system I have setup is something like so:
    Code:
    public string Input = "";
    // Converts code into something readable to the interpret function.
    public void ParseInput()
    {
          // Code here would read the input offered by the text box and convert it.
          interpret();
    }
    // Reads code and decides what to do with it.
    public void Interpret();
    {
          if (input == proper_syntax)
             commandA_do();
          elseif(input == proper_syntaxB)
             commandB_do();
          // 300 elseif's later...
          else
          { // say nothing happened }
    }
    Proper syntax notwithstanding, of course. Now I would assume this is very bad to have 300 'if' long if statement (hogging resources, and clogging pipes, and whatnot). Even with the 15 or so commands I had declared using that format, it did crash the program at some times. So, what would be an effective way to condense down those if statements?
    Attached Images Attached Images

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured