Loops and procedure problem

Good morning,
I made a program to calculate exposure times.
TempsDePoseAstroObjetListe.aia (18.4 KB)

I would like my program to execute each procedure 6 times and increase the Gregorian time by 0.5 hours for the calculation (this is the only variable that changes in the loop). Then I store in a list the time example 8pm 8.5pm 9pm... and in another list the calculated exposure time (12sec,...).
But when I click on calculate only the first calculation is good.
I don't know loops in programs.
Otherwise do not look at my programming it must be indigestible :o)
Thank you for your help. I attach the program.

upload your relevant (not all) blocks photo here, not an aia.

Ok 2 blocks :

Have you seen the time manipulation blocks in the Clock component?

Just the user imput the time but not time now. My program is ok for 1 value in HeureGregorien but in the loop its bad.
Excuse me for my english but i m french :o)

Have you considered working with Milliseconds for your math?

Also, your blocks image shows a lack of procedure parameters and return values from procedures.

https://code.appinventor.mit.edu/reference/components/sensors.html#Clock

Clock

Image of the Clock component

Non-visible component that provides the instant in time using the internal clock on the phone. It can fire a timer at regularly set intervals and perform time calculations, manipulations, and conversions.

Operations on dates and times, such as from DatePicker and TimePicker, are accomplished through methods in Clock. Date and Time are represented as InstantInTime and Duration.

Instants are assumed to be in the device’s local time zone. When they are converted to or from milliseconds, the milliseconds for a given Instance are calculated from January 1, 1970 in UTC (Greenwich Mean Time).

Methods to convert an Instant to text are also available. Acceptable patterns are empty string, MM/dd/YYYY HH:mm:ss a, or MMM d, yyyy HH:mm. The empty string will provide the default format, which is "MMM d, yyyy HH:mm:ss a" for FormatDateTime, "MMM d, yyyy" for FormatDate. To see all possible formats, please see here.

A note on combining date and time: In order to combine the date from one Instant and the time from another, for example from a DatePicker and TimePicker, extract the parts as text and use the text to create a new Instant. For example:

Example code blocks to combine date and time picker data

Properties

TimerAlwaysFires

Will fire even when application is not showing on the screen if true

TimerEnabled

Specifies whether the Timer event should run.

TimerInterval

Specifies the interval between subsequent Timer events.

Note: Drift may occur over time and that the system may not honor the timing specified here if the app or another process on the phone is busy.

Events

Timer()

The Timer event runs when the timer has gone off.

Methods

AddDays(instant,quantity)

Returns an instant in time some days after the given instant.

AddDuration(instant,quantity)

Returns an instant in time some duration after the argument

AddHours(instant,quantity)

Returns an instant in time some hours after the given instant.

AddMinutes(instant,quantity)

Returns an instant in time some minutes after the given instant.

AddMonths(instant,quantity)

Returns an instant in time some months after the given instant.

AddSeconds(instant,quantity)

Returns an instant in time some seconds after the given instant.

AddWeeks(instant,quantity)

Returns An instant in time some weeks after the given instant.

AddYears(instant,quantity)

Returns an instant in time some years after the given instant.

DayOfMonth(instant)

Returns the day of the month.

Duration(start,end)

Returns the milliseconds by which end follows start (+ or -)

DurationToDays(duration)

Returns the duration converted from milliseconds to days.

DurationToHours(duration)

Returns the duration converted from milliseconds to hours.

DurationToMinutes(duration)

Returns the duration converted from milliseconds to minutes.

DurationToSeconds(duration)

Returns the duration converted from milliseconds to seconds.

DurationToWeeks(duration)

Returns the duration converted from milliseconds to weeks.

FormatDate(instant,pattern)

Converts and formats an instant into a string of date with the specified pattern. To learn more about valid patterns, please see SimpleDateFormat.

FormatDateTime(instant,pattern)

Converts and formats an instant into a string of date and time with the specified pattern. To learn more about valid patterns, please see SimpleDateFormat.

FormatTime(instant)

Converts and formats the given instant into a string with the specified pattern. To learn more about valid patterns, please see SimpleDateFormat.

GetMillis(instant)

Returns the instant in time measured as milliseconds since 1970.

Hour(instant)

Returns the hours for the given date.

MakeDate(year,month,day)

Returns an instant in time specified by year, month, date in UTC. Valid values for the month field are 1-12 and 1-31 for the day field.

MakeInstant(from)

Returns an instant in time specified by MM/dd/YYYY hh:mm:ss or MM/dd/YYYY or hh:mm.

MakeInstantFromMillis(millis)

Returns an instant in time specified by the milliseconds since 1970 in UTC.

MakeInstantFromParts(year,month,day,hour,minute,second)

Returns an instant in time specified by year, month, date, hour, minute, second in UTC.

MakeTime(hour,minute,second)

Returns an instant in time specified by hour, minute, second in UTC.

Minute(instant)

Returns the minutes for the given date.

Month(instant)

Returns the number of the month for the given instant.

MonthName(instant)

Returns the name of the month for the given instant.

Now()

Returns the current instant in time read from phone’s clock.

Second(instant)

Returns the seconds for the given instant.

SystemTime()

Returns the phone’s internal time.

Weekday(instant)

Returns the weekday for the given instant.

WeekdayName(instant)

Returns the name of the weekday for the given instant.

Year(instant)

Returns the year of the given instant.

I post the .aia for see my program with all parameters and procedure.
I think the problem is increment my HeureGregorien because with my excel page i haven't the same results in label text with the JourJulien variable.

Since your code is already full of global variables, try debugging using the Do It facility, tracing numeric values through your code.

Be sure your Companion is up to date.

I see you are doing trigonometry.

See

for how to bridge between Excel trigonometry and AI2 trigonometry.

Ok i see my error. Juste at the end of procedure i add a command to multiply the value by 24.
Thank

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.