initWithObjects in Objective-C 1.0

Discussion in 'Mac Programming' started by trey5498, Aug 14, 2008.

  1. trey5498 macrumors regular

    Joined:
    Jun 16, 2008
    #1
    Code:
    arrSelections1 = [[NSArray alloc] initWithObjects: cse211djq, wei408djq, arc118djq, cse211clq, arc118clq, hubatlabclq, nrng514clq, wei408clq, tur2215clq, arcatlabbwq, b105110bwq, cse211bwq, hscmdlbwq, hubatlabbwq, lawpclabbwq, lbw3radbwq, nrnatlabbwq, tur2215bwq, weiatlabbwq, nil];
    

    Above is the code located in the awakeFromNib() and it works just fine 2.0, however it doesnt add to the array correctly in 1.0 I am converting intel to PPC
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    I don't see an issue. The only thing I would say is make sure one of those objects isn't nil, because if it is then any object after it won't be inserted into the array.
     
  3. trey5498 thread starter macrumors regular

    Joined:
    Jun 16, 2008
    #3
    These objects are buttons. None of them are even added to the array under 1.0
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    I'd say there is something else going on. Can't really help unless you post more code.

    Edit: make sure you're not using features of NSButton that are 10.5 only.
     
  5. trey5498 thread starter macrumors regular

    Joined:
    Jun 16, 2008
    #5
    Code:
    @implementation AppController
    //sets points of prninstall and prninstall104 to point to PrnInstall.m and PrnInstall104.m for method calls
    PrnInstall * prninstall;
    PrnInstall104 * prninstall104;
    
    int i;
    int tmp;
    int tmp1;
    NSString *stTmp;
    NSButton *button1;
    
    
    -(id) init
    {
    	
    	if ([super init]) {
    		//initializes the arrays and the points to call other methods
    		arrPRN = [[NSMutableArray alloc] init];
    		arrPRNint = [[NSMutableArray alloc] init];
    		arrSelections = [[NSMutableArray alloc] init];
    		arrInstalled = [[NSMutableArray alloc] init];
    		prninstall = [[PrnInstall alloc] init];
    		prninstall104 = [[PrnInstall104 alloc] init];
    		
    	}
    	return self;
    }
    -(void) dealloc
    {
    	//releases the arrays from memory
    	[super dealloc];
    	[arrPRN release];
    	[arrPRNint release];
    	[arrSelections release];
    	[arrSelections1 release];
    	
    }
    
    
    
    
    
    - (void)awakeFromNib {
    	//calls the method to check the verison of OS and sets the value to the approiate value
    	[self CheckInstalled];
    	if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_3) {
    		stDvrChk = @"Panter";
    	} else {
    		stDvrChk = @"Tiger";
    	}
    	arrSelections1 = [[NSArray alloc] initWithObjects: cse211djq, wei408djq, arc118djq, cse211clq, arc118clq, hubatlabclq, nrng514clq, wei408clq, tur2215clq, arcatlabbwq, b105110bwq, cse211bwq, hscmdlbwq, hubatlabbwq, lawpclabbwq, lbw3radbwq, nrnatlabbwq, tur2215bwq, weiatlabbwq, nil];
    
           for(i=0; i<[arrSelections1 count]; i++) {
    		button1 = [arrSelections1 objectAtIndex:i];
                    NSLog(@"%@", button1);
            }
    
    		
    } 
    
    Here is the larger chunk, I have it printing the elements of the object array to the console.
     
  6. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #6
    I would add a check like:
    Code:
    if(cse211djq == nil) {
      NSLog("First object to add is nil, add will fail\n");
    }
    to see if this is the problem.

    -Lee
     
  7. m85 macrumors newbie

    Joined:
    Apr 8, 2008
    #7
    Not directly related but you should should always [super dealloc] after releasing all other objects.

    Code:
    - (void)dealloc
    {
    	//releases the arrays from memory
    	[arrPRN release];
    	[arrPRNint release];
    	[arrSelections release];
    	[arrSelections1 release];
    	[B][super dealloc];[/B]	
    }
    
     
  8. trey5498 thread starter macrumors regular

    Joined:
    Jun 16, 2008
    #8
    Nope, Not nil. The array just doesnt seem to have anything in it


    2008-08-14 11:45:02.119 Circa Printer Installer[8223:10b] <NSButton: 0x2348d0>

    That is on the first line got 19 of these.
     
  9. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #9
    So on 10.3 -count on your array is 0 after you do the -initWithObjects? What if you use a NSMutableArray and -addObject for each? What about trying -initWithObjects:count: with a C array literal to see if this behaves differently? Does +arrayWithObjects behave differently?

    -Lee
     
  10. trey5498 thread starter macrumors regular

    Joined:
    Jun 16, 2008
    #10
    stupid questions, need the + sigh?
     
  11. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #11
    + Indicates a class method rather than an instance method. it is called on the class, like NSArray, instead of an instance of that class.

    -Lee
     
  12. trey5498 thread starter macrumors regular

    Joined:
    Jun 16, 2008
    #12
    I have changed the way it prints out to the console as I messed on that code:

    Code:
    NSLog(@"object at %d is %d \n", i, button1);
    
    This is of course in a for loop that will run through the array, and for some reason the object cse211djq (this is the name of a button object) is changed to 2311104. What did I mess up?
     
  13. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #13
    For one, use the %p format specifier to print a pointer, not %d. On some systems pointers are wider than ints.

    After you change that, when does the address of it change? What was it before (nil?)?

    -Lee
     
  14. trey5498 thread starter macrumors regular

    Joined:
    Jun 16, 2008
    #14
    It is now 0x2343c0

    Code:
    NSLog(@" there are %d object in the array", [arrSelections1 count]);
    
    that yields 19 and there is 19 objects.

    The objects are checkbox NSButtons
     
  15. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #15
    So it's fixed, then?
     
  16. trey5498 thread starter macrumors regular

    Joined:
    Jun 16, 2008
    #16
    in the first spot :cse211djq should be there so in the later rounds I will be using a for loop to uncheck or check the checkboxes. It yields a number when I use %d and I assume %p just gives me the address?
     
  17. trey5498 thread starter macrumors regular

    Joined:
    Jun 16, 2008
    #17
    This is supposed to work to all me to use a for loop to uncheck all the checkboxes. The array is all the objects connected to the checkbox buttons. How the selectall can not use the array as it seems to contain number only.

    Code:
    arrSelections1 = [[NSArray alloc] initWithObjects: cse211djq, wei408djq, arc118djq, cse211clq, arc118clq, hubatlabclq, nrng514clq, wei408clq, tur2215clq, arcatlabbwq, b105110bwq, cse211bwq, hscmdlbwq, hubatlabbwq, lawpclabbwq, lbw3radbwq, nrnatlabbwq, tur2215bwq, weiatlabbwq, nil];
    
    then tried this however it crashed the program.

    Code:
    //in the init function
    arrSelections1 = [[NSArray alloc] init];
    
    //awakeFromNib()
    arrSelections1 = [NSArray arrayWithObjects: cse211djq, wei408djq, arc118djq, cse211clq, arc118clq, hubatlabclq, nrng514clq, wei408clq, tur2215clq, arcatlabbwq, b105110bwq, cse211bwq, hscmdlbwq, hubatlabbwq, lawpclabbwq, lbw3radbwq, nrnatlabbwq, tur2215bwq, weiatlabbwq, nil];
    

    Neither work. Both show as having 19 objects in the array, however when I print out the objects to the console it shows up as numbers not the object name (cse211djq). It works fine in objective 2.0 however I need to scale it to work with 1.0 for power pc. Any ideas where I went wrong
     
  18. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #18
    I'm pretty lost, so I'm going to try to get you to break this down...

    All of those variables are IBOutlet's that represent buttons? When you print them, the best you'll get is their memory address with the %p format specifier. Otherwise, you'd need to send a message to invoke some method that will return something a little more useful, like the state of the buttons, to print.

    -Lee
     
  19. trey5498 thread starter macrumors regular

    Joined:
    Jun 16, 2008
    #19
    arrSelections contains the of the IBOutlets of the checkboxes. I need the literal names of the objects, this works perfectly in 2.0


    Here is the 2.0 code. So you see in the setting of the array and the cse211djq example is the name of a checkbox outlet. I will manipulate the checkboxes with the array so I do not have to set each one long way.

    Code:
    
    - (IBAction)selectall:(id)sender 
    {
    	//uses the Selections1 array to select check all the checkboxes
    	for(NSButton *button1 in arrSelections1) [button1 setState:NSOnState];
            //unchecks the selectall button
    	[selectall setState:NSOffState];
    	
    }
    


    here is the 1.0 code I think
    Code:
    
    - (IBAction)selectall:(id)sender 
    {
            NSButton *button1
    	//uses the Selections1 array to select check all the checkboxes
    	for(i=0; i<[arrSelections1 count]; i++) {
                   button1=[arrSelections1 objectAtIndex:1];
                   [button1 setState:NSOnState];
                   //unchecks the selectall button
    	       [selectall setState:NSOffState];
             }
    	
    }
    

    The array does not contain the correct names of the outlets but some strange number. As the selectall button does not work in 1.0
     
  20. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #20
    If you post your project I will fix it :)

    Also why are you using global variables? That is unnecessary and just further complicates things.

    Third, for(X in X) loops are ObjC-2.0 only, so remove those if you are compiling for 10.4.
     
  21. trey5498 thread starter macrumors regular

    Joined:
    Jun 16, 2008
    #21
    There are no global variables. I pass variables from one place to another and the outlets are contained in the header file.

    Here is the full AppController.m file in it entirety.

    Code:
    
    #import "AppController.h"
    #import "PrnInstall.h"
    #import "PrnInstall104.h"
    
    
    
    @implementation AppController
    //sets points of prninstall and prninstall104 to point to PrnInstall.m and PrnInstall104.m for method calls
    PrnInstall * prninstall;
    PrnInstall104 * prninstall104;
    
    int i;
    int tmp;
    int tmp1;
    NSString *stTmp;
    NSButton *button; //ppc
    NSButton *button1; //ppc
    
    
    -(id) init
    {
    	
    	if ([super init]) {
    		//initializes the arrays and the points to call other methods
    		arrPRN = [[NSMutableArray alloc] init];
    		arrPRNint = [[NSMutableArray alloc] init];
    		arrSelections = [[NSMutableArray alloc] init];
    		arrInstalled = [[NSMutableArray alloc] init];
    		prninstall = [[PrnInstall alloc] init];
    		prninstall104 = [[PrnInstall104 alloc] init];
    		arrSelections1 = [[NSArray alloc] init];
    		
    	}
    	return self;
    }
    -(void) dealloc
    {
    	//releases the arrays from memory
    	[super dealloc];
    	[arrPRN release];
    	[arrPRNint release];
    	[arrSelections release];
    	[arrSelections1 release];
    	[super dealloc]; 
    	
    }
    
    
    
    
    
    - (void)awakeFromNib {
    	//calls the method to check the verison of OS and sets the value to the approiate value
    	[self CheckInstalled];
    	//if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4) {   //For Intel Build
    	if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_3) {   //for PPC Build
    		stDvrChk = @"Panther";   //for PPC Build
    	//	stDvrChk = @"Tiger";  //For Intel Build
    	} else {
    	//	stDvrChk = @"Leopard";  //For Intel Build
    		stDvrChk = @"Tiger";    //for PPC Build
    	}
    
    	arrSelections1 = [NSArray arrayWithObjects: cse211djq, wei408djq, arc118djq, cse211clq, arc118clq, hubatlabclq, nrng514clq, wei408clq, tur2215clq, arcatlabbwq, b105110bwq, cse211bwq, hscmdlbwq, hubatlabbwq, lawpclabbwq, lbw3radbwq, nrnatlabbwq, tur2215bwq, weiatlabbwq, nil];
    	NSLog(@"%d items in the array\n", [arrSelections1 count]);
    	if(cse211djq == nil) {
    		NSLog(@"Nothing in CSE-211-DJQ\n");
    	} else {
    		NSLog(@"Something there");
    	}
    	for(i=0;i<[arrSelections1 count]; i++) {        //PPC Build
    		button1=[arrSelections1 objectAtIndex:i];
    		NSLog(@"object at %d is %d \n", i, button1);
    	} 
    			
    } 
    	
    
    - (IBAction)NextButton:(id)sender 
    {
    	// Color Printer 
    	//Checks for each one check button if they are checked and adds the correct values to the appropiate arrays
    	if([arc118clq state]==NSOnState) {
    		[arrPRN addObject:@"ARC-118-CLQ"];
    		[arrPRNint addObject:@"ARC118ClQ"];
    		[arrSelections addObject:arc118clq];
    		
    	 } 
    	 if([cse211clq state]==NSOnState) {
    		[arrPRN addObject:@"CSE-211-CLQ"];
    		[arrPRNint addObject:@"CSE211CLQ"];
    		[arrSelections addObject:cse211clq];
    	 }  
    	 if([hubatlabclq state]==NSOnState) {
    		[arrPRN addObject:@"HUB-ATLAB-CLQ"];
    		[arrPRNint addObject:@"HUBATLABCLQ"];
    		[arrSelections addObject:hubatlabclq];
    	 } 
    	
    
    	 // Black and Whites
    	//Checks for each one check button if they are checked and adds the correct values to the appropiate arrays
    	if([arcatlabbwq state]==NSOnState) {
    		[arrPRN addObject:@"ARC-ATLAB-BWQ"];
    		[arrPRNint addObject:@"ARCATLABBWQ"];
    		[arrSelections addObject:arcatlabbwq];
    	 }
    	 
    	 if([hscmdlbwq state]==NSOnState) {
    		[arrPRN addObject:@"HSC-MDL-BWQ"];
    		[arrPRNint addObject:@"HSCMDLBWQ"];
    		[arrSelections addObject:hscmdlbwq];
    	 }
    	 if([hubatlabbwq state]==NSOnState) {
    		[arrPRN addObject:@"HUB-ATLAB-BWQ"];
    		[arrPRNint addObject:@"HUBATLABBWQ"];
    		[arrSelections addObject:hubatlabbwq];
    	 }
    	 if([lawpclabbwq state]==NSOnState) {
    		[arrPRN addObject:@"LAW-PCLAB-BWQ"];
    		[arrPRNint addObject:@"LAWPCLABBWQ"];
    		[arrSelections addObject:lawpclabbwq];
    	 }
    	 if([lbw3radbwq state]==NSOnState) {
    		[arrPRN addObject:@"LBW-3RAD-BWQ"];
    		[arrPRNint addObject:@"LBW3RADBWQ"];
    		[arrSelections addObject:lbw3radbwq];
    	 }
    	 
    	 if([weiatlabbwq state]==NSOnState) {
    		[arrPRN addObject:@"WEI-ATLAB-BWQ"];
    		[arrPRNint addObject:@"WEIATLABBWQ"];
    		[arrSelections addObject:weiatlabbwq];
    	 }
    	
    	 // Plotters
    	//Checks for each one check button if they are checked and adds the correct values to the appropiate arrays
    	 if([arc118djq state]==NSOnState) {
    		[arrPRN addObject:@"ARC-118-DJQ"];
    		[arrPRNint addObject:@"ARC118DJQ"];
    		[arrSelections addObject:arc118djq];
    	 } 
    	 if([cse211djq state]==NSOnState) {
    		[arrPRN addObject:@"CSE-211-DJQ"];
    		[arrPRNint addObject:@"CSE211DJQ"];
    		[arrSelections addObject:cse211djq];
    	 } 
    	 if([wei408djq state]==NSOnState) {
    		[arrPRN addObject:@"WEI-408-DJQ"];
    		[arrPRNint addObject:@"WEI408DJQ"];
    		[arrSelections addObject:wei408djq];
    	 } 
    	
    	
    	//prints out array of the selected printers to the NSTextView on the overview page then show the overview page and hides the selection screen 
    	tmp = [arrPRN count];
    	stTmp = [NSString stringWithFormat:@" \n \nYou have Selected %d out of 19 Printers to Install\n", tmp];
    	for(i=0; i<[arrPRN count]; i++) {
    		[textView insertText:[((NSString *) [arrPRN objectAtIndex: i]) stringByAppendingString:@"\n"]];
    	}
    	[textView insertText:stTmp];
    	[textView setEditable:false];
    	[prnSelector orderOut:nil];
    	[prnOverview makeKeyAndOrderFront:nil];
    
    }
    - (IBAction)BackButton:(id)sender 
    {	
    	
    	//clears out all the arrays and clears the check boxes so the use may start over again, then hides the overview screen and open the selection screen again
    	//for(NSButton *button in arrSelections) [button setState:NSOffState];  //Intel Build
    	
    /* */	for(i=0;i<[arrSelections count]; i++) {        //PPC Build
    		button=[arrSelections objectAtIndex:i];
    		[button setState:NSOffState];
    	} 
    
    	for(i=0; i<[arrPRN count]; i++) {
    		[textView setString:@""];
    		[arrPRN removeAllObjects];
    		[arrPRNint removeAllObjects];
    		[arrSelections removeAllObjects];
    		
    	}
    	[textView setEditable:true];
    	[prnOverview orderOut:nil];
    	[prnSelector makeKeyAndOrderFront:self];
    }
    - (IBAction)ProcessButton:(id)sender 
    {
    	// calls the install file according to the correct OS version, hides the overview screen and shows a progress bar to show the progress
    	[prnOverview orderOut:nil];
    	[prnProcessing makeKeyAndOrderFront:self];
    	[prnProgress setIndeterminate:NO];
    	for(i=0; i<[arrPRNint count]; i++) {
    		//sets the length of the progress in time according to the count of arrPRNint array and updates the display until finished
    		[prnProgress setDoubleValue:100*i/(double)[arrPRNint count]];
    		[prnProgress displayIfNeeded];
    		stTmp = [arrPRNint objectAtIndex: i];
    		
    	/*	*/if([stDvrChk isEqualToString:@"Panther"]) {
    			NSRunAlertPanel(@"Installation Error", @"This Installation is made specifically for OS X version of Tiger and Above", @"Ok", nil, nil);
    			exit(0);
    		} 
    		if([stDvrChk isEqualToString:@"Tiger"]) {
    			[arrInstalled addObject:objc_msgSend(prninstall104, NSSelectorFromString(stTmp))];
    		}
    		else {
    			[arrInstalled addObject:objc_msgSend(prninstall, NSSelectorFromString(stTmp))];
    		}
    	}
    
    	//hides the progress bar and brings up the wrapup screen.  Will display the printers that were installed correctly  and then display a message panel if there was an error in copying a driver.
    	[prnProcessing orderOut:nil];
    	[prnWrapup makeKeyAndOrderFront:self];
    	NSBeep();
    	for(i=0; i<[arrInstalled count]; i++) {
    		[endtextView insertText:[((NSString *) [arrInstalled objectAtIndex: i]) stringByAppendingString:@"\n"]];
    	}
    	//checks for errors in the installs and will display the error code to contact the help desk
    	tmp1 = [arrInstalled count];
    	stTmp = [NSString stringWithFormat:@" \n \n%d out of %d Printers have been Installed correctly\n", tmp, tmp1];
    	[endtextView insertText:stTmp];
    	[endtextView setEditable:false];
    	if (tmp != tmp1) {
    		NSRunAlertPanel(@"Driver Error", @"There was some error with insatalling the drivers.  Please contact the Help Desk for more information", @"Ok", nil, nil);
    	}		
    }
    - (IBAction)CancelProcess:(id)sender 
    {
    	//clears out all the arrays and clears the check boxes so the use may start over again, then hides the progress screen and open the selection screen again
    //	for(NSButton *button in arrSelections) [button setState:NSOffState];  //Intel Build
    /**/	 for(i=0;i<[arrSelections count]; i++) {        //PPC Build
    		button=[arrSelections objectAtIndex:i];
    		[button setState:NSOffState];
    	} 
    	for(i=0; i<[arrPRN count]; i++) {
    		[textView setString:@""];
    		[arrPRN removeAllObjects];
    		[arrPRNint removeAllObjects];
    		[arrSelections removeAllObjects];
    	}
    	
    	[prnProcessing orderOut:nil];
    	[prnSelector makeKeyAndOrderFront:self];	
    }
    - (IBAction)CancelButton:(id)sender 
    {
    	exit(0);
    }
    - (IBAction)HelpButton:(id)sender 
    {
    	[prnHelp makeKeyAndOrderFront:self];
    }
    - (IBAction)AboutButton:(id)sender 
    {
    	[prnAbout makeKeyAndOrderFront:self];
    }
    - (IBAction)OKButton:(id)sender 
    {
    	exit(0);
    }
    
    - (IBAction)selectall:(id)sender 
    {
    	//uses the Selections1 array to select check all the checkboxes
    //	for(NSButton *button1 in arrSelections1) [button1 setState:NSOnState];      //Intel Build
    	/* */
    	for(i=0;i<[arrSelections1 count]; i++) {        //PPC Build
    		button1=[arrSelections1 objectAtIndex:i];
    		[button1 setState:NSOffState];
    	} 
    
    	[selectall setState:NSOffState];
    	
    }
    - (IBAction)unselectall:(id)sender 
    {
    	//uses the Selections1 array to unselect check all the checkboxes after seeing if they are checked
    //	for(NSButton *button1 in arrSelections1) {   //Intel Build
        for(i=0;i<[arrSelections1 count]; i++) {        //PPC Build
    		button1=[arrSelections1 objectAtIndex:i];   //PPC Build
    		if ([button1 state]==NSOnState) {
    			[button1 setState:NSOffState];
    		}
    		[unselectall setState:NSOffState];
    	}
    }
    - (void)CheckInstalled {
    	
    	FILE *myFD = NULL;
    	char buffer[9];
    	
    	// Plotters
    	//will create a file instance to place the value of the system call
    	myFD = popen("lpstat -a CSE-211-DJQ | grep -o \"accepting\"","r");
    	//retrieves the output of the system call and places it in the variable of buffer
    	fgets (buffer, 10, myFD);
    	//checks if the output of buffer is accepting then it will not allow the printer to be selected.  Also sets the tooltips for each printer
    	if (strncmp (buffer,"accepting", 9) == 0) {
    		[cse211djq setToolTip:@"Printer already Installed"];
    		[cse211djq setEnabled:false]; 
    	} else {
    		[cse211djq setToolTip:@"CSE Plotters"];
    	}
    	//clears the buffer character variable and then closes the instance
    	strcpy(buffer, "     ");
    	pclose(myFD);
    	
    	myFD = popen("lpstat -a ARC-118-DJQ | grep -o \"accepting\"","r");
    	fgets (buffer, 10, myFD);
    	//checks if the output of buffer is accepting then it will not allow the printer to be selected.  Also sets the tooltips for each printer
    	if (strncmp (buffer,"accepting", 9) == 0) {
    		[arc118djq setToolTip:@"Printer already Installed"];
    		[arc118djq setEnabled:false]; 
    
    	} else {
    		[arc118djq  setToolTip:@"Architecture Plotters"];
    	}
    	strcpy(buffer, "     ");
    	pclose(myFD);
    
    	
    
    
    
    
    	 // Color Printer
    	myFD = popen("lpstat -a CSE-211-CLQ | grep -o \"accepting\"","r");
    	fgets (buffer, 10, myFD);
    	if (strncmp (buffer,"accepting", 9) == 0) {
    	//checks if the output of buffer is accepting then it will not allow the printer to be selected.  Also sets the tooltips for each printer
    		[cse211clq setToolTip:@"Printer already Installed"];
    		[cse211clq setEnabled:false]; 
    
    	} else {
    		[cse211clq setToolTip:@"CSE Color Printer"]; 
    	}
    	strcpy(buffer, "     ");
    	pclose(myFD);
    
    	myFD = popen("lpstat -a ARC-118-CLQ | grep -o \"accepting\"","r");
    	fgets (buffer, 10, myFD);
    	//checks if the output of buffer is accepting then it will not allow the printer to be selected.  Also sets the tooltips for each printer
    	if (strncmp (buffer,"accepting", 9) == 0) {
    		[arc118clq setToolTip:@"Printer already Installed"];
    		[arc118clq setEnabled:false]; 
    
    	} else {
    		[arc118clq setToolTip:@"Architecture Color Printer"]; 
    	}
    	strcpy(buffer, "     ");
    	pclose(myFD);
    
    	myFD = popen("lpstat -a HUB-ATLAB-CLQ | grep -o \"accepting\"","r");
    	fgets (buffer, 10, myFD);
    	//checks if the output of buffer is accepting then it will not allow the printer to be selected.  Also sets the tooltips for each printer
    	if (strncmp (buffer,"accepting", 9) == 0) {
    		[hubatlabclq setToolTip:@"Printer already Installed"];
    		[hubatlabclq setEnabled:false]; 
    
    	} else {
    		[hubatlabclq setToolTip:@"Hub Color Printers (Rooms 120 and 224)"]; 
    	}
    	strcpy(buffer, "     ");
    	pclose(myFD);
    	
    	myFD = popen("lpstat -a NRN-G514-CLQ | grep -o \"accepting\"","r");
    	fgets (buffer, 10, myFD);
    	//checks if the output of buffer is accepting then it will not allow the printer to be selected.  Also sets the tooltips for each printer
    	if (strncmp (buffer,"accepting", 9) == 0) {
    		[nrng514clq setToolTip:@"Printer already Installed"];
    		[nrng514clq setEnabled:false]; 
    
    	} else {
    		[nrng514clq setToolTip:@"Norman Hall Color Printers"]; 
    	}
    	strcpy(buffer, "     ");
    	pclose(myFD);
    
    	myFD = popen("lpstat -a WEI-408-CLQ | grep -o \"accepting\"","r");
    	fgets (buffer, 10, myFD);
    	//checks if the output of buffer is accepting then it will not allow the printer to be selected.  Also sets the tooltips for each printer
    	if (strncmp (buffer,"accepting", 9) == 0) {
    		[wei408clq setToolTip:@"Printer already Installed"];
    		[wei408clq setEnabled:false]; 
    
    	} else {
    		[wei408clq setToolTip:@"Weil Hall Color Printer"]; 
    	}
    	strcpy(buffer, "     ");
    	pclose(myFD);
    
    	myFD = popen("lpstat -a TUR-2215-CLQ | grep -o \"accepting\"","r");
    	fgets (buffer, 10, myFD);
    	//checks if the output of buffer is accepting then it will not allow the printer to be selected.  Also sets the tooltips for each printer
    	if (strncmp (buffer,"accepting", 9) == 0) {
    		[tur2215clq setToolTip:@"Printer already Installed"];
    		[tur2215clq setEnabled:false]; 
    
    	} else {
    		[tur2215clq setToolTip:@"Turlington Hall Room 2215 Color Printer"];
    	}
    	strcpy(buffer, "     ");
    	pclose(myFD);
    
    
    	// Black and White Printers
    	myFD = popen("lpstat -a ARC-ATLAB-BWQ | grep -o \"accepting\"","r");
    	fgets (buffer, 10, myFD);
    	//checks if the output of buffer is accepting then it will not allow the printer to be selected.  Also sets the tooltips for each printer
    	if (strncmp (buffer,"accepting", 9) == 0) {
    		[arcatlabbwq setToolTip:@"Printer already Installed"];
    		[arcatlabbwq setEnabled:false]; 
    
    	} else {
    		[arcatlabbwq setToolTip:@"Architecture Black and White Printers (Rooms 116 and 118)"];
    	}
    	strcpy(buffer, "     ");
    	pclose(myFD);
    
    	myFD = popen("lpstat -a B105-110-BWQ | grep -o \"accepting\"","r");
    	fgets (buffer, 10, myFD);
    	//checks if the output of buffer is accepting then it will not allow the printer to be selected.  Also sets the tooltips for each printer
    	if (strncmp (buffer,"accepting", 9) == 0) {
    		[b105110bwq setToolTip:@"Printer already Installed"];
    		[b105110bwq setEnabled:false]; 
    
    	} else {
    		[b105110bwq setToolTip:@"Building 105 Room 110 Black and White Printers"];
    	}
    	strcpy(buffer, "     ");
    	pclose(myFD);
    
    	myFD = popen("lpstat -a CSE-211-BWQ | grep -o \"accepting\"","r");
    	fgets (buffer, 10, myFD);
    	//checks if the output of buffer is accepting then it will not allow the printer to be selected.  Also sets the tooltips for each printer
    	if (strncmp (buffer,"accepting", 9) == 0) {
    		[cse211bwq setToolTip:@"Printer already Installed"];
    		[cse211bwq setEnabled:false]; 
    
    	} else {
    		[cse211bwq setToolTip:@"CSE Black and White Printers (Rooms 211A and 211)"];
    	}
    	strcpy(buffer, "     ");
    	pclose(myFD);
    
    	myFD = popen("lpstat -a HSC-MDL-BWQ | grep -o \"accepting\"","r");
    	fgets (buffer, 10, myFD);
    	//checks if the output of buffer is accepting then it will not allow the printer to be selected.  Also sets the tooltips for each printer
    	if (strncmp (buffer,"accepting", 9) == 0) {
    		[hscmdlbwq setToolTip:@"Printer already Installed"];
    		[hscmdlbwq setEnabled:false]; 
    
    	} else {
    		[hscmdlbwq setToolTip:@"The Black and White Printers for the Medical Science Center"];
    	}
    	strcpy(buffer, "     ");
    	pclose(myFD);
    
    
    	myFD = popen("lpstat -a HUB-ATLAB-BWQ | grep -o \"accepting\"","r");
    	fgets (buffer, 10, myFD);
    	//checks if the output of buffer is accepting then it will not allow the printer to be selected.  Also sets the tooltips for each printer
    	if (strncmp (buffer,"accepting", 9) == 0) {
    		[hubatlabbwq setToolTip:@"Printer already Installed"];
    		[hubatlabbwq setEnabled:false]; 
    
    	} else {
    		[hubatlabbwq setToolTip:@"Hub Black and White Printers (Rooms 120 and 224)"];
    	}
    	strcpy(buffer, "     ");
    	pclose(myFD);
    
    	myFD = popen("lpstat -a LAW-PCLAB-BWQ | grep -o \"accepting\"","r");
    	fgets (buffer, 10, myFD);
    	//checks if the output of buffer is accepting then it will not allow the printer to be selected.  Also sets the tooltips for each printer
    	if (strncmp (buffer,"accepting", 9) == 0) {
    		[lawpclabbwq setToolTip:@"Printer already Installed"];
    		[lawpclabbwq setEnabled:false]; 
    
    	} else {
    		[lawpclabbwq setToolTip:@"Law Library Black and White Printers"];
    	}
    	strcpy(buffer, "     ");
    	pclose(myFD);
    
    	myFD = popen("lpstat -a LBW-3RAD-BWQ | grep -o \"accepting\"","r");
    	fgets (buffer, 10, myFD);
    	//checks if the output of buffer is accepting then it will not allow the printer to be selected.  Also sets the tooltips for each printer
    	if (strncmp (buffer,"accepting", 9) == 0) {
    		[lbw3radbwq setToolTip:@"Printer already Installed"];
    		[lbw3radbwq setEnabled:false]; 
    
    	} else {
    		[lbw3radbwq setToolTip:@"West Library Black and White Printer"];
    	}
    	strcpy(buffer, "     ");
    	pclose(myFD);
    
    	myFD = popen("lpstat -a NRN-ATLAB-BWQ | grep -o \"accepting\"","r");
    	fgets (buffer, 10, myFD);
    	//checks if the output of buffer is accepting then it will not allow the printer to be selected.  Also sets the tooltips for each printer
    	if (strncmp (buffer,"accepting", 9) == 0) {
    		[nrnatlabbwq setToolTip:@"Printer already Installed"];
    		[nrnatlabbwq setEnabled:false]; 
    
    	} else {
    		[nrnatlabbwq setToolTip:@"Norman Hall Black and White Printers (Rooms G512, G514 and G514I)"];
    	}
    	strcpy(buffer, "     ");
    	pclose(myFD);
    
    	myFD = popen("lpstat -a TUR-2215-BWQ | grep -o \"accepting\"","r");
    	fgets (buffer, 10, myFD);
    	//checks if the output of buffer is accepting then it will not allow the printer to be selected.  Also sets the tooltips for each printer
    	if (strncmp (buffer,"accepting", 9) == 0) {
    		[tur2215bwq setToolTip:@"Printer already Installed"];
    		[tur2215bwq setEnabled:false]; 
    
    	} else {
    		[tur2215bwq setToolTip:@"Turlington Hall Room 2215 Black and White Printer"];	
    	}
    	strcpy(buffer, "     ");
    	pclose(myFD);
    
    	myFD = popen("lpstat -a WEI-ATLAB-BWQ | grep -o \"accepting\"","r");
    	fgets (buffer, 10, myFD);
    	//checks if the output of buffer is accepting then it will not allow the printer to be selected.  Also sets the tooltips for each printer
    	if (strncmp (buffer,"accepting", 9) == 0) {
    		[weiatlabbwq setToolTip:@"Printer already Installed"];
    		[weiatlabbwq setEnabled:false]; 
    
    	} else {
    		[weiatlabbwq setToolTip:@"Weil Hall Black and White Printers (Rooms 408, 410, and 412)"];
    	}
    	strcpy(buffer, "     ");
    	pclose(myFD);
    
    }
    
    @end
    

    EDIT: I had to remove some of the redundancy items to keep it able to post Just in the printer areas that have different names but the rest of the code is the same.
     
  22. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #22
    These are global variables:
    Code:
    PrnInstall * prninstall;
    PrnInstall104 * prninstall104;
    
    int i;
    int tmp;
    int tmp1;
    NSString *stTmp;
    NSButton *button; //ppc
    NSButton *button1; //ppc
    They should be declared in your class @interface, not inside the @implementation. Very few reasons you would ever need to declare a variable here.

    Also I meant your complete project folder, because your code is dependent on your NIBs.
     
  23. trey5498 thread starter macrumors regular

    Joined:
    Jun 16, 2008
  24. trey5498 thread starter macrumors regular

    Joined:
    Jun 16, 2008
    #25
    anyone have any ideas what I did wrong with the Array? or do I need to flat out add each item line by line?
     

Share This Page