Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Problem: CurrencyConverter Tutorial

Problem: CurrencyConverter Tutorial
Thread Tools
Mac Enthusiast
Join Date: Mar 2001
Location: North America
Status: Offline
Reply With Quote
Apr 7, 2001, 02:13 AM
 
This is embarrassing, but I can't get my CurrencyConverter to work. It won't enter the method below under debug. It skips over and does not return the correct float number.

Code:
- (float)convertAmount float)amt atRate float)rate { return (amt * rate); }
Is anyone familiar with this? I tried the usual debugging stuff but it never gives the right return value. It's got me worried that my programming skills are rusting...


It gets called from this method:

Code:
- (IBAction)convert id)sender { float rate, amt, total; total = 10; amt = [dollarField floatValue]; rate = [rateField floatValue]; // THIS LINE HERE!!!!!! total = [converter convertAmount:amt atRate:rate]; // [totalField setFloatValue:total]; [rateField selectText:self]; }
Thanks for any help.
John

[This message has been edited by SillyMonk (edited 04-07-2001).]
My life is my argument. --Albert Schweitzer
     
Fresh-Faced Recruit
Join Date: Apr 2001
Status: Offline
Reply With Quote
Apr 7, 2001, 03:50 AM
 
I am having the same problem with the exact same line of code. I keep getting the message "converter undeclared (first use in this function)" when I build the app. I went back so many times through the tutorial to see if I missed something. I didn't.

I am sure it is one of those things that is so simple, but we don't see it. Any Cocoa experts give us a hand? Please?
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Apr 7, 2001, 04:15 AM
 
Are you including the Converter.h header file in ConverterController? This works fine for me:

ConverterController.m:
Code:
#import "ConverterController.h" #import "Converter.h" @implementation ConverterController - (IBAction)convert:(id)sender { float rate, amt, total; amt = [dollarField floatValue]; rate = [rateField floatValue]; total = [converter convertAmount:amt atRate:rate]; [totalField setFloatValue:total]; [rateField selectText:self]; } - (void)awakeFromNib { [rateField selectText:self]; [[rateField window] makeKeyAndOrderFront:self]; } @end
Converter.m:
Code:
#import "Converter.h" @implementation Converter - (float)convertAmount:(float)amt atRate:(float)rate { return (amt * rate); } @end
     
Mac Enthusiast
Join Date: Mar 2001
Location: North America
Status: Offline
Reply With Quote
Apr 7, 2001, 11:01 AM
 
Angus_D,

thank you for the reply and code. I cut your code and pasted it into my files and I still get the same problem. It compiles fine, just no worky.

I wonder if it is a problem with my use of the Interface builder and the hooks it needs for calling different methods? There was some dragging and dropping that I may have "programmed" incorrectly in the tutorial.

thanks
John
My life is my argument. --Albert Schweitzer
     
Fresh-Faced Recruit
Join Date: Apr 2001
Status: Offline
Reply With Quote
Apr 7, 2001, 01:52 PM
 
John,

I fixed the problem with mine. It seems that I forgot to add the converter outlet in IB. I added it and then declared "IBOutlet id converter;" in ConverterController.h

Now it builds fine. However it still won't run. When I try to run it, I get:

Code:
Apr 07 14:52:07 CurrencyConverter[748] *** -[ConverterController selectText:]: selector not recognized Apr 07 14:52:07 CurrencyConverter[748] An uncaught exception was raised Apr 07 14:52:07 CurrencyConverter[748] *** -[ConverterController selectText:]: selector not recognized Apr 07 14:52:07 CurrencyConverter[748] *** Uncaught exception: <NSInvalidArgumentException> *** -[ConverterController selectText:]: selector not recognized CurrencyConverter.app has exited with status 255.
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Apr 7, 2001, 02:14 PM
 
Definitely sounds like you got some outlets wired up wrong. Check, check and doublecheck!

I can .tar.gz the source and put it on my iDisk if that would be useful, but it's probably best if you do it for yourself (for your own sake ).
     
dws
Forum Regular
Join Date: Apr 2001
Location: Minneapolis, MN, USA
Status: Offline
Reply With Quote
Apr 7, 2001, 02:46 PM
 
My first experience with this tutorial was not promising. I didn't get any compile errors, or errors when running the thing, but it did nothing!

I tried mucking with the build, but got nada.

Then, I started from scratch and did everything again; discovering that I hadn't really understood the instructions about outlets and connections!

It works perfectly now. The tutorial contains no errors. If you follow the instructions exactly, you'll get the right results. You'll also gain valuable experience in working with PB & IB!

Good luck...
     
Mac Enthusiast
Join Date: Mar 2001
Location: North America
Status: Offline
Reply With Quote
Apr 7, 2001, 04:09 PM
 
Thanks everyone for the help.

Angus_D, thanks for the code offer. I really need to understand where I went wrong, but thanks.

dws, I think I messed up the IB stuff as you did. However you say that the tutorial has no errors. I cannot get the find "NSApplicationMain" example to work using the "definitions' setting as they suggest. It only works for me with "textual" option. Maybe my system is messed up <horrors!>

Scratch that last part...I just had to index a couple of more times and then it worked, although I don't know why....

Thanks again.
John

[This message has been edited by SillyMonk (edited 04-07-2001).]
My life is my argument. --Albert Schweitzer
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:58 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2