This is ResistorObject.m in view mode; [Download] [Up]
#import "ResistorObject.h"
@implementation ResistorObject
- (void)Calculate:(id)sender
{
// Declare variables
int Vfirstband; // Value of firstband
int Vsecondband; // Value of secondband
int Vthirdband; // Value of thirdband
float Vfourthband; // Value of fourthband
int SwitchOne; // Dummy int for switch statment
int SwitchTwo; // Dummy int for switch statment
int temp;
int temp2;
float resistorValue;
float resistorValueK;
float range1;
float range2;
char SRvalue[20];
char SRKvalue[20];
char SR1value[20];
char SR2value[20];
// Assigns the value of the currently selected button found in the
// button matrixs of Resistor using tag as a reference
Vfirstband = [FirstBand selectedTag];
Vsecondband = [SecondBand selectedTag];
Vthirdband = [ThirdBand selectedTag];
// thirdband: Assigns the proper value depending on which button was selected
SwitchOne = [ThirdBand selectedTag];
Vthirdband = SwitchOne;
switch (SwitchOne) { // start switch
case 2:
Vthirdband = 0.10; // Gold (ThirdBand)
break;
case 3:
Vthirdband = 0.01; // Silver (ThirdBand)
break;
case 4:
Vthirdband = 1000000; // Blue (ThirdBand)
break;
case 5:
Vthirdband = 10000000; // Voilet (ThirdBand)
break;
case 6:
Vthirdband = 100000000; // Grey (ThirdBand)
break;
} // end switch
// fourthband: Assigns the proper value depending on which
// button was selected
SwitchTwo = [FourthBand selectedTag];
switch (SwitchTwo) { // start switch
case 0:
Vfourthband = 0.20; // No Band
break;
case 1:
Vfourthband = 0.10; // Silver
break;
case 2:
Vfourthband = 0.05; // Gold
break;
} // end switch
// Calculations
temp = Vfirstband*10;
temp2 = temp + Vsecondband;
resistorValue = temp2 * Vthirdband;
range1 = resistorValue * Vfourthband;
range1 = resistorValue - range1;
range2 = resistorValue * Vfourthband;
range2 = resistorValue + range2;
resistorValueK = resistorValue / 1000;
// Convert a number to a string a adjust the floating point accuracy
sprintf(SRvalue,"%.2f",resistorValue);
sprintf(SRKvalue,"%.2f",resistorValueK);
sprintf(SR1value,"%.2f",range1);
sprintf(SR2value,"%.2f",range2);
// Assign the values to the proper display
// Display the value of the resistor in the form
[ValueOhms setStringValue:[NSString stringWithCString:SRvalue]];
// Display the value of the resistor in K in the form
[ValueKOhms setStringValue:[NSString stringWithCString:SRKvalue]];
// Display the value of the range1 in the form
[RangeOne setStringValue:[NSString stringWithCString:SR1value]];
// Display the value of the range2 in the form
[RangeTwo setStringValue:[NSString stringWithCString:SR2value]];
}
- (void)Ohms100:(id)sender
{
[FirstBand selectCellWithTag:1]; // This will select radio button number 1
[SecondBand selectCellWithTag:0];
[ThirdBand selectCellWithTag:1];
[FourthBand selectCellWithTag:0];
[self Calculate:sender];
}
- (void)Ohms100K:(id)sender
{
[FirstBand selectCellWithTag:1]; // This will select radio button number 1
[SecondBand selectCellWithTag:0];
[ThirdBand selectCellWithTag:10000];
[FourthBand selectCellWithTag:0];
[self Calculate:sender];
}
- (void)Ohms10:(id)sender
{
[FirstBand selectCellWithTag:1]; // This will select radio button number 1
[SecondBand selectCellWithTag:0];
[ThirdBand selectCellWithTag:1];
[FourthBand selectCellWithTag:0];
[self Calculate:sender];
}
- (void)Ohms10K:(id)sender
{
[FirstBand selectCellWithTag:1]; // This will select radio button number 1
[SecondBand selectCellWithTag:0];
[ThirdBand selectCellWithTag:1];
[FourthBand selectCellWithTag:0];
[self Calculate:sender];
}
- (void)Ohms15K:(id)sender
{
[FirstBand selectCellWithTag:1]; // This will select radio button number 15K
[SecondBand selectCellWithTag:5];
[ThirdBand selectCellWithTag:1000];
[FourthBand selectCellWithTag:0];
[self Calculate:sender];
}
- (void)Ohms1K:(id)sender
{
[FirstBand selectCellWithTag:1]; // This will select radio button number 1K
[SecondBand selectCellWithTag:0];
[ThirdBand selectCellWithTag:100];
[FourthBand selectCellWithTag:0];
[self Calculate:sender];
}
- (void)Ohms1p5K:(id)sender
{
[FirstBand selectCellWithTag:1]; // This will select radio button number 1.5K
[SecondBand selectCellWithTag:5];
[ThirdBand selectCellWithTag:100];
[FourthBand selectCellWithTag:0];
[self Calculate:sender];
}
- (void)Ohms220:(id)sender
{
[FirstBand selectCellWithTag:2]; // This will select radio button number 220
[SecondBand selectCellWithTag:2];
[ThirdBand selectCellWithTag:10];
[FourthBand selectCellWithTag:0];
[self Calculate:sender];
}
- (void)Ohms330:(id)sender
{
[FirstBand selectCellWithTag:3]; // This will select radio button number 330
[SecondBand selectCellWithTag:3];
[ThirdBand selectCellWithTag:10];
[FourthBand selectCellWithTag:0];
[self Calculate:sender];
}
- (void)Ohms33:(id)sender
{
[FirstBand selectCellWithTag:3]; // This will select radio button number 3
[SecondBand selectCellWithTag:3];
[ThirdBand selectCellWithTag:1];
[FourthBand selectCellWithTag:0];
[self Calculate:sender];
}
- (void)Ohms470:(id)sender
{
[FirstBand selectCellWithTag:4]; // This will select radio button number 470
[SecondBand selectCellWithTag:7];
[ThirdBand selectCellWithTag:10];
[FourthBand selectCellWithTag:0];
[self Calculate:sender];
}
- (void)Ohms47:(id)sender
{
[FirstBand selectCellWithTag:4]; // This will select radio button number 47
[SecondBand selectCellWithTag:7];
[ThirdBand selectCellWithTag:1];
[FourthBand selectCellWithTag:0];
[self Calculate:sender];
}
- (void)Ohms47K:(id)sender
{
[FirstBand selectCellWithTag:4]; // This will select radio button number 47K
[SecondBand selectCellWithTag:7];
[ThirdBand selectCellWithTag:1000];
[FourthBand selectCellWithTag:0];
[self Calculate:sender];
}
- (void)Ohms560:(id)sender
{
[FirstBand selectCellWithTag:5]; // This will select radio button number 5
[SecondBand selectCellWithTag:6];
[ThirdBand selectCellWithTag:10];
[FourthBand selectCellWithTag:0];
[self Calculate:sender];
}
- (void)Ohms680:(id)sender
{
[FirstBand selectCellWithTag:6]; // This will select radio button number 6
[SecondBand selectCellWithTag:8];
[ThirdBand selectCellWithTag:10];
[FourthBand selectCellWithTag:0];
[self Calculate:sender];
}
- (void)PrintColorTable:(id)sender
// This method will print the Resistor Color Code Table
{
[ColorTable print:self];
}
- (void)Reset:(id)sender
{
[FirstBand selectCellWithTag:0]; // This will select radio button number 0
[SecondBand selectCellWithTag:0];
[ThirdBand selectCellWithTag:0];
[FourthBand selectCellWithTag:0];
[self Calculate:sender];
}
- (void)MoreInfo:(id)sender
{
[NSBundle loadNibNamed:@"MoreInfo.nib" owner:self]; // load nib
}
@end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.