home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / OPENSTEP / Utilities / ElectronHelper-2.0-MIS / ResistorObject.m < prev   
Encoding:
Text File  |  1997-02-03  |  7.4 KB  |  313 lines

  1. #import "ResistorObject.h"
  2.  
  3. @implementation ResistorObject
  4.  
  5. - (void)Calculate:(id)sender
  6. {
  7.  
  8.     // Declare variables
  9.     int Vfirstband;     // Value of firstband 
  10.     int Vsecondband;     // Value of secondband
  11.     int Vthirdband;     // Value of thirdband 
  12.     float Vfourthband;     // Value of fourthband 
  13.     int SwitchOne;     // Dummy int for switch statment 
  14.     int SwitchTwo;     // Dummy int for switch statment
  15.     int temp;
  16.     int temp2;
  17.     float resistorValue;
  18.     float resistorValueK;
  19.     float range1;
  20.     float range2;
  21.     char SRvalue[20];
  22.     char SRKvalue[20];
  23.     char SR1value[20];
  24.     char SR2value[20];
  25.  
  26.  
  27.    // Assigns the value of the currently selected button found in the
  28.    // button matrixs of Resistor using tag as a reference  
  29.        Vfirstband = [FirstBand selectedTag];
  30.        Vsecondband = [SecondBand selectedTag];
  31.        Vthirdband = [ThirdBand selectedTag];
  32.  
  33.   // thirdband: Assigns the proper value depending on which button was selected    
  34.        SwitchOne = [ThirdBand selectedTag];
  35.        Vthirdband = SwitchOne;
  36.  
  37.        switch (SwitchOne)  { // start switch
  38.  
  39.                case 2:
  40.                Vthirdband = 0.10; // Gold (ThirdBand) 
  41.                break;
  42.  
  43.                case 3:
  44.                Vthirdband = 0.01; // Silver (ThirdBand) 
  45.                break;
  46.  
  47.               case 4:
  48.                Vthirdband = 1000000; // Blue (ThirdBand) 
  49.                break;
  50.  
  51.               case 5:
  52.                Vthirdband = 10000000; // Voilet (ThirdBand)
  53.                break;
  54.  
  55.               case 6:
  56.                Vthirdband = 100000000; // Grey (ThirdBand)
  57.                break;
  58.  
  59.                                } // end switch
  60.  
  61.  
  62.  
  63.    // fourthband: Assigns the proper value depending on which
  64.    // button was selected
  65.        SwitchTwo = [FourthBand selectedTag];
  66.  
  67.        switch (SwitchTwo)  { // start switch 
  68.  
  69.                case 0:
  70.                Vfourthband = 0.20; // No Band 
  71.                break;
  72.  
  73.                case 1:
  74.                Vfourthband = 0.10; // Silver
  75.                break;
  76.  
  77.                case 2:
  78.                Vfourthband = 0.05; // Gold
  79.                break;
  80.  
  81.                                } // end switch
  82.  
  83. // Calculations
  84.  
  85. temp = Vfirstband*10;
  86. temp2 = temp + Vsecondband;
  87. resistorValue = temp2 * Vthirdband;
  88. range1 = resistorValue * Vfourthband;
  89. range1 = resistorValue - range1;
  90. range2 = resistorValue * Vfourthband;
  91. range2 = resistorValue + range2;
  92. resistorValueK = resistorValue / 1000;
  93.  
  94. // Convert a number to a string a adjust the floating point accuracy
  95. sprintf(SRvalue,"%.2f",resistorValue);
  96. sprintf(SRKvalue,"%.2f",resistorValueK);
  97. sprintf(SR1value,"%.2f",range1);
  98. sprintf(SR2value,"%.2f",range2);
  99.  
  100.  
  101.  
  102. // Assign the values to the proper display
  103.  
  104. // Display the value of the resistor in the form
  105. [ValueOhms setStringValue:[NSString stringWithCString:SRvalue]];
  106.  
  107. // Display the value of the resistor in K in the form 
  108. [ValueKOhms setStringValue:[NSString stringWithCString:SRKvalue]];
  109.  
  110. // Display the value of the range1 in the form
  111. [RangeOne setStringValue:[NSString stringWithCString:SR1value]];
  112.  
  113. // Display the value of the range2 in the form 
  114. [RangeTwo setStringValue:[NSString stringWithCString:SR2value]]; 
  115.  
  116.     
  117. }
  118.  
  119. - (void)Ohms100:(id)sender
  120. {
  121.  
  122.     [FirstBand selectCellWithTag:1]; // This will select radio button number 1
  123.     [SecondBand selectCellWithTag:0];
  124.     [ThirdBand selectCellWithTag:1];
  125.     [FourthBand selectCellWithTag:0];
  126.     [self Calculate:sender]; 
  127.     
  128. }
  129.  
  130. - (void)Ohms100K:(id)sender
  131. {
  132.  
  133.     [FirstBand selectCellWithTag:1]; // This will select radio button number 1
  134.     [SecondBand selectCellWithTag:0];
  135.     [ThirdBand selectCellWithTag:10000];
  136.     [FourthBand selectCellWithTag:0];
  137.     [self Calculate:sender]; 
  138.     
  139.     
  140. }
  141.  
  142. - (void)Ohms10:(id)sender
  143. {
  144.  
  145.     [FirstBand selectCellWithTag:1]; // This will select radio button number 1
  146.     [SecondBand selectCellWithTag:0];
  147.     [ThirdBand selectCellWithTag:1];
  148.     [FourthBand selectCellWithTag:0];
  149.     [self Calculate:sender]; 
  150.     
  151. }
  152.  
  153. - (void)Ohms10K:(id)sender
  154. {
  155.  
  156.     [FirstBand selectCellWithTag:1]; // This will select radio button number 1
  157.     [SecondBand selectCellWithTag:0];
  158.     [ThirdBand selectCellWithTag:1];
  159.     [FourthBand selectCellWithTag:0];
  160.     [self Calculate:sender]; 
  161.     
  162. }
  163.  
  164. - (void)Ohms15K:(id)sender
  165. {
  166.  
  167.     [FirstBand selectCellWithTag:1]; // This will select radio button number 15K
  168.     [SecondBand selectCellWithTag:5];
  169.     [ThirdBand selectCellWithTag:1000];
  170.     [FourthBand selectCellWithTag:0];
  171.     [self Calculate:sender]; 
  172.     
  173. }
  174.  
  175. - (void)Ohms1K:(id)sender
  176. {
  177.  
  178.     [FirstBand selectCellWithTag:1]; // This will select radio button number 1K
  179.     [SecondBand selectCellWithTag:0];
  180.     [ThirdBand selectCellWithTag:100];
  181.     [FourthBand selectCellWithTag:0];
  182.     [self Calculate:sender]; 
  183.     
  184. }
  185.  
  186. - (void)Ohms1p5K:(id)sender
  187. {
  188.  
  189.     [FirstBand selectCellWithTag:1]; // This will select radio button number 1.5K
  190.     [SecondBand selectCellWithTag:5];
  191.     [ThirdBand selectCellWithTag:100];
  192.     [FourthBand selectCellWithTag:0];
  193.     [self Calculate:sender]; 
  194.     
  195. }
  196.  
  197. - (void)Ohms220:(id)sender
  198. {
  199.  
  200.     [FirstBand selectCellWithTag:2]; // This will select radio button number 220
  201.     [SecondBand selectCellWithTag:2];
  202.     [ThirdBand selectCellWithTag:10];
  203.     [FourthBand selectCellWithTag:0];
  204.     [self Calculate:sender]; 
  205.     
  206. }
  207.  
  208. - (void)Ohms330:(id)sender
  209. {
  210.  
  211.     [FirstBand selectCellWithTag:3]; // This will select radio button number 330
  212.     [SecondBand selectCellWithTag:3];
  213.     [ThirdBand selectCellWithTag:10];
  214.     [FourthBand selectCellWithTag:0];
  215.     [self Calculate:sender]; 
  216.     
  217. }
  218.  
  219. - (void)Ohms33:(id)sender
  220. {
  221.  
  222.     [FirstBand selectCellWithTag:3]; // This will select radio button number 3
  223.     [SecondBand selectCellWithTag:3];
  224.     [ThirdBand selectCellWithTag:1];
  225.     [FourthBand selectCellWithTag:0];
  226.     [self Calculate:sender];
  227.     
  228. }
  229.  
  230. - (void)Ohms470:(id)sender
  231. {
  232.  
  233.     [FirstBand selectCellWithTag:4]; // This will select radio button number 470
  234.     [SecondBand selectCellWithTag:7];
  235.     [ThirdBand selectCellWithTag:10];
  236.     [FourthBand selectCellWithTag:0];
  237.     [self Calculate:sender]; 
  238.     
  239. }
  240.  
  241. - (void)Ohms47:(id)sender
  242. {
  243.  
  244.     [FirstBand selectCellWithTag:4]; // This will select radio button number 47
  245.     [SecondBand selectCellWithTag:7];
  246.     [ThirdBand selectCellWithTag:1];
  247.     [FourthBand selectCellWithTag:0];
  248.     [self Calculate:sender]; 
  249.     
  250. }
  251.  
  252. - (void)Ohms47K:(id)sender
  253. {
  254.  
  255.     [FirstBand selectCellWithTag:4]; // This will select radio button number 47K
  256.     [SecondBand selectCellWithTag:7];
  257.     [ThirdBand selectCellWithTag:1000];
  258.     [FourthBand selectCellWithTag:0];
  259.     [self Calculate:sender];
  260.     
  261. }
  262.  
  263. - (void)Ohms560:(id)sender
  264. {
  265.  
  266.     [FirstBand selectCellWithTag:5]; // This will select radio button number 5
  267.     [SecondBand selectCellWithTag:6];
  268.     [ThirdBand selectCellWithTag:10];
  269.     [FourthBand selectCellWithTag:0];
  270.     [self Calculate:sender]; 
  271.     
  272. }
  273.  
  274. - (void)Ohms680:(id)sender
  275. {
  276.  
  277.     [FirstBand selectCellWithTag:6]; // This will select radio button number 6
  278.     [SecondBand selectCellWithTag:8];
  279.     [ThirdBand selectCellWithTag:10];
  280.     [FourthBand selectCellWithTag:0];
  281.     [self Calculate:sender]; 
  282.     
  283. }
  284.  
  285. - (void)PrintColorTable:(id)sender
  286. // This method will print the Resistor Color Code Table
  287. {
  288.  
  289.      [ColorTable print:self];
  290. }
  291.  
  292. - (void)Reset:(id)sender
  293. {
  294.  
  295.     [FirstBand selectCellWithTag:0]; // This will select radio button number 0
  296.     [SecondBand selectCellWithTag:0];
  297.     [ThirdBand selectCellWithTag:0];
  298.     [FourthBand selectCellWithTag:0];
  299.     [self Calculate:sender]; 
  300.     
  301. }
  302.  
  303. - (void)MoreInfo:(id)sender
  304. {
  305.  
  306.     [NSBundle loadNibNamed:@"MoreInfo.nib" owner:self]; // load nib
  307.  
  308. }
  309.  
  310.  
  311.  
  312. @end
  313.