Null and nan on my counting app

Thanks for the help. As of now my app works great except one little bug. When I start my app for the first time, where the amount goes I get a null. If I hit a button I get a nan. It’s not a big deal because the app is just for me and if I hit reset it works fine. Although it would be nice to fix it. Here are screenshots.




When you use Stored variables, you have to give them a starting value.

In your screen opens blocks, do this:

If Stored variable = null
…Set Stored variable to 0.

1 Like

@tatiang I’m not home, but I’ll try it when I get home. If I set it at zero, do I do it in the block when the screen opens? If so will it be zero every time I open the app? I want every time the app opens for it to pick up where it left off.

1 Like

The reason for the conditional IF is that you only set the variable to 0 if it hasn’t been set before. Once you set the variable to 0 it is no longer null. And because it’s a Stored variable, it’s saved to the device. So it gets set to 0 once and then whatever value you change that variable to, it will keep that value and the IF block will not be true ever again.

1 Like

@tatiang Sorry to be a bother. I was confused how to use the IF conditional that you were talking about. Is the top block of the screenshot right or am I way off?

1 Like

The blocks in the screen Opens are not correct.

You need to check the variable first before assigning it to any other component.

See this simple example
image

2 Likes

@muneer thank you for trying to help me. I tried the following (screenshot) but I still get null the first time I open the new screen. I guess I’ll just live with it. It’s not a big deal, it’s just an app for myself. I was hoping I could fix it, but unfortunately I’m not the brightest when it comes to this stuff. Thank you very much.

1 Like

I can see from the image
image

You are testing Amount 5 instead of the actual stored variable Running Total 5. This is the mistake.

Just follow the same example I showed you.

@muneer thank you for being patient with me. I’m not always so bright. I misread your example and when I fixed it like you said, it works perfectly. Thank you. I’m done with my app now so I should be a bother anymore (for the time being at least). Thanks

1 Like

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