Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Tools & Utilities

Reply
 
LinkBack Thread Tools Display Modes
Old 12-11-2010, 11:38 PM   #1 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 6
jassim is on a distinguished road
Default Actions and reseting values within the if statement.

hi guys,

I am a beginner to programming, i need some help if possible.

i have created 4 Actions a,b,c & reset. each action is connected to a button. and within each Action, there is an if statement. So if the first action 'a' fulfills the if statement within, then the second button 'b' is to be pressed until the if statement within is fulfilled. then is the same for the third button 'c'.

the buttons. a,b and c they count and show numbers. 'a' will show 1-4, 'b' will show 1-3 and 'b' will show 1-3 again.
all the above up to here are ok.

my problem is with the final button i have created 'reset'. the purpose is to reset all variables to '0' and start over the counting again for a,b and c. I CANNOT DO THIS RESET. i need this reset to reset all values to start over again whenever it is pressed.

please could anybody let me know how could i do this and where to find the solution?

Thanks,
jass
jassim is offline   Reply With Quote
Old 12-12-2010, 12:43 AM   #2 (permalink)
Registered Member
 
Join Date: Oct 2010
Location: Reston, VA
Posts: 39
FirozeLafeer is on a distinguished road
Default

When you say you "can't" do it, what have you tried and what was the outcome?

Where are these counts being stored? Where are these actions defined?
FirozeLafeer is offline   Reply With Quote
Old 12-12-2010, 02:14 AM   #3 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 551
aldcorn@live.com is on a distinguished road
Default Are you using value ?

It sounds like each button is generating a value, yes?

Each push adds on 1 to that value, yes?

In the reset action you simply need to set value 1,2 and 3 to 0.
Use the same process that you use to create the value to be displayed for each button and set it to =0.

If you post code it should be easy to give you an answer specific to your needs.
aldcorn@live.com is offline   Reply With Quote
Old 12-12-2010, 09:07 PM   #4 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 6
jassim is on a distinguished road
Default

Quote:
Originally Posted by aldcorn@live.com View Post
It sounds like each button is generating a value, yes?

Each push adds on 1 to that value, yes?

In the reset action you simply need to set value 1,2 and 3 to 0.
Use the same process that you use to create the value to be displayed for each button and set it to =0.

If you post code it should be easy to give you an answer specific to your needs.

Thanks for responding,
I think you got my point, I did what you recommended and set the value again to 0, but when i press the actions again the value remains as 0.
hoe to make the actions a,b and c start counting again from 1?


This is what i am doing

"
int counta=1;
NSString *msga=nil;

-(IBAction)outPutaid)sender {

msga=[[NSString alloc]initWithFormat:@"%i",counta];

if (counta<=4) {

printf("%i",counta);
resulta.text=msga;
}
counta=counta+1;

}


int countb=1;
NSString *msgb=nil;

-(IBAction)outPutbid)sender {
msgb=[[NSString alloc]initWithFormat:@"%i",countb];

if (counta>4) {

if (countb<=3) {
printf("%i",countb);
resultb.text=msgb;
}
countb=countb+1;
}
}


int countc=1;
NSString *msgc=nil;

-(IBAction)outPutcid)sender {
msgc=[[NSString alloc]initWithFormat:@"%i",countc];

if (countb>3) {

if (countc<=3) {
printf("%i",countc);
resultc.text=msgc;
}
countc=countc+1;
}


}

NSString *msgreset=nil;

-(IBAction)resetButtonid)send{


int counta=0;
int countb=0;
int countc=0;


msgreset=[[NSString alloc]initWithFormat:@"%i",counta];
msgreset=[[NSString alloc]initWithFormat:@"%i",countb];
msgreset=[[NSString alloc]initWithFormat:@"%i",countc];


resulta.text=msgreset;
resultb.text=msgreset;
resultc.text=msgreset;

printf("count a=%i",counta);
printf("count b=%i",countb);
printf("count c=%i",countc);

}


- (void)dealloc {

[resulta release];
[resultb release];
[resultc release];

[super dealloc];
}

"


thanks, very appreciate your support.
Jassim.
jassim is offline   Reply With Quote
Old 12-12-2010, 10:34 PM   #5 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 551
aldcorn@live.com is on a distinguished road
Default let's see

Just to help others read your code please use the code tags when posting...

Code:
your code here
Try replacing this (in your reset function):
Code:
resulta.text=msgreset;
resultb.text=msgreset;
resultc.text=msgreset;
With this:
Code:
msga=[[NSString alloc]initWithFormat:@"%i",counta];
resulta.text=msga;
msgb=[[NSString alloc]initWithFormat:@"%i",countb];
resultb.text=msgb;
msgc=[[NSString alloc]initWithFormat:@"%i",countc];
resultc.text=msgc;
Remove all of these:
Code:
NSString *msgreset=nil;
They don't look like they are doing anything, except for the ones in your reset function. They are not helping you in that function though. Try to remove them.

Last edited by aldcorn@live.com; 12-12-2010 at 10:38 PM.
aldcorn@live.com is offline   Reply With Quote
Old 12-13-2010, 09:39 PM   #6 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 6
jassim is on a distinguished road
Smile

Quote:
Originally Posted by aldcorn@live.com View Post
It sounds like each button is generating a value, yes?

Each push adds on 1 to that value, yes?

In the reset action you simply need to set value 1,2 and 3 to 0. your
Use the same process that you use to create the value to be displayed for each button and set it to =0.

If you post code it should be easy to give you an answer specific to your needs.
Quote:
Originally Posted by aldcorn@live.com View Post
Just to help others read code please use the code tags when posting...

Code:
your code here
Try replacing this (in your reset function):
Code:
resulta.text=msgreset;
resultb.text=msgreset;
resultc.text=msgreset;
With this:
Code:
msga=[[NSString alloc]initWithFormat:@"%i",counta];
resulta.text=msga;
msgb=[[NSString alloc]initWithFormat:@"%i",countb];
resultb.text=msgb;
msgc=[[NSString alloc]initWithFormat:@"%i",countc];
resultc.text=msgc;
Remove all of these:
Code:
NSString *msgreset=nil;
They don't look like they are doing anything, except for the ones in your reset function. They are not helping you in that function though. Try to remove them.

Thank for your advice. I have changed as per your advised,


Code:
msga=[[NSString alloc]initWithFormat:@"%i",counta];
resulta.text=msga;
msgb=[[NSString alloc]initWithFormat:@"%i",countb];
resultb.text=msgb;
msgc=[[NSString alloc]initWithFormat:@"%i",countc];
resultc.text=msgc;
this way looks better.

but removing the

Code:
NSString *msgreset=nil;
I received error messages. so I have kept it.

Then I have tracked my values with fprint and found that the value 'counta' was still adding when ever a button is pressed. so I have adjusted the if statement and then everything went just great.

again, thank you very much for your advice.

Somehow I could not see the silly mistake. Your advice made me look from a different angle .


cheeers
jassim is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting 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



» Advertisements
» Online Users: 422
11 members and 411 guests
AppleDev, chemistry, Emy, Gi-lo, ipodphone, mistergreen2011, pipposanta, Retouchable, skrew88, SLIC
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,128
Posts: 402,923
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:21 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0