Skip to first unread message
Assigned to halab...@google.com by taifu...@gmail.com

lenela...@gmail.com

unread,
Aug 10, 2014, 11:27:12 AM8/10/14
to mitappinv...@googlegroups.com
Hi

I have a procedure that returns the day number of the year. I want it to be called when a button is clicked. And if the day is today I want to open another screen.
But nothing happens.
Attached are procedure.
I can't get the emulator to work, I have started aistarter. But nothing happens.

Kind regards Lene


procedure.png

Enis

unread,
Aug 10, 2014, 11:39:18 AM8/10/14
to
You have to write a procedure to figure out what day of the year it actually is.  Now returns an instant, but you'll have to write something that determines the specific day.  You'll have to know what years are Leap years... they have 366 days vs 365 in a normal year.

Here's the documentation on the Clock component: http://ai2.appinventor.mit.edu/reference/components/sensors.html#Clock

If you're saying the emulator doesn't open at all, that's a totally different issue.

Also, in your code, you're trying to open Screen1.  Screen1 is ALWAYS open... it's the starting screen of your app, and you can't call it with the OpenScreen block.

Stephen Zipprich

unread,
Aug 10, 2014, 10:31:59 PM8/10/14
to mitappinv...@googlegroups.com
Regarding the opening of the screen, it's pretty much irrelevant which screen you're trying to open with your blocks setup the way they are.  You have the label component plugged into the equals operator and the component will never be anything that you specify there.  If you're looking to test the value of the text on the label, you need to use the label.text block instead of the component block.

Taifun

unread,
Aug 11, 2014, 12:56:21 PM8/11/14
to mitappinv...@googlegroups.com
 And if the day is today I want to open another screen.
but you don't like to create a separate screen for each day of the year, do you?
Taifun

Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by Taifun.         

lenela...@gmail.com

unread,
Aug 12, 2014, 11:26:39 AM8/12/14
to mitappinv...@googlegroups.com
Hi

I was send the following:

I'm a bit confused, do I have to code the procedure or is it allready made, and I just have to call it?

Kind Regards Lene



Just use the Clock.Now block to get loads of information, then use a parse procedure to extract the day of year (see snippet below).

Stephen Zipprich

unread,
Aug 12, 2014, 11:39:18 AM8/12/14
to mitappinv...@googlegroups.com
That is a custom procedure you have to write.  Taifun has it linked on his site.

Abraham Getzler

unread,
Aug 12, 2014, 6:02:29 PM8/12/14
to mitappinv...@googlegroups.com
You might not be able to see it online,
but I am waggling my finger now
in disapproval.

Though you have managed to peep under the skirts
of the Clock.Now() routine and seen its hidden
internals, that is no cause to build a routine
based on what you saw today.

There is no assurance in the MIT docs that Clock.Now has
that format.  It's entirely possible and reasonable for any
MIT dev to change that internal format at any time, as long as the external
formats and methods still work the same.

For the sake of your program's longevity and your own
development as a programmer, I say Math Up and find a
sequence of legitimate blocks that will :
  1. Get the formatted YYYY/MM/DD date from Now()   (MM/DD/YYYY is okay too)
  2. Extract the current 4 digit year YYYY
  3. Build the date for New Years YYYY/01/01
  4. Convert that to an Instant
  5. Get the Duration from the New Years Instant to Now() in Milliseconds
  6. Calculate the number of Milliseconds in a day
  7. Divide the Duration by the Milliseconds per day number, and discard the fractional part
  8. Add one to get the day number.

ABG



Taifun

unread,
Aug 12, 2014, 9:26:32 PM8/12/14
to mitappinv...@googlegroups.com
as far as I can see, the Clock.Now method returns the values from the Java class java.util.GregorianCalendar, see also here for Java 7:  http://docs.oracle.com/javase/7/docs/api/java/util/GregorianCalendar.html

I don't think, this will change, at least also for Java 8 this looks the same...
Taifun

Stephen Zipprich

unread,
Aug 12, 2014, 9:34:01 PM8/12/14
to mitappinv...@googlegroups.com
  1. Divide the Duration by the Milliseconds per day number, and discard the fractional part
  2. Add one to get the day number.

Or just use the ceiling block.

 

Abraham Getzler

unread,
Aug 12, 2014, 11:53:51 PM8/12/14
to mitappinv...@googlegroups.com
@Stephen

Virtue is restored!

ABG

Abraham Getzler

unread,
Aug 13, 2014, 12:23:45 AM8/13/14
to mitappinv...@googlegroups.com
@Taifun

Thank you.

That explains the leakage of the term "Calendar" into the web docs for the Clock component.
It deserves a separate post.

I consider use of "inside information" like this hazardous to one's career in programming,
and not to be encouraged.

ABG


Taifun

unread,
Aug 13, 2014, 10:31:37 AM8/13/14
to mitappinv...@googlegroups.com
I consider use of "inside information" like this hazardous to one's career in programming, and not to be encouraged.

that's just some provided information as any other information. IMHO it would be stupid to not use that information to get for example the day of the year.
But probably someone from MIT can say something to clarify that?
Taifun

Abraham Getzler

unread,
Aug 13, 2014, 12:20:21 PM8/13/14
to mitappinv...@googlegroups.com
I'm probably wasting every one's time with this objection.

There's no point in playing building inspector in Lego Land.

;)

ABG



Hal Abelson

unread,
Aug 14, 2014, 9:25:22 AM8/14/14
to mitappinv...@googlegroups.com
App Inventor implements the Clock.Now operation simply by calling Android's Date.Now operation and returning the result.  You can look at the Android SDK operation to see exactly what Google documents.

It's pretty unlikely we're going to change this.  On the other hand, this is an undocumented feature so MIT has no commitment to keep the interface stable.   As Abraham and Tifun have pointed out, using this is risky.
But you are one to decide how much risk you can accept.   You won't be the first software developer to have relied on undocumented features, and you won't be the first one to get burned by it -- nor the last.

== Hal

Peep Prants

unread,
Aug 14, 2014, 9:36:48 AM8/14/14
to mitappinv...@googlegroups.com
If you have virtual server with php support you can make simple php page and use Web->Get->respond
And manual for different samples and format http://www.w3schools.com/php/php_date.asp

Peep Prants

unread,
Aug 14, 2014, 12:49:49 PM8/14/14
to
Sample for you, you Get weekday name here: http://peep.prants.ee/weekday.php 
Php script:
<?php
echo date("l") ;
?>
And sample blocks:


Taifun

unread,
Aug 14, 2014, 1:25:19 PM8/14/14
to mitappinv...@googlegroups.com
thank you for your example Peep, however this discussion was about the "day number of the year", but this of course also could be done using a small php script...
Taifun

lenela...@gmail.com

unread,
Aug 15, 2014, 7:29:37 AM8/15/14
to mitappinv...@googlegroups.com
Hi taifun

No I want to create one new screen, and change the label text and image, depending on the daynumber.

Kind regards Lene

Taifun

unread,
Aug 15, 2014, 10:41:50 AM8/15/14
to mitappinv...@googlegroups.com
Hi Lene, yes, that's the way to go. Happy inventing!
Taifun
Reply all
Reply to author
Forward
0 new messages