Help with calling function

Could someone help me with this function?

Please note that:
(1) This is an abridge code.
(2) performAfterDelay is a beebegames class.
(3) ‘Timer’ is used twice for different call function. Not sure if this is the problem.

However, it is not executing Validate_Date local function at all.

Any clues will be appreciated.

Regards.

[lua]-----------------------------------------------------------------------------
local function Validate_Date ()

– Day must be > 0 but < 32
if InpDate_Day <= 0 then
Date_Invalid = true
Msg_Line.text = “Day must be greater than zero.”
end
end


– Calculate Calendar days difference –

local function Calc_Days_Diff (event)

Date_Invalid = false

if event.phase == “began” then

Msg_Line.text = nil
InpDate_Day = FromDate_Group[1].text
InpDate_Month = FromDate_Group[2].text
InpDate_Year = FromDate_Group[3].text
Timer.performAfterDelay(0, Validate_Date, 1)
end
end[/lua] [import]uid: 93204 topic_id: 19008 reply_id: 319008[/import]

Looking in the API doc’s there does not appear to be a Timer.performAfterDelay function.
Try using:
timer.performWithDelay( delay, listener [, iterations] ) [import]uid: 22878 topic_id: 19008 reply_id: 73215[/import]

Thanks for responding zaphod8. I am using the class as per below for Timer.performAfterDelay.

http://developer.anscamobile.com/forum/2010/12/14/beebegames-class-download

I had also tried using the generic performWithDelay class and that don’t work either.

Regards. [import]uid: 93204 topic_id: 19008 reply_id: 73319[/import]

Try adding a print statement to the function to see if it is getting executed.

Your if statement might not be getting called [import]uid: 84637 topic_id: 19008 reply_id: 73366[/import]

Perhaps having a delay of zero may not work. Have you tried putting in a delay of say 10? [import]uid: 22878 topic_id: 19008 reply_id: 73404[/import]

Thanks Danny and Zaphod8.

I don’t have a print statement, but when I executed the app under the Debugger, it definitely did not execute the Validate_Date function. The delay of 0 worked in a previous function call.

I will give it another go tonight. Perhaps I may even revert back to the previous stable build and find out.

Regards. [import]uid: 93204 topic_id: 19008 reply_id: 73466[/import]

Ok :slight_smile: Post back if it doesn’t work as I have some more ideas as to why it’s not working

You were missing a return statement in your call so see if this eliminates the issue :

[code]

local function Validate_Date ()

– Day must be > 0 but < 32
if InpDate_Day <= 0 then
Date_Invalid = true
Msg_Line.text = “Day must be greater than zero.”
end
end


– Calculate Calendar days difference –

local function Calc_Days_Diff (event)

Date_Invalid = false

if event.phase == “began” then

Msg_Line.text = nil
InpDate_Day = FromDate_Group[1].text
InpDate_Month = FromDate_Group[2].text
InpDate_Year = FromDate_Group[3].text
Timer.performAfterDelay(0, Validate_Date, 1)
end

return true --you need this or the function could get executed a undefined number of times upon a single press of the button
end
[/code] [import]uid: 84637 topic_id: 19008 reply_id: 73758[/import]