Skip to first unread message

Mrs. Mac

unread,
Feb 11, 2019, 4:43:02 PM2/11/19
to MIT App Inventor Forum
Hello All,

I am new at this.  I created a firedatabase that accepts a State and a percentage of the State.  The Dat gets stored then I can display it.  No Problem.  However I want to add a number to my Tag's Value and I get the String Problem . I know I am doing something ridiculous but can you help me.
stringerror.png
Stringproblem.png

Evan Patton

unread,
Feb 11, 2019, 5:03:50 PM2/11/19
to MIT App Inventor Forum
It's tough to tell, but here's my thought:

1. In the store method, you store the value "" in the key named by the state variable
2. This will trigger the Firebase DataChanged event, where you check the value of the tag against the state, and since that's probably still true from the previous step, then it will store the value (which was the empty string) into the percentage field.
3. Now, when you click the button to add 2 percent, percentage is now the empty string, resulting in your error.

To confirm, you might want to have the store value function store the value 0 rather than the empty string, or adapt your logic in your DataChanged event to be more robust based on the type of data you're storing, e.g., by making the tag include more information or using the isnumber? and isstring? blocks depending on what you're trying to manipulate.

Cheers,
Evan

Mrs. Mac

unread,
Feb 12, 2019, 7:37:11 PM2/12/19
to MIT App Inventor Forum
Hi Evan,

I'm so glad you are willing to help me.  Please bare with me on a few problems.  When I make the Store Value a "0" the values gets stored in my database as a "0" In fact any number I put in there gets stored as that number.  I am using one of the blue math components to do this, I'm assuming thats right?  The I used the isnumber? and String? together and separately I still get the problem.

Any other suggestions?

Thanks
Deb

ABG

unread,
Feb 13, 2019, 1:58:10 PM2/13/19
to MIT App Inventor Forum
You haven't shown us all your blocks.

In a blank space in the Blocks Editor,
do a right click Download Blocks As Image
and post your blocks.png file here.

The + block, like other math blocks,
is finicky, rejecting empty text.
You can filter its input to avoid errors:

C = + (if is a number(A) then A else 0,
         (if is a number(b) then b else 0)

ABG

Deborah MacNeil

unread,
Feb 13, 2019, 2:51:06 PM2/13/19
to MIT App Inventor Forum
Dear ABG,

Thank you for helping attached are all my blocks.  I think I understand what you are talking about utilizing the if is a number.  I tried it and it sdid not work.  I used it on the changes data component and the 1800 button.  Any other suggestions.

Thanks you again

Deb
2-13-19database.PNG

ABG

unread,
Feb 13, 2019, 3:08:34 PM2/13/19
to MIT App Inventor Forum
Attached is a plus procedure you can use instead of
the AI2 + block, to never crash.

You can copy it by importing the .aia file
and using the backpack to copy it
across projects.

But never crashing doesn't insure correctness,
like in the 2% example,
since AI2 does not understand the meaning of %
and ignoring it by zeroing out everything is
quiet but inadequate.

ABG
plus.PNG
text.aia

Mrs. Mac

unread,
Feb 13, 2019, 7:19:27 PM2/13/19
to MIT App Inventor Forum
Thanks ABC, can't wait to try this.  I'll let you know if it works.
Reply all
Reply to author
Forward
0 new messages