2016년 12월 11일 일요일

Help with making an age calculator?

I was hoping some one could possibly help me code an app that is able to tell you your exact age down to the second. I have a small amount of knowledge with coding in MIT App Inventor 2, so you'll have to bear with me. I have the app layout completed, but I'm completely stumped with the code. I have a clock component and see all of the blocks that you would use, I just don't know how to make it happen. When you press the 'Find my age button', it will take you to a second screen that displays your age. I understand a Tiny DB is required to transfer data between screens, but yet again, I am not sure how. I understand this will all have to be on one screen if it is too complicated to transfer the answer and all over to another screen. I will show screenshots of both of the screens at the bottom of this post. (Sorry if the first screen is confusing to look at. I wasn't sure how to put spaces between text boxes and such and didn't want the entire screen crammed together, so I used blank horizontal alignments.) The only coding I have done so far is for the clear button. Any help would be greatly appreciated, and if you need any extra info ask away, I will provide you with as much details as I can.
Screen Shot 2016-12-05 at 6.10.11 PM.png 표시 중

Screen Shot 2016-12-05 at 5.59.52 PM.png 표시 중
You might look at the example here which is not exactly what you want but perhaps good enough  https://groups.google.com/forum/#!searchin/mitappinventortest/calculate$20age/mitappinventortest/cwn1_Kj_wVY/8gpGS4R8DwAJ     Try the aia.

Perhaps before you continue your Project you should consider doing some tutorials about how to program?

Here are several issues that make your apparently simple app difficult even for seasoned users to program.  

How to pass values from one screen to another screen by Scott

Before starting to create another screen, think about is it really necessary?  If you use multiple screens you have to pass information between screen which means you will probably use a TinyDB control -- not simple for a beginner.   It would be better to build this on  a single screen.  See  Building apps with many screens and the reasons why a single screen is probably best  https://groups.google.com/forum/#!msg/mitappinventortest/ka-LS7wmWxs/wRbs70x2BgAJ   

Also you need to learn to switch screens responsibly as shown in Taifun's example:
      The recommended method of switching screens in App Inventor   if you are firm about using multiple screens.

To understand the Clock component, you might read http://ai2.appinventor.mit.edu/reference/components/sensors.html#Clock

To finish your project, you might consult the following resources to help you learn to use the AI2 tools:  A very good way to learn App Inventor is to read the free Inventor's Manual in the AI2 free online eBook   http://www.appinventor.org/book2 ... the links are at the bottom of the Web page.  The book 'teaches' users how to program with AI2 blocks.  

There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro  and the aia files for the projects in the book are here:  http://www.appinventor.org/bookFiles  

How to do a lot of basic things with App Inventor are described here:  http://www.appinventor.org/content/howDoYou/eventHandling.

The MIT tutorials are here:  http://appinventor.mit.edu/explore/ai2/tutorials.html  

Have you read Dr. Wolber's book?  Have you done any tutorials?

Thank you for the help everyone, sorry for the long reply. I've moved everything to one screen so things are less complicated. I have indeed done some tutorials, I have been in an app developing class (we've used nothing but MIT2 so far) since August. My teacher isn't exactly the best at explaining things so I'm not as well developed as I should be. I've looked at the .aia for the file you attached and I'm wondering how I would show the other time values (months, weeks, days, hours, minutes, and seconds) instead of only the year being displayed. I've read up on the clock components and things make a bit more sense, though I'm still slightly confused on to how to do it all. Again, thank you for taking the time to respond to my post, I appreciate the help.

This is a different solution

Feel free to experiment.  It does not break the age in to  days + hours + minutes + seconds   if that is what you have to have.   You can use the days and the fractional part to convert the fractional day into hours and minutes and seconds remembering     24 hours in a day  60 minutes in an hour and 60 seconds in a minute ..... Purists will quibble about the 4 leap years in this example (or 3 depending on how you count) and how to handle it but I suspect this may be good enough?

Yes, this will be good enough. Thank you so much! Have a wonderful rest of the night sir.


Multi-Select in AI2

Abe Getzler

Instead of a whole bunch of check boxes, it’s possible to use two list pickers to maintain lists of included and excluded values.

These two side by side list pickers show their underlying lists in their text areas.
They are wired so that selecting from one side transfers the selected item to the other side.

The list pickers are arranged side by side above a button that resets their contents.

After resetting the list picker lists, we update the list picker Text areas to display the lists vertically.

The AfterPicking blocks for the two list pickers are symmetric.  The selected item is merged into the other list picker’s Elements list, then it is removed from the chosen list picker’s Elements list. Finally, the Text areas of the list pickers are refreshed.

To maintain sort order in the elements lists, we use a function procedure to handle the insertion …

The merge procedure accepts a copy of a list and the value to insert.  It searches from position 1 forward until the end of the list or until the insertion value is no longer greater than the current item. It then inserts the input item at that slot, and returns the updated list.


Re-order bands music playlist (not Google playlist)

 I want to make an app for my girlfriends band. I have searched many forums and the net at large but, because of the naming (music re-order list) the wrong type of apps come up. I want 2 simple boxes. The left hand box to hold a list of all the bands songs and associated meta data such as length of each song. The idea is, you select the songs from the left box which creates the new playlist in the right box. Long-pressing the songs in the right box to re-order them.  Having the length of songs attached allows a cumulative total length of show, in the right box,  to be easily configured into a 1, 2, or 3 hour show. I have attached a similar image layout, albeit not the same content.  Please let me know if this is not the right place for this thread, as its been years since I last delved into apps. 

App idea 001.png 표시 중

Try to learn some App Inventor first by doing some tutorials. That way you will find out whether AI is suitable for you, and you will have more specific questions you can add here.
Taifun's top 5 tips: http://puravidaapps.com/learn.php
See this Multi-Select example ...

Wow....Thank you so much! That is so close to what I am looking for it's scary. Lot's of tweaking yet but what a great start!  Now hoping there is a way to change the integers into buttons that link to words for the associated songs. Also, my girlfriend is legally blind so need to make them expandable.


Now hoping there is a way to change the integers into buttons that link to words for the associated songs

You can just as easily load text into lists as integers.
for navigable text samples.

. Also, my girlfriend is legally blind so need to make them expandable.

The ListView has an adjustable font size.


a random generator (issues with code)

Firstly: i know very little about programming and what i have done is based on some of the example programs and videos i have found.

Secondly: this program is just a way to generate a random set of information about MTG cards that i can deign around.


(1) i have IF statements to take care of outliers in regards to things that definitly don't exist or can't exist in the MTG card universe. the main issue i'm having is that no matter if i nest the IF statements regarding Land, or separate the IF statements I still have an issue where when the Supertype: "land" is picked randomly it produces a set of colors, which can't happen.

(2) the same issue with land happens with the Supertypes: "Creature", "Land Creature", "Artifact Creature"

you will notice that i have not completed the global lists for each section, as such i want the generator to function as needed before changing the list with the correct information.

i have no clue what is going on and would greatly appreciate some assistance as to why this is the case and maybe a solution to the issue if possible.

What is a set of MTG cards?
And, could you post a readable screenshot?

to answer the questions:

*MTG is a shorthand or an abbreviation of the card game Magic: The Gathering.
*the screenshot that i posted is huge. if you click on it you also have the ability to zoom into 90% of the code and see the possible issues.
*i've also attached to the original post the whole program in .aia format for people who would like to mess around with the code themselves without relying on screenshots.

 I still have an issue where when the Supertype: "land" is picked randomly it produces a set of colors, which can't happen

Look in the logic blocks for green AND blocks, to combine restrictions.
See the Books and tutorials section of this FAQ for a well indexed textbook,
to learn about logic.

Also consider setting up your combinations in a table or tables.
Read up on lists and lists of lists, especially the lookup-in-pairs block.

See the Lists section of that FAQ for examples.

I asked my husband, who used to play MTG endlessly with my sons. He said that he did not understand what you are trying to do.
Maybe you could spell out the rules more clearly and make a table or a tree structure showing what the possible combinations are.
Then, you can determine a strategy to implement this.
Cheers, Ghica.

so the goal is to create a fake card (for art reasons) keep my mind going, etc...

the generator creates a fake card based on the border (old, modern, unglued, etc...). what the color might be for the card (white, blue, black, red, green), what type of card (land, creature, sorcery, instant, etc...), and any any creature types if creature is the typed picked by the generator.

the issues i'm having result when card that can't have a color assigned to them (anything with the Land or Conspiracy type in the name) end up with a random color that gets picked by the generator. which i don't want.

the picture shows that i have created if/then/else statements to help the generator, but they don't seem to be doing what i expect.

with other programming languages (OBJ/Java) this type of implementation is easy. i'm just not a fan. and this web-based program was supposed to make the whole thing quick-and-dirty as i don't need to be polished i'm just looking for a way to keep my creative juices working when i'm bored. 

never mind et. al. i fixed my own issue.

i used nested IF/THEN/ELSE statements to fix the logic problem with the program. 

ugly and dirty way to fix and issue i know but it works and thats all that matters.

What you want to do with your project is relatively straight forward in AI2 too.   I expect you have read http://www.appinventor.org/bookChapters/chapter18.pdf  It shows how if..then..else statements work and how to use them with conditionals. Since you are familiar with Java you just need to get familiar with using the blocks.   Rereading you will find that the if statements work just like they do in scripting languages.  Moving from low level languages to AI2 is a bit discerning, especially for programmers who have experience with other programming languages.

With the code you posted, it is not apparent how you tried to handle  "cards that can't have a color assigned to them (anything with the Land or Conspiracy type in the name) "  .  Take a look at the section Programming Conditions within Conditions perhaps and you might not have an 'ugly and dirty" way to fix the issue.

Glad you got your test set to work the way you wanted it to.  


How to use an external Bluetooth GPS ?

I need to use an external GPS. GPS is connected with a bluetooth. What blocks could i use for Latitude and longitude ? 

I assume you have an Arduino and a GPS shield.  You might want to view this video https://www.youtube.com/watch?v=v74E01ESdUA    The video shows the principles of use.  The Arduino has the ability to send the latitude, longitude and time  from the GPS as comma separated data. (cvs).  

The Arduino needs a module to communicate via Bluetooth.    You use the Bluetooth to communicate with your Android with AI2.  

You will need the AI2 Bluetooth blocks and capture the NEMA cvs, you can then post the data stream to a label or whatever.  You might search the forum for  GPS Arduino Bluetooth to see what other forum users have to say.   I am not aware of a tutorial that specifically shows how to  capture latitude and longitude from the external GPS.

What have you tried?   Can you capture the data stream from the GPS or are you just starting to program?

 I suggest before you start using a separate device, you learn to use GPS navigation using the GPS in your Android.  You might look at the MIT tutorial  Walk, then run.  Then look at the threads here   https://groups.google.com/forum/#!searchin/mitappinventortest/arduino   that lists discussions in the Forum how to do do things with Arduino ... a device controller possibly similar to what you have.  One of the threads discusses using a separate GPS device ..you need to find it.

We want you to have fun with App Inventor so here are some resources to help you learn to use the AI2 tools  A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook   http://www.appinventor.org/book2 ... the links are at the bottom of the Web page.  The book 'teaches' users how to program with AI2 blocks. You can read the entire book in an hour or so and the time spent will be worth while.

There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro  and the aia files for the projects in the book are here:  http://www.appinventor.org/bookFiles  

How to do a lot of basic things with App Inventor are described here:  http://www.appinventor.org/content/howDoYou/eventHandling.

Does this help you program?    Please continue to ask questions here however if you read the information above, you will not have to wait for answers.

Just try some blocks and have fun... and walk, don't run.  Run later and ask specific questions when you have tried some blocks.

I use also external BT-gps module due the possibility to have correction calculation to data stream with Lefebure NTRIP software, maybe this could be one solution. But now one question about Ai2 position block: why lat&lon desimal are cutted (trim) to 5 digits? And is there a trick to get more digits from block; location changed? And another question: how to make block where I can get lat&lon for example every second? This would be very useful when calculating capability of location data, for example collect 10 pcs lat&lon => calculate position accuracy, how big circle is where all collected points are etc.

Have you read the MIT LocationSensor tutorial and did you DO the exercises (both projects)  https://docs.google.com/document/d/1V1Zm5cYoa12KVb_cTlfelSfyUkW7IH2WPHUoTa02XaY/pub  
The gps in phones/tablets is not necessarily the precision surveying tool many think it is.  Data reported by the GPS is frequently off by +/- 50 meters or more and seldom accurate to within 2 or 3 meters.

Satellite NEMA strings are reported to five digits as the data is broadcast from the positional satellites.  The GPS receives a data string to a precision of five digits as a text string..   0.00001 of a degree of latitude is 0.006 of a nautical mile, or 3 feet, 7+3/4 inches

More digits ... oh it is possible but NOT with the phones and tablets that Android uses. "More digits" is obtained by 'averaging' multiple satellite fixes and statistical processing.  One cannot do that to the precision required with AI2 in a reasonable time frame probably. Professional surveyors us multi-channel dedicated GPS receivers and special techniques to get greater precision.  Five digits (  0.00001 of a degree of latitude)  provides a resolution of  0.9144 meters; seldom possible with a phone GPS  (read the article about Accuracy and multi-channel GPS receivers)

You cannot actually get latitude and longitude every second using an Android and AI2.  When you query the sensor, the sensor takes a few seconds to get a satellite 'fix'   The initial fix might take 20 to 30 seconds or more and sometimes one can get a 'fix'.  Setting the interval to less than 5000 ms (5 seconds) will probably give your Android a 'heart attack'...AI2 processes commands asynchronously.  Request more often and you request a new fix before the previous fix is resolved by your Android's cpu . Most likely no new data will be acquired.  There are other reasons why you do not want to sample every second.

The LocationSensor algorithms calculate an Accuracycircle.  You can read about it and use the aia file in the article to test your device.  Sorry, the GPS and Android usually do not report exactly where the data says the device is located.  Really? So, to help users, a concept called Accuracy is calculated.  What is reported as a satellite fix lays within one standard deviation of where it is actually reported.  Accuracy is affected by the number of satellites the GPS uses to get a fix, the angles to the satellites etc.

Yes, you can plot 10 samples of latitude and longitude using the Google Maps API ...the simplest way is to create a static map  and/or you could write a statistical algorithm to use the information from the ten locations to statistically average them.  Have you ever tried to solve Math issues with AI2 blocks?   Scary.  Statistical algorithms take a long time to create.  AI2 is not a scripting language and the blocks are awkward creating formulas.  When you are done the processing is relatively slow for lots of reasons compared to a Java solution.  The algorithms themselves are not trivial.  Give it a try and please post your statistical averaging block so the AI2 users can benefit.   You might find searching for terms like Kriging , spatial data, gridding etc will help you find an appropriate algorithm to create a spatial average of the ten locations.  Many of these techniques require using matrices , integration and determinates ..concepts AI2's math drawer cannot really handle.

Please read the article and when you are done perhaps google     NEMA ,  GPS resolution  etc. on the Internet to help you understand why GPS measurements with Android phones is not precise.  The MIT article is intended as an introduction to the concepts of geo-positioning and using a GPS receiver.

Yep, just those mentioned tutorials has guided to this location world with AI2. I understand the fact of phone or tablet gps/glonass capabilty&accuracy and that is the reason why I am using external BT-receiver&software to re-calculate the information of positioning (Lefebure NTRIP).

 I live in Finland and we have free (!) accses to correlation data from our geologic institute and with this method the accuracy of positioning data can be quite nice. I can reach HDOP-values up to 0.7-0.9 with 11-12 satellites, when the sky is clear and the humidity is low. HDOP-value is telling to me, when the quality is good enough to use data to post processing.

I studied also a little the documentation of those java classes and I found the information of class Location:Constants;Constant used to specify formatting of a latitude or longitude in the form "[+-]DDD.DDDDD where D indicates degrees.

So, I have to study more of programming and try to read direct information of nmea-stream...

And the reason why I am doing this more or less crazy stuff:

I like to develop a app where user can pick two points (more than 50 meters difference) and this app calculates my diff from straight line when I am walking between points.
And because my hobby is also math&stats, the calculating two-dimensional data capability is also quite challenging and fun and those purposes I use R, but the data have to be collect first.


Image switch on and off with AppInventor

I use an image (gr_Pkt_Z2_li), that only shows a green point.  This image I want to switch on (it's visibel)  or off (it is'nt visibel) by touching the button  "lenken_STOPP".

With this block it works well  to switch the picture off. But if I change false to true it don't work, the picture isn't to see.   What is wrong?

The parameter Visible I can't use, because the image is in a field of a TableArrangement. If I switch Visible off, than the other parts off this row move to left.

What you could do is provide a second image that is the same size as gr_{lt_Z72_li but is entirely white and set the Picture of the button to that image?  That is, why not switch between two images, one your green point and another image that is entirely white?  One for ON one for OFF?

Incidentally for you block set gr_Pkt_Z2_li. Picture  (which I think might be an Image control), should possibly be not Picture but Visible = false  ??   (set gr_Pkt_Z2_li.Visible to false ) if you want to hide it and to true if you want to show it.

Yes, if you hide an image in a TableArrangement , it is true that one switch Visible off by hiding the image , than the other parts off this row move to left, so if you are going to work like this, use TWO images.

If you haven't seen the free online AI2 book by Prof. Wolber (  http://www.appinventor.org/book2 ) you might want to read it.   It will help you to program.

thanks for your answer.

But it isn't possible to put 2 images into the same field of the TableArrangement. So I have to add one column??  Is that correct?


I think you can place two images into the same field of the TableArrangement.   Make one image's   visible property  true, the other false; when you want to switch which shows, make the first false and the second true.  I am fairly certain this works.  Try it and let us know how it works.

Alternatively, yes, you could add another column, however instead you can write code to replace the green image with a different image of the same size.   Several different images can be displayed on an Image component by writing  if .. then code.

Try some different solutions Freddy and let us know what works for you in your App.

what about using only one image component and change the picture property of the image accordingly?

And I don't know how to change the picture property of an imagee.

set Image.Picture to "blau.jpg"

and somewhere else in your blocks

set Image.Picture to "weiss.jpg"

A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook   http://www.appinventor.org/book2 ... the links are at the bottom of the Web page.  The book 'teaches' users how to program with AI2 blocks.
There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro  and the aia files for the projects in the book are here:  http://www.appinventor.org/bookFiles  
How to do a lot of basic things with App Inventor are described here:  http://www.appinventor.org/content/howDoYou/eventHandling  .

Also do the tutorials http://appinventor.mit.edu/explore/ai2/tutorials.html to learn the basics of AppInventor, then try something and follow the
 Top 5 Tips: How to learn App Inventor

You will not find a tutorial, which does exactly what you are looking for. But doing the tutorials (not only reading a little bit) help you to understand, how things are working. This is important and this is the first step to do.


Easiest way to connect MiT App Inventor to SQL Server DB or other options

Can anyone tell me the easiest way to connect MiT AppInventor to SQL Server DB or if there are easier options via other app designer companies!
Is this the same for connecting to a Microsoft SQL Server database? ("not" MySQL?)


Run out of memory when loading new screen

I have an app that only has 2 screens.  But just recently the app would crash every time i try to go to screen 2 and idk why

What does your Screen2 initialize do? Do you have/load large media files?

No, there's not even a Screen Initialize block put into that screen

My mistake, yes there is, 5 txt files are created if they were not already when screen 2 is loaded

Consider monitoring the logcat which most likely will tell you what the issue is.

Based on crash reports, the app runs out of memory when it tries to load page 2

I think i found the issue!  If i remove the Pink Play buttons to the right, it stops crashing.  But the only problem is that i need those buttons to play audio.  Any way around this?

Check the type of image and also check its size.

The images are only 40x by 40x and are PNG