How might I associate a label with a checkbox?

This can get the selected checkbox text:

How well stocked is your JSON toolbox?
Study JSON.org

Well, that was depressing! The last thing I want to do at age 65 while creating an app is to learn another programming language. When I see JSON, I think of the horror movie.

I was hoping I could use a "Join" block and somehow associate every checkbox with a specific label using the MIT Visual block code. It seems like something that many before me have done, as it practically allows one to pull up data based on a check box selection.

I will keep on playing and searching the Internet, as the likelihood of my stumbling across the answer is higher than learning JSON such that I can apply it in this specific situation.

1 Like

JSON is just a text representation of dictionaries and lists.

If you post your exported .aia file, it would be easier to show how to use them in context.

Greetings, Here is my .ala file. I simplified it here so I can better understand the functions. In doing so, I accidentally changed something that no longer allows me to uncheck a checkbox without an error but I am not concerned with that at this point.

One burner question is why I could use the join commands to add a carriage return but when I try to use "Replace All Text" to eliminate the brackets and quotation marks, I can not remove them. Where should these commands be placed to do what I seek?

You can see that I have simply created a Label45 onto which I placed a humidity percentage. You can also see that I placed it in such a way that it shows up attached to every checked box when they are selected. The screenshot shows a previous label (Temp>ble) but the name is immaterial. What I wish to do is to set up this program such that every checkbox has a label "attached" or assigned to it in such a way that when I call up (by checking) any parameters, the program places the label contents after the checkbox text on the selection page. The label contains the result of the necessary calculations.

I am further confused by seeing that people create lists with items and tags, such that calling up a tag displays the item's contents. I want to transfer that logic to checkboxes but my mental acuity is limited to trying to express my desires succinctly here.

The attached .ala allows one to check some boxes and then have their contents displayed on another virtual screen. Unchecking a box creates a false error right now but that is a problem with me duplicating my program for review that doesn't present itself in my full-out file. I will eventually add a "Uncheck All" button as a finishing touch.

I would love to check a number of boxes, then hit "Get Selection" and have the checkbox name appear, followed by the label contents, and a carriage return to the next data point.

As I can sometimes look at an answer and not immediately recognize it for what it is, I would be happy with a link that describes what I am trying to achieve. I am simply overwhelmed by the number of different ways any one objective may be achieved. Thank you, again, for your patience and expertise.

Community_Support.aia (3.5 MB)



Do you also have a short version of that?
Sorry, too long, I didn't read...

But as far as t I can see, you do not know how to work with lists

Taifun

Here's a sample using a YAML display, to avoid the tedium of laying out pairs of Labels and checkboxes.

It works entirely off the text in the CheckBoxes, and off a dictionary fed from procedures to load its data from your favorite data source. I used a test procedure to call a couple such procedures to get some sample data into the dictionary, and from there to the YAML display.
image

(I left your 35.6% in).

Sample run:
sample run

The check box events aren't needed for this approach.
All the work happens in that button click, using two value procedures using the new advanced list blocks.


Community_Support (1).aia (3.5 MB)

I only did a couple of data saving procedures. They are easy to propagate by duplication, renaming, and switching checkbox.

1 Like

Wow, I apologize for trying to explain myself. Your comments are a little cheeky for a "Power User" but maybe I caught you at a bad time or you are simply tired of my line of query? Either way, I appreciate the links and your recognition of the obvious - I do NOT know how to work with lists, or a thousand other aspects of AI2.

I am trying hard to learn but my life is not set up for learning by trial and error right now. I learn and move ahead best by studying a functional example of something close to what I am seeking to accomplish. ABG went above and beyond and gave me something to sink my teeth into and play with so no harm, no foul.

OMG! Thank you a thousand times. You must be an educator with your over-the-top clarity and detailed explanation. This is exactly what I have been trying to accomplish (in a most unskillful manner as noted by Talfun;)-. There is so much I do not yet know about AI2 but, in the 2 months that I have been immersed, I have gained skills and confidence thanks to community supporters such as yourself. Words cannot properly express my gratitude.

That incorporated wonderfully into my larger file. My only burning question is where does the data go (how do I make a dictionary)? I tried something like this:

but that didn't replace the zeros with the text strings. I tried several names but to no avail. Can you throw me another bone? Thank you so much

When you posted an .aia you left out the data feed from BLE part.

Otherwise, I could have shown how to call those extra little procedures "save_..." that feed into the global dictionary I included with my sample.

Your global_readings_dictionary is not a dictionary.
A dictionary is a place where you can look things up by name, not by position like a list.
(Look in the Oxford English Dictionary in the reference section of your local library under the word 'Oops'. There's probably a picture of a computer programmer there.)

See MIT App Inventor Dictionary Blocks for samples and explanations.

Post your complete .aia with the BLE Received events, so I can show you how to hook up the data feeds into my dictionary.

1 Like

Hi Baran

Simple Question. What is supposed to happen when a check-box is checked? Also when unchecked?

Greetings,
Fair enough, I make a partial post, I get a partial answer - the best you can do based on what I have provided. In the attached file, I have hidden the five labels for temperature, humidity, and pressure. Perhaps you could demonstrate with the humidity label, as it requires no formula or choice between Imperial or Metric.
Thank you, again, for your guidance.

Community_Support (2).aia (3.5 MB)

Hi Chris,

The check boxes are just a simple and convenient way for someone to select only the data they wish to view. At some point, if I do not go crazy creating the app, I will have a multiplicity of data points available. The check boxes allow a user to customize the data s/he receives - why scan through 20+ data points when you are interested in only five of them.

The concept is that a quantity of check boxes are checked and, when the "fetch" data button is pressed, only the checked boxes appear with the requisite attached data.

I like the layout of multiple check boxes as opposed to a scroll list. It is more a matter of aesthetics. ABG had a novel (to me) solution that I never would have dreamed existed - creating a dictionary with data that is accessed with the associated checkboxes.

You may remember, about 8 weeks ago, I was struggling with UUIDs and thinking I would be using a UUID for every data point. Then, I realized that I can do the calculations in the app and send much less data.

So . . . checking or unchecking simply adds the check box event to the dictionary where I should have matching data available.

Your checkbox texts don't match up to your Labels anywhere except for humidity.

So all I could do was grab the humidity as it comes in from BLE:


Community_Support2 (1).aia (3.5 MB)

That makes sense. Everything else needs specificity (Celsius or Imperial) or a formula. Humidity is about the only copy-and-paste reading and all I need is one example to go to town. And I'm off . . .

1 Like

Wow, after several days of (mental) anguish trying to associate a checkbox with external content, your example brought tears to my eyes . . . well, for a few seconds;). I now get to be a busy beaver and transcribe some formulas from C++ to Visual math blocks. At least I am back on solid ground in both technique and content. Thank you so much for your time and experience (and solutions)!.

OK, that sense of relief was short-lived. I have examined your blocks and I just do not see where Humidity_ble.Text or fHumidity is handed off to be processed and ultimately wind up as a result of the CheckBox_9_Humidity being checked. How does the humidity measurement find its way into the global_readings_dictionary?

If you could tell me where the magic happens, I would be most grateful.

Start from the BLE.FloatsReceived event block, which I posted above. It has 3 sections, one per reading type. In the humidity section, there is an extra block I inserted, to call my new save_Humidity procedure and pass it the local variable fHumidity through the lazily named parameter x.

I included the save_Humidity procedure, nice and big for easy reading.
It receives a parameter, lazily named x, which should contain the fHumidity value from the call statement earlier. It saves that fHumidity value into the aforementioned global dictionary named readings_dictionary, which is still wired into that Get_Selectrion(sic) button click event, under the key named in the humidity checkbox.

By the way, if you want the numbers in the YAML display to update continuously as data arrives from BLE, you would have to duplicate (via a new procedure) that code from the Get_Selectrion Click event in the BLE data arrival event. Otherwise, the newly arrived data would just sit there in the dictionary.

Thank you for spoon-feeding me this information. I swear I will embody it. I don't know if it is a random occurrence of senior moments or just latent attention-deficit disorder but I just didn't see what you are kindly pointing out here for me. Thank you, again, for your patience.