Continuing to Get Error _____ when we try to add things to tinyDB and retrieve things to ListView

Hi all,

I'm working to create an app that uses TinyDB, utilizing Web1.JsonTextDecode and such.

The code is supposed to:

  1. Add a time frame
  • take the text from a textbox (Timeframe)
  • take the selected date for the DatePicker (startDate)
  • take the selected date from another DatePicker (endDate)

...and save this to TinyDB and display them to a ListView ("ListView_Timeframes").

  1. Delete a Selected Timeframe

HOWEVER, I am getting the following error upon booting in AI companion: "the The operation Elements cannot accept the arguments: , [""]"

It also displays this error when "add timeframe" button is selected (and the fields are populated).

Here is the pseudocode I am working on:

// 1. this is a nav button that takes you to a previous menu

when Be_Button5_BackToMain.Click do
open another screen screenname to (BE_MENU)

// 2. Here, I initialize several variables

initialize global timeframes to ""
initialize global selectedTimeframe to ""
initialize global tfDateStart to ""
initialize global tfDateEnd to ""

// 3. Screen Initialization

when BE_Define_a_Timeframe.Initialize do
set global timeframes to
call Web1.JsonTextDecode jsonText
call TinyDB1.GetValue
tag "timeframes"
valueIfTagNotThere ""
set ListView_Timeframes.Elements to
get global timeframes
set labeldebug.Text to
get global timeframes

// 4. When-Do once dates are picked in datepicker

when DatePicker_tf_start.AfterDateSet
set global_tfDateStart to
DatePicker_tf_start.Instant
when DatePicker_tf_end.AfterDateSet
set global_tfDateEnd to
DatePicker_tf_end.Instant

// 5. When-Do on Add Timeframe Button Being Clicked (3 Things that need to happen)

when Button_AddTF.Click do
add items to list
make a list
TextBox_tf_Name.Text
get global tfDateStart
get global tfDateEnd
call TinyDB1.StoreValue
tag "timeframes"
valueToStore
call Web1.JsonObjectEncode
get global timeframes
set ListView_Timeframes.Elements to
call Web1.JsonTextDecode jsonText
get global timeframes

// 5B. Here is some code we wrote that I don't quite remember the purpose of

when ListView_Timeframes.AfterPicking do
set global selectedTimeframe to
ListView_Timeframe.Selection

// 6. When-Do on Delete Timeframe Button Being Clicked (3 Things That Need to Happen)

when Button_DeleteTF.Click do

remove list item 
list get global timeframes 
index get global selectedTimeframe
call TinyDB1.StoreValue 
tag "timeframes" 
valueToStore
    call Web1.JsonObjectEncode jsonObject
	get global timeframes
set ListView_Timeframes.Elements to
call Web1.JsonTextDecode jsonText
	get global timeframes

And here are some screen shots:

image


Thanks in advance for any help!

Use the companion app and Do it to debug your blocks, see also tip 4 here App Inventor: How to Learn | Pura Vida Apps
see also Live Development, Testing, and Debugging Tools

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

the Elements property expects a list

also currently you are storing instants in the list

let me suggest you to convert these instants into milliseconds and store these

please provide screenshots of your blocks... pseudo code does not help very much and is hard to read...

Taifun

Thanks. Let me wrestle with your response and your markups of my blocks.

Blockquote please provide screenshots of your blocks... pseudo code does not help very much and is hard to read...

I don't understand. I did post all my blocks.

You know TinyDB can store dictionaries and lists directly, right?

There's no need to convert them back and forth to JSON for storage in TinyDB.

I have since learned that, yes. Thanks for lending a hand :slight_smile:

Here is my work since yesterday if anyone cares to help.

I am still getting the same error. Here are my blocks:

image

image

image

Thanks in advance for any help.

Clear TinyDB abd restart testing
And

And if you still have issues, post a screenshot of the error message

Taifun

Also, understand the difference between SelectionIndex and Selection, if you need an index for a list block.

Did you lose a socket from your Add Items to List block?

It needs both a socket to say which list is getting the additional item, and another socket for the item that is being added.

In the case of the three column table in global timeframes, the item to be added is a list of (name, start, end), an additional row for that two dimensional table.

I'm not sure how to clear TInyDB.

I don't see the milliseconds option. I only see these:

image

I'll try that. Thanks.

Let's see if I can fix that. Thanks.

Use the TinyDB.ClearAll method

The clock component offers rhe GetMillis method to convert an instant into milliseconds

Taifun

I don't mean to be flippant because you're being so helpful. But I don't even know what you're talking about with regards to a clock component.

Extra info: I don't really need milliseconds or minutes or even hours for this area of the app I am trying to build. I simply need days.

I need a user to a) pick a name for a time frame (eg. "End of Year") , pick a start date (eg 2024-08-15) and an end date (eg 2024-12-31).

I'm struggling with how difficult is to pick beginning and ending dates.

Thank you again.

The Clock component is in the Sensors Drawer in the Designer.

It has all the date math and date formatting blocks.

If all you need is dates, use the Date Picker component.

However, to format the chosen date(s) into an exact format, you will probably need the Clock component's blocks, unless you want to play with adding leading zeroes to days and month numbers.

P.S. Here is a trick formula to get a yyyyMMdd value from a Date Picker, suitable for before/after comparisons

Haha!!!! It's working! I couldn't have done it without you guys.

Here are the working code blocks for anyone who was following this thread. It isn't perfect, but it works:

image

image

image

image

image

Thanks again! I'll now takw some time ti analyze this success, and then on to the next screen!

Congratulations!

I notice you are using format yyy instead of yyyy for your years.

What does that end up looking like?

Hi. I actually spotted that error after posting the screenshot.

However, I went back and changed it to yyy after you posted to see what was the result, and it still displays yyyy. I'm not sure why.

Thanks again for your help.

1 Like

Here you go:

lowercase y and uppercase Y return the same result

1 Like

Yeah, I'm not sure why that is.