PDA

View Full Version : Problem with my for loop?




trey5498
Jun 23, 2008, 01:35 PM
I am no idiot when it comes to for loops. I have to use them all the time when it comes to Perl and I KNOW the syntax. How on earth is this syntax wrong and cause the program to crash. And I thought Macs weren't supposed to Crash?


- (IBAction)NextButton:(id)sender
{
if([arc118clq state]==NSOnState) {
// printerarray[i] = Printer1;
arrPRN = [NSMutableArray new];
[arrPRN addObject:@"ARC-118-CLQ"];

} else if([cse211clq state]==NSOnState) {
// printerarray[i] = Printer1;
//arrPRN = [NSMutableArray new];
[arrPRN addObject:@"CSE-211-CLQ"];

} else if([hubatlabclq state]==NSOnState) {
// printerarray[i] = Printer1;
//arrPRN = [NSMutableArray new];
[arrPRN addObject:@"HUB-ATLAB-CLQ"];

} else if([nrnatlabclq state]==NSOnState) {
// printerarray[i] = Printer1;
//arrPRN = [NSMutableArray new];
[arrPRN addObject:@"NRN-ATLAB-CLQ"];

}

int ind;
for(ind=0; ind<17; ind++) {
NSLog(@"%@", arrPRN[ind]);
}
[prnSelector orderOut:nil];
[prnOverview makeKeyAndOrderFront:nil];
}


basically I am tring to print the array to NSLog to test to see if the addObject is adding it correctly. I am attempting step by step to eventually print this to a text field screen, which I don't know how to do either. So Question number one, why is the for loop screwing everthing up and if I take it out why does it function correctly? Question number two: How do I set this to show up in a text field (the class is NSScrollView)?



robbieduncan
Jun 23, 2008, 01:48 PM
Where did the 17 come from? What do you thing arrPRN[17] will do? arrPRN is not an array: it's an object. You are using it as a pointer array using that syntax and will be readying into "random" memory. Go back and read some Cocoa and C basics.

Cromulent
Jun 23, 2008, 01:52 PM
And I thought Macs weren't supposed to Crash?

Of course they will crash if you run some bad software on them. They just have a better chance of only the app crashing without bringing the whole system down (although admittedly Vista is pretty rock solid for me).

trey5498
Jun 23, 2008, 01:54 PM
maybe I should have been a tad bit more specific....

the 17 is the fact that there is 17 check boxes it is checking, I just didn't want to put all 17 there to clutter up stuff, however all are coded in the exact same way. the array is declared in the header file as:


NSMutableArray *arrPRN;


If this is done incorrectly, I have coded it the exact same way that the developer site of apple has declaring arrays. So how did I screw up?

robbieduncan
Jun 23, 2008, 01:59 PM
That is not an array. It is a pointer to type NSMutableArray. An array would be declared like this:

NSMutableArray arrPRN[17];

Note the above array has 18 elements, not 17 as 0 is considered to be an element in arrays.

And is an array of NSMutableArrays. Which would be quite unusual. As he's adding NSStrings to his NSMutableArray would it not be better to declare an array of NSStrings? Or even pointers to NSStrings...

Edit: damn, Cromulent seems to have deleted his post!

Cromulent
Jun 23, 2008, 02:00 PM
And is an array of NSMutableArrays. Which would be quite unusual. As he's adding NSStrings to his NSMutableArray would it not be better to declare an array of NSStrings? Or even pointers to NSStrings...

Bah, ninja quote. I noticed my mistake and deleted my original post. I guess I didn't get away with it :).

robbieduncan
Jun 23, 2008, 02:04 PM
maybe I should have been a tad bit more specific....

the 17 is the fact that there is 17 check boxes it is checking, I just didn't want to put all 17 there to clutter up stuff, however all are coded in the exact same way. the array is declared in the header file as:


NSMutableArray *arrPRN;


If this is done incorrectly, I have coded it the exact same way that the developer site of apple has declaring arrays. So how did I screw up?

Ok the problem here seems to be that you are used to Perl. Which will allow you to make mistakes and try and access memory you have not initialised/used. C and, therefore, Objective-C will not. And it will cause your code (not your Mac) to crash.

Your array is an Object. So you declare it something like:

NSMutableArray *arrPRN = [[NSMutableArray alloc] init];


You can then use the methods in the documentation (http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html) to add and remove elements from the array. You cannot use arrPRN[index]. This offsets through RAM to RAM you do not own.

trey5498
Jun 23, 2008, 02:19 PM
Your array is an Object. So you declare it something like:

NSMutableArray *arrPRN = [[NSMutableArray alloc] init];



This gave me the error of "error:syntax error before '=' token"

robbieduncan
Jun 23, 2008, 02:30 PM
This gave me the error of "error:syntax error before '=' token"

Really? Is that in your .h or .m file. I can't see any obvious stupid errors on my part...

lee1210
Jun 23, 2008, 02:35 PM
This thread has pretty much covered the right way to do what you're wanting to do, but I thought I'd toss out there what your code actually did, since C is so different in this regard than perl (though you could do something similar with arrayrefs, i suppose).

Any pointer in C can have the array subscript operator, [] applied to it. The first operand, the pointer, has the address it points to incremented by the size of the type it points to multiplied by the second operand, which is the number between the square brackets. In this case, the pointer arrPRN points to the memory allocated by the new message. That address is taken, then 0 to 16*sizeof(NSMutableArray) is added to that address. The resulting memory pointed to by this address is returned as an NSMutableArray, and passed to NSLog. This is, as I'm sure you know by now, not at all what you wanted to happen.

Good luck applying what others in this thread explained.

-Lee

trey5498
Jun 23, 2008, 02:36 PM
NSMutableArray *arrPRN = [[NSMutableArray alloc] init];

is in the header file and the error is located in the .m file. I do apologize for my ignorance in this as I am over taken this task from a coworker that TRULY has no idea. I have made leaps and bounds coming from a Perl man.

robbieduncan
Jun 23, 2008, 02:37 PM
OK, not convinced you are are allowed to allocate an object in the header. Allocate it in the init method in the .m file.

trey5498
Jun 23, 2008, 03:04 PM
error initializing all together whether it is in the .m or the .h

Stupid question? Do I need to include the NSArray.h?

robbieduncan
Jun 23, 2008, 03:05 PM
error initializing all together whether it is in the .m or the .h

Stupid question? Do I need to include the NSArray.h?
Not as long as you are including Cocoa/Cocoa.h or similar.

trey5498
Jun 23, 2008, 03:07 PM
I have that one included. What is a better way of doing the? I really need to figure this out lol

Sbrocket
Jun 23, 2008, 03:10 PM
error initializing all together whether it is in the .m or the .h

Stupid question? Do I need to include the NSArray.h?

Not NSArray.h specifically, no, but there should be somewhere in your code (possibly a .pch file, or if not somewhere else) that includes <Foundation/Foundation.h>. The Foundation framework will include all your base classes like NSArray, NSString, their mutable subclasses, and so on.

Normally Xcode does that kind of thing for you automatically when you start a new project with a Cocoa template, so if you're rolling your own project from scratch you'll need to include Foundation, add the framework to your project, and make sure things are building correctly.

Edit: You people are too quick. Yeah, <Cocoa/Cocoa.h> will work just fine too.

robbieduncan
Jun 23, 2008, 03:11 PM
Post your entire .h and .m files. You need to be doing the allocation in a method like init: not just loose.

Sbrocket
Jun 23, 2008, 03:12 PM
Post your entire .h and .m files. You need to be doing the allocation in a method like init: not just loose.

Well he doesn't have to, no. Not if he's just going to be using that object inside that method anyways.

And dear god, stop typing so fast. :eek:

:p

robbieduncan
Jun 23, 2008, 03:16 PM
Well he doesn't have to, no. Not if he's just going to be using that object inside that method anyways.

And dear god, stop typing so fast. :eek:

:p

I think he does: if you just put something like this in a .m file you get a compiler error (assuming the variable has been declared in a header file):


@implementation MyClass
arrPTR = [[NSMutableArray alloc] init];
@end


It appears that he wants this variable to be an instance variable for the class available for re-use every time the method is called. So it should be in init.

Sbrocket
Jun 23, 2008, 03:18 PM
@implementation MyClass
arrPTR = [[NSMutableArray alloc] init];
@end


It appears that he wants this variable to be an instance variable for the class available for re-use every time the method is called. So it should be in init.

Well no, just sticking it willy nilly in the middle of nowhere isn't right. I was under the impression it was just some temp variable he was using in that method, not an instance variable. Hence the confusion.

trey5498
Jun 23, 2008, 03:26 PM
import <Cocoa/Cocoa.h>

@interface AppController : NSObject {

NSMutableArray *arrPRN = [[NSMutableArray alloc] init];;

//NSArray *arrPRN;
NSWindow *prnOverview;
NSWindow *prnSelector;
// Plotters
IBOutlet NSButton *cse211djq;
IBOutlet NSButton *arc118djq;
// Color Printer
IBOutlet NSButton *cse211clq;
IBOutlet NSButton *arc118clq;
IBOutlet NSButton *hubatlabclq;
IBOutlet NSButton *nrnatlabclq;
IBOutlet NSButton *wei408clq;
}
- (IBAction)NextButton:(id)sender;
- (IBAction)BackButton:(id)sender;
@end


The is a variable that will be used in two places. When the user clicks next it will print it into a NSScrollView so the user can recap what he selected and then again to know what subroutine to call to install.


the comments are me attempt to play around to try different things

robbieduncan
Jun 23, 2008, 03:28 PM
Change the .h to this:

import <Cocoa/Cocoa.h>

@interface AppController : NSObject {

NSMutableArray *arrPRN;

//NSArray *arrPRN;
NSWindow *prnOverview;
NSWindow *prnSelector;
// Plotters
IBOutlet NSButton *cse211djq;
IBOutlet NSButton *arc118djq;
// Color Printer
IBOutlet NSButton *cse211clq;
IBOutlet NSButton *arc118clq;
IBOutlet NSButton *hubatlabclq;
IBOutlet NSButton *nrnatlabclq;
IBOutlet NSButton *wei408clq;
}
- (IBAction)NextButton:(id)sender;
- (IBAction)BackButton:(id)sender;
@end


Edit:

Add


-(id) init
{
if ([super init])
{
arrPRN = [[NSMutableArray alloc] init];
}
return self;
}

-(void) dealloc
{
[arrPRN release];
}

to .m

But in all seriousness this is Cocoa 101. Please go and read some basic documentation...

trey5498
Jun 23, 2008, 03:32 PM
ok, good link on how to convert this onto the NSScrollView? If I was not being rushed because the other person dropped the ball I wouldn't be asking so much.

I do appreciate all the help.

robbieduncan
Jun 23, 2008, 03:36 PM
ok, good link on how to convert this onto the NSScrollView?

You can't. A NSScrollView simply holds another view and allows scrolling of that view via a NSClipView contained within. You need to click through further/harder in Interface Builder to get to the actual NSTextView contained within. Once you have a connection to the text view (not the scroll view or the clip view) you can simply use the insertText: (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextView_Class/Reference/Reference.html#//apple_ref/occ/instm/NSTextView/insertText:) method.

Sbrocket
Jun 23, 2008, 03:37 PM
ok, good link on how to convert this onto the NSScrollView? If I was not being rushed because the other person dropped the ball I would be asking so much.

I do appreciate all the help.

That question doesn't even make any sense.

I would take robbieduncan's advice and go read up on Cocoa 101. We aren't here to do your project or whatever this is for you.

trey5498
Jun 23, 2008, 03:50 PM
the last question was a good link for me to read there Sbrocket. The question however was answered by robbie who went above and beyond simply telling em to read as I would understand him if he just saying this. I do not want you to "do" my project as this will be my job and I need to know how. This project is past over due because of the person I am taking over this for. I simple need guidance and maybe a little looking over my code to see what I did wrong.

Again I appreciate all the help.

Cromulent
Jun 23, 2008, 04:02 PM
the last question was a good link for me to read there Sbrocket. The question however was answered by robbie who went above and beyond simply telling em to read as I would understand him if he just saying this. I do not want you to "do" my project as this will be my job and I need to know how. This project is past over due because of the person I am taking over this for. I simple need guidance and maybe a little looking over my code to see what I did wrong.

Again I appreciate all the help.

Your doing this as a commercial project?

trey5498
Jun 23, 2008, 04:21 PM
no as an educational project to keep the students from screwing up on the printer installs. Each student can download for free once I have done it. It was just promised a month ago and I finally got it thrown into my hands

trey5498
Jun 24, 2008, 06:57 AM
Change the .h to this:

import <Cocoa/Cocoa.h>

@interface AppController : NSObject {

NSMutableArray *arrPRN;

//NSArray *arrPRN;
NSWindow *prnOverview;
NSWindow *prnSelector;
// Plotters
IBOutlet NSButton *cse211djq;
IBOutlet NSButton *arc118djq;
// Color Printer
IBOutlet NSButton *cse211clq;
IBOutlet NSButton *arc118clq;
IBOutlet NSButton *hubatlabclq;
IBOutlet NSButton *nrnatlabclq;
IBOutlet NSButton *wei408clq;
}
- (IBAction)NextButton:(id)sender;
- (IBAction)BackButton:(id)sender;
@end


Edit:

Add


-(id) init
{
if ([super init])
{
arrPRN = [[NSMutableArray alloc] init];
}
return self;
}

-(void) dealloc
{
[arrPRN release];
}

to .m

But in all seriousness this is Cocoa 101. Please go and read some basic documentation...

This built correctly, however it still does the same issue and crashes and never works.

robbieduncan
Jun 24, 2008, 07:00 AM
This built correctly, however it still does the same issue and crashes and never works.

Well, all your previous errors in the .m file still need to be corrected. You should:

1) Not re-initialise arrPRN
2) Ensure you are using the correct NSMutableArray methods (see my previous link) to add/remove items from the array
3) Check that items you read from the array are not nil before using them for anything.

Edit to add: as before: read some basic intro to Cocoa and probably C books/tutorials

trey5498
Jun 24, 2008, 08:13 AM
I have tried every method it seems on that page, I have to be missing something. I have tried initializing the array in almost every way. The way you just suggested doesn't seem to work as I get the same problem that everytime I try to access the array it locks up. I have tried in 2 places (I actually did try it in 2 places before you suggested it as I have 2 books that will be posted at the bottom):


NSMutableArray * arrPRN = [[NSMutableArray alloc] init];


when placed in the .m file it yields an error: " initializer element is not constant" and when in the .h file it yields an error: "syntax error before '=' token".

I understand that this is basic stuff and me being thrown into it kinda defeats the purpose, however when I code the things exactly how apple does and everyone else that knows what they are doing and I get all kinds of errors, I tend to think I need to reach out for help.


there has to be one small thing I have missed. This thing is frustrating me because ever site and ever book I pick up shows the above code I am using and it does not help or work. I get those errors and can't do anything else.

robbieduncan
Jun 24, 2008, 08:19 AM
You are missing the most basic understanding of C (let alone Objective-C or Cocoa). That is the root problem.

Declare the variable in the header.

Initialise the variable in the init. Do not redeclare the variable. This will simply be local to the method call you are in and will not set the class-level variable.

If you are still using arrPRN[] syntax anywhere stop. It's totally wrong.

In all seriousness you need to go back to basics and learn what you are doing. You are a danger at the moment.

lazydog
Jun 24, 2008, 08:30 AM
Hi Trey5498

If you are pushed to get this app out quickly, and considering that you are not familiar with Objective-C and Cocoa, perhaps Cocoa isn't the most appropriate tool for the job. If you are familiar with VisualBASIC then I would suggest taking a look at RealBasic for the Mac. It will do what you need and even if you haven't used VisualBasic etc it will be a lot easier to 'learn on the job' than Objective-C and Cocoa.

b e n

trey5498
Jun 24, 2008, 08:42 AM
I guess this is where my Perl has overwritten anything I ever learned in C/C++.

in Perl you would use arrPRN[i];

in mac you use: anArray objectAtIndex:0?


so the for loop would be?:


for (i=0; i<[arrPRN count]; i++) {
NSLog(@"%@", [arrPRN objectAtIndex: 0];
}


Does it help for you to know that all my C training and experence was in Windows and not in the world of Macs? Every C++ book I have say arrPRN[i] which would explain my confusion if Macs are that much different. Again I do apologize for my ignorance as I am trying to learn under pressure and on the run. I think I am doing pretty darn good to get as far as I have lol.

trey5498
Jun 24, 2008, 08:49 AM
I will try that out. I want to learn all I can, and I am just as eager to learn this as I was in the first. I relish the learning and again, I haven't done that bad considering. I normally have valid code to ask for interpretation of instead of asking how do I do this. I try to read the few books I have and google.

I just need a good nudge in the right directions sometimes it is more of a blatant shove.

robbieduncan
Jun 24, 2008, 08:50 AM
in Perl you would use arrPRN[i];

in mac you use: anArray objectAtIndex:0?

It's not in Mac, it's in Objective-C/Cocoa. You can use other languages to write Mac software (including Perl with the correct libraries installed).

And the answer is still no. If you had an array the arrPRN[i] syntax would be fine. But you don't have an array: you have an object. That object implements methods that allow it to behave like an unbounded array but it's not an array.



for (i=0; i<[arrPRN count]; i++) {
NSLog(@"%@", [arrPRN objectAtIndex: 0];
}



Should work, but you will print the first element every time.

trey5498
Jun 24, 2008, 09:04 AM
meant this:


for (i=0; i<[arrPRN count]; i++) {
NSLog(@"%@", [arrPRN objectAtIndex: i];
}


tried it with:


NSLog(@"%@", [arrPRN objectAtIndex: 0];
NSLog(@"%@", [arrPRN objectAtIndex: 1];
NSLog(@"%@", [arrPRN objectAtIndex: 2];


and it gave me: "-[NSCFArray objectAtIndex:]: index (1) beyond bounds (1)" Which I am assuming that it has something to do with maybe not setting an index or my syntax in adding the the objects to the array. I am using an for every check box.


arrPRN = [NSMutableArray new];
[arrPRN addObject:@"Printer Name"];


seems to workt the first with no problem, code I had there and never took a look at. Guess next thing would be to look at that.

At least I am heading in the right direction I guess lol. I love challenges but I somehow think I will die early because of them.

lee1210
Jun 24, 2008, 09:22 AM
meant this:


for (i=0; i<[arrPRN count]; i++) {
NSLog(@"%@", [arrPRN objectAtIndex: i];
}


tried it with:


NSLog(@"%@", [arrPRN objectAtIndex: 0];
NSLog(@"%@", [arrPRN objectAtIndex: 1];
NSLog(@"%@", [arrPRN objectAtIndex: 2];


and it gave me: "-[NSCFArray objectAtIndex:]: index (1) beyond bounds (1)" Which I am assuming that it has something to do with maybe not setting an index or my syntax in adding the the objects to the array. I am using an for every check box.


arrPRN = [NSMutableArray new];
[arrPRN addObject:@"Printer Name"];


seems to workt the first with no problem, code I had there and never took a look at. Guess next thing would be to look at that.

At least I am heading in the right direction I guess lol. I love challenges but I somehow think I will die early because of them.

I don't know if this is going to be the point that pushes you into getting this going the right way... but arrPRN must be declared once in your header, and initialized once in your init method. You are getting a new bit of memory each time the code is run, so only the last addObject matters. Essentially the code that will run is:


//From init
arrPRN = [[NSMutableArray alloc] init];
//From subsequent calls to your action
arrPrn = [NSMutableArray new];
[arrPRN addObject:@"ItemA"];
arrPrn = [NSMutableArray new];
[arrPRN addObject:@"ItemB"];
arrPrn = [NSMutableArray new];
[arrPRN addObject:@"ItemC"];
arrPrn = [NSMutableArray new];
[arrPRN addObject:@"ItemD"];
arrPrn = [NSMutableArray new];
[arrPRN addObject:@"ItemE"];
NSLog(@"%@", [arrPRN objectAtIndex: 0]; //ItemE will display
NSLog(@"%@", [arrPRN objectAtIndex: 1]; //This will crash, there is only 1 item


At the end, ItemE will be the only one in the list.

Do not access with fixed indicies, this is asking for a seg fault. The first thing you did was OK, but you could also save yourself some trouble and use fast enumeration:
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_7_section_1.html

This will prevent you from violating bounds and save you from having to declare throw-away variables. If you aren't comfortable with that, using a temporary variable from 0-[myObject count] is fine too.

What you want the code to look like is:

//From init
arrPRN = [[NSMutableArray alloc] init];
//From subsequent calls to your action
[arrPRN addObject:@"ItemA"];
[arrPRN addObject:@"ItemB"];
[arrPRN addObject:@"ItemC"];
[arrPRN addObject:@"ItemD"];
[arrPRN addObject:@"ItemE"];
for(NSString tmpString in arrPrn) {
NSLog(@"%@",tmpString);
}


Take the new messages out. You don't want them, and you don't need them. You only need to allocate once, and that should be done with an alloc/init pair of messages in your init method.

-Lee

trey5498
Jun 24, 2008, 10:33 AM
ok the error is in the initiation of the array. I have it set up in the header as

NSMutatableArray *arrPRN;

and I have in the main file of :


-(id) init
{
if ([super init]) {
arrPRN = [[NSMutableArray alloc] init];
}
return self;
}
-(void) dealloc
{
[arrPRN release];
}


Compiles fine with a warning about dealloc not being called, but I know that is because I must call the function. With the for loop now functioning correctly i notice that it still only has one element in the array. Am I correct that a mutablearray is supposed to allow you add an subtract elements from the array with out indicating an index total? How did I manage to mess up the initializer yet again lol. Everything else works.

lee1210
Jun 24, 2008, 10:38 AM
did you take out the new messages? If so, add some NSLog messages around each call to addObject, perhaps printing the count before and after the calls.

-Lee

robbieduncan
Jun 24, 2008, 10:42 AM
Compiles fine with a warning about dealloc not being called, but I know that is because I must call the function.

You should never call dealloc yourself. It's complaining because you are not chaining to the superclass dealloc like this:


-(void) dealloc
{
[super dealloc];
[arrPRN release];
}

trey5498
Jun 24, 2008, 10:47 AM
did you take out the new messages? If so, add some NSLog messages around each call to addObject, perhaps printing the count before and after the calls.

-Lee

I did take out all the [NSMutableArray New]

robbieduncan
Jun 24, 2008, 10:51 AM
Look, zip up the entire project (but not any built/compiled code) and post it here. It'll be easier.

trey5498
Jun 24, 2008, 11:07 AM
Since I have a little bit of size on this I had to use a website by an old firm I used to work for.

http://www.cyberchem.com/Circa.zip

robbieduncan
Jun 24, 2008, 11:08 AM
Great. I'll take a look when I'm at home and on a Mac.

trey5498
Jun 24, 2008, 11:14 AM
Thank you for your time. Again I, in no way want it done for me as I need to learn it, but knowledge of what I am doing wrong will help me learn.

Thank you again for your time. And the DvrChk is not being called at this time because I haven't gotten to it yet lol.

gnasher729
Jun 24, 2008, 11:23 AM
maybe I should have been a tad bit more specific....

the 17 is the fact that there is 17 check boxes it is checking, I just didn't want to put all 17 there to clutter up stuff, however all are coded in the exact same way. the array is declared in the header file as:


NSMutableArray *arrPRN;


If this is done incorrectly, I have coded it the exact same way that the developer site of apple has declaring arrays. So how did I screw up?

It's not so much a screw up, it seems like a complete lack of understanding what you are doing.

arrPRN is a pointer to an object of type NSMutableArray. A pointer to an object should be initialised to NULL until an actual object is created, and then the pointer to that object should be stored here. Question: How often do you call [NSMutableArray new]? Second question: How often _should_ you call [NSMutableArray new]?

Now look up the documentation for NSMutableArray and find out how you access the objects stored in an NSMutableArray. Hint: It doesn't involve the [] operator. It would be useful if you took a C book and figured out what for example the expression arrPRN [15] actually means. It is frighteningly different from what you think it means.

Lastly about your comment "I thought Macs never crash". It is of course not true that Macs _never_ crash, they just don't do it very often unless your hardware is broken. But I am quite sure that running your program didn't crash the Mac at all. I am 99.9999% sure it was _only_ your program that crashed, not the Macintosh. Think of it as a security feature: The Macintosh protects its users from buggy code.

trey5498
Jun 24, 2008, 11:48 AM
gnasher,

have you read all the posts here? A lot of this has been cover from A to Z. I do appreciate your input, however I am not an idiot as one may paint me, just under pressure an asking for advice on my code, not for someone to do it for me.

lee1210
Jun 24, 2008, 12:20 PM
It would be useful if you took a C book and figured out what for example the expression arrPRN [15] actually means. It is frighteningly different from what you think it means.


I posted on this earlier in the thread, my explanation might not be crystal clear, but it should be a start:
http://forums.macrumors.com/showthread.php?t=504818&p=5644889

-Lee

robbieduncan
Jun 24, 2008, 12:36 PM
OK I've found why you only ever have 1 item in your NSMutableArray. And it's a basic logic error that would be the same in Perl so no defence here.

You have code like

if([arc118clq state]==NSOnState) {
[arrPRN addObject:@"ARC-118-CLQ"];

} else if([cse211clq state]==NSOnState) {
[arrPRN addObject:@"CSE-211-CLQ"];

}


So if the first if statement is true the second will never get called and so on (the else).

You need to remove all those elses.

In general the whole thing is a mess. It doesn't seem to follow any OSX interface conventions and is really weird.

trey5498
Jun 24, 2008, 12:46 PM
ya know, I always miss the easy stuff. That is why I ask others to take a look at stuff for me at times. Sometimes you need a 2nd pair of eyes to find an error. Thank, you ever so much.

Next task, head to the NSTextView to get that one working. Thanks for your patience.

trey5498
Jun 24, 2008, 02:49 PM
btw, anymore documentation on how to even get the NSTextView to function correctly? http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextView_Class/Reference/Reference.html#//apple_ref/occ/instm/NSTextView/initWithFrame:
was a good start however The Text View (which says it is both NSScrollView and NSTextView) does not seem to respond to me setting it to a NSTextView in the header file.

I actually got a break tomorrow so I plan on reading as MUCH as possible. So any other good docs/examples of how to set up the array to print to the Text View and also docs on how to check OS version with cocoa? I know how to do it shell.

lee1210
Jun 24, 2008, 03:03 PM
For the text view stuff, it might be good to start a new thread. For the OS detection:
http://cocoadevcentral.com/articles/000067.php

This is an old article, and it would be worth searching the apple dev site for which is best supported on which versions of OS X.

-Lee

trey5498
Jun 24, 2008, 03:07 PM
ty, I found a few threads on here that are worth a look as well. not sure if I can take an array and fill a NSTextView outlet that is connected to the NSScrollView/Text View object. Probably another stupid thing I am missing and I am bound to find it.