How to execute a selected statement?

switch statement - GA

  • The room number that we extracted, i need it to be used in the switch statement below to refenrence the array for the correct room #. public void CcmcRoom() { int room; room = 601; //FromFile("c:\\lightsr\\test.txt") (room ); switch (room ) //("c:\\lightsr\\test.txt")) { case 601: Console.WriteLine("You selected: 601"); // Perform action 601 break; case 602: Console.WriteLine("You selected:602"); // Perform action 602 break; case 603: Console.WriteLine("You selected: 603"); // Perform action 603 break; case 604: Console.WriteLine("You selected: 604"); // Perform action 604 break; case 605: Console.WriteLine("You selected:605"); // Perform action 605 break; case 606: Console.WriteLine("You selected: 606"); // Perform action 606 break; case 607: Console.WriteLine("You selected: 607"); // Perform action 607 break; case 608: Console.WriteLine("You selected:608"); // Perform action 608 break; case 609: Console.WriteLine("You selected: 609"); // Perform action 609 break; case 610: Console.WriteLine("You selected: 610"); // Perform action 610 break; case 611: Console.WriteLine("You selected:611"); // Perform action 611 break; case 612: Console.WriteLine("You selected: 612"); // Perform action 612 break; case 613: Console.WriteLine("You selected: 613"); // Perform action 613 break; case 614: Console.WriteLine("You selected:614"); // Perform action 614 break; case 615: Console.WriteLine("You selected: 615"); // Perform action 615 break; case 616: Console.WriteLine("You selected: 616"); // Perform action 616 break; case 617: Console.WriteLine("You selected:617"); // Perform action 617 break; case 618: Console.WriteLine("You selected: 618"); // Perform action 618 break; case 619: Console.WriteLine("You selected: 619"); // Perform action 619 break; case 620: Console.WriteLine("You selected:620"); // Perform action 620 break; case 621: Console.WriteLine("You selected: 621"); // Perform action 621 break; case 622: Console.WriteLine("You selected:622"); // Perform action 622 break; case 623: Console.WriteLine("You selected: 623"); // Perform action 623 break; case 624: Console.WriteLine("You selected: 624"); // Perform action 624 break; case 625: Console.WriteLine("You selected:625"); // Perform action 625 break; case 626: Console.WriteLine("You selected: 626"); // Perform action 626 break; case 627: Console.WriteLine("You selected: 627"); // Perform action 627 break; case 628: Console.WriteLine("You selected: 628"); // Perform action 628 break; default: Console.WriteLine("Bad selection"); break; } } }

  • Answer:

    Hi, Amy: I created a new C# source file orders.cs in the project we did earlier, contents are given below. As we discussed, there is a namespace Hospitals.Orders defined in this assembly, and the class Switchbox with its data members and methods is a part of that. To call this new class for testing purposes, I added a couple of lines to the textextract.cs file from the earlier project. One is the "initialization" code for making the World 1/2 box configured to write digital lines as needed. We should clear up how line 5 is supposed to be managed; for the present I've tried to treat it as read digital. I put this line in the Main method of the TxtXtrct class, just ahead of the call to TxtXtrct.ListItems: Hospital.Orders.Switchbox.MyInit(); The exact location is not critical, so long as it is called before then. Then, inside the ListItems method I inserted this line right after the room number is parsed out: Hospital.Orders.Switchbox.Lampset( int.Parse(roomnumber), true); This uses the method for converting the string roomnumber to an integer that we discussed earlier. The MyInit and Lampset methods of class Switchbox are currently built on "stubs" for the serial port communication called: SerialWrite( byte c) SerialWrite( byte c, byte i ) in the same class Switchbox. It is these which we would proceed to replace with code for the actual serial port communications. Currently these stubs write to the Console window, similar to how we treated output in the earlier project. Testing so far has been limited to running the program against the original test file, which "turns on the lamp" for room 11. Let me know your questions once you've had a chance to compile and look over the new code. regards, mathtalk-ga * * * * * * * < orders.cs > * * * * * * * * * using System; using System.IO; namespace Hospital.Orders { public class Switchbox { private static int[] port = new int[31]; private static byte[] line = new byte[31]; private static byte[] pimg = new byte[5]; private static byte[] pcmd = new byte[5]; static Switchbox() { // port A and five lines port[0] = 0; line[0] = 1; port[1] = 0; line[1] = 2; port[2] = 0; line[2] = 4; port[3] = 0; line[3] = 8; port[4] = 0; line[4] = 32; // port B and eight lines port[5] = 1; line[5] = 1; port[6] = 1; line[6] = 2; port[7] = 1; line[7] = 4; port[8] = 1; line[8] = 8; port[9] = 1; line[9] = 16; port[10] = 1; line[10] = 32; port[11] = 1; line[11] = 64; port[12] = 1; line[12] = 128; // port C and six lines port[13] = 2; line[13] = 1; port[14] = 2; line[14] = 2; port[15] = 2; line[15] = 4; port[16] = 2; line[16] = 8; port[17] = 2; line[17] = 16; port[18] = 2; line[18] = 32; // port D and eight lines port[19] = 3; line[19] = 1; port[20] = 3; line[20] = 2; port[21] = 3; line[21] = 4; port[22] = 3; line[22] = 8; port[23] = 3; line[23] = 16; port[24] = 3; line[24] = 32; port[25] = 3; line[25] = 64; port[26] = 3; line[26] = 128; // port E and one line port[27] = 4; line[27] = 1; // set image bits to zero for (int i = 0; i < 5; ++i) pimg[i] = 0; // set commands to write ports for (int i = 0; i < 5; ++i) pcmd[i] = Convert.ToByte(16 * (i + 10) + 1); } public static void MyInit() { // set all ports & lines to write digital except 5,28,29 SerialWrite( Convert.ToByte( 0xfb ) ); SerialWrite( (byte) 0xa0, (byte) 0x2f ); SerialWrite( (byte) 0xb0, (byte) 0xff ); SerialWrite( (byte) 0xc0, (byte) 0x3f ); SerialWrite( (byte) 0xd0, (byte) 0xff ); SerialWrite( (byte) 0xe0, (byte) 0x01 ); } public static void Lampset(int rn, bool ls) { // turn lamp for room # rn on or off int p = port[rn - 1]; byte b = line[rn - 1]; // set respective bit of port image pimg[p] |= b; // if not ls, then unset that bit if (!ls) pimg[p] ^= b; // write the affected port's image SerialWrite(pcmd[p],pimg[p]); } static void SerialWrite(byte c) { // write byte to serial comm port Console.WriteLine( "Command: {0}", Convert.ToInt16(c) ); } static void SerialWrite(byte c, byte i) { // write byte to serial comm port Console.WriteLine( "Port Cmd: {0} Bit Image: {1}", Convert.ToInt16(c), Convert.ToInt16(i) ); } } } * * * * * * * * < end of orders.cs > * * * * * * * * * * regards, mathtalk-ga

amy123456-ga at Google Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.