Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Runs Commands in order

Runs Commands in order

Scheduled Pinned Locked Moved Managed C++/CLI
c++databasewinformshelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    newkid
    wrote on last edited by
    #1

    Hi, I'm using Windows Forms C++. I'm getting the user to add commands to a listbox then they click on a button and this runs the commands in the listbox. The problem I have is, I don't know how to run these commands from an index number because they are currently being run in the order shown below and not in the order of where they are in the listbox. Does anyone have any ideas? do { if(lstCommands->Items->Count > 0) { if(lstCommands->Items->Contains("Move forward")) { protocol_test(2, distance, 0); } else if(lstCommands->Items->Contains("Move Back")) { protocol_test(3, distance, 0); } else if(lstCommands->Items->Contains("Turn Right")) { protocol_test(4, distance, degrees); lstCommands->Items->Remove("Turn Right"); } else if(lstCommands->Items->Contains("Turn Left")) { protocol_test(5, distance, degrees); } } else if(lstCommands->Text->Empty) { MessageBox::Show("No Commands selected","No Commands",MessageBoxButtons::OKCancel,MessageBoxIcon::Exclamation); } } while(!lstCommands->Items->Count == 0);

    L 1 Reply Last reply
    0
    • N newkid

      Hi, I'm using Windows Forms C++. I'm getting the user to add commands to a listbox then they click on a button and this runs the commands in the listbox. The problem I have is, I don't know how to run these commands from an index number because they are currently being run in the order shown below and not in the order of where they are in the listbox. Does anyone have any ideas? do { if(lstCommands->Items->Count > 0) { if(lstCommands->Items->Contains("Move forward")) { protocol_test(2, distance, 0); } else if(lstCommands->Items->Contains("Move Back")) { protocol_test(3, distance, 0); } else if(lstCommands->Items->Contains("Turn Right")) { protocol_test(4, distance, degrees); lstCommands->Items->Remove("Turn Right"); } else if(lstCommands->Items->Contains("Turn Left")) { protocol_test(5, distance, degrees); } } else if(lstCommands->Text->Empty) { MessageBox::Show("No Commands selected","No Commands",MessageBoxButtons::OKCancel,MessageBoxIcon::Exclamation); } } while(!lstCommands->Items->Count == 0);

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      newkid wrote:

      Does anyone have any ideas?

      Yes. An Object Oriented Design would be far easier to understand. In this regard finding errors would be relatively simple.

      If/then and switch statements are the simplest form of instance –specific behavior….
      The more paths through a program the less likely the program is to be correct….
      The proliferation of conditionals reduces reliability….
      This problem is compounded when conditionals are duplicated.

      These problems can all be eliminated by converting the conditional
      logic to messages, either with subclasses or delegation.

      Kent Beck - Implmentation Patterns

      led mike

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups