Is WebListBox.CellValueAt String or Variant?

After I tried to open an old web-project with newer Xojo (web1->web2) I saw the documentation:

CellValueAt (Row As Integer, Column As Integer) As String

While Xojo itself mentioned:

(2, 60) WebListBox.CellValueAt(Row as Integer, Column as Integer) As Variant

Is that a problem with the docs?

Marius

I think CellValueAt is overloaded:

Function CellValueAt(Row as Integer, Column as Integer) As Variant
Sub CellValueAt(Row as Integer, Column as Integer, Assigns Value as String)
Sub CellValueAt(Row as Integer, Column as Integer, Assigns Value as WebListboxCellRenderer)

Overloaded by MBS-Plugins?
So your plugins change the way that works like it is documented??? :face_with_raised_eyebrow:

If Xojo is using String for Cell-Fields (everywhere else), why should that be changed to variant?
If CellValueAt returns Variant, shouldn’t there be Autocomplete for “.StringValue”, “.IntegerValue” etc?

Not overloaded by plugin although a method in a module (plugin or project) can add something there.

It returns a variant. The return value can either be a string or a custom cell instance.

Is it possible to read the content from such a custom cell instance. This might solve my problem to read the format of the cell.

Sure. If you convert the value to a string, it’ll be a serialized json representation of the cell.

This worked with 2021r1.1. But with the later versions I get an exception when I try to read the value.

In this example the cell is a styled cell

Dim T2 as Variant
Dim AktGesamt As Dictionary

T2 = ListBox1.CellValueAt( 0,1)
AktGesamt = JSONItem( T2)

The assignment to T2 works. But as soon as I try to read the content I get an exception. If T2 would be of type String and contains the JSON it should work. But I have no idea to cast the variable so I could decode it.

The code you’ve got there is probably going to throw an IllegalCastException I think. You really ought to be checking if T2 IsA JSONItem before casting it like that.

Hello,

this example should be as simple as possible. So I didn’t add this part of code.

I investigated a little bit.

The problem seems to be that CellValueAt return a type 9 (Object) and JSONItem need a String value. So it raises a TypeMismatchException. Maybe a change of the return type to String would solve the problem.

BTW: 2021R1.1 returns a type String.

Did you check to see if that object IsA JSONItem?

To help make that more clear:
https://documentation.xojo.com/api/language/isa.html#isa

Hello,

I added the if statement. but the return value is not an JSONItem.

T1 = ListBox1.CellValueAt( 0,0)
T2 = ListBox1.CellValueAt( 0,1)
aktType = T2.Type '8 with 2021R1.1 and 9 with 2022R1
If T2 IsA JSONItem Then
AktWerte = ParseJSON( T2)
End If

I loaded my example project to

https://beta.mcrichter.de/TestGetCellValue.zip

I hope this makes all a little bit more clear.

ParseJSON(variable) and JSONItem(variable) do different things.

ParseJSON is a function that accepts a string and returns a JSONItem. Documentation Link
JSONItem(variable) is casting the object to a JSONItem. Documentation Link

In your example project you’re checking T2, but it’s not a JSONItem so the code is correctly skipping that part. What exactly are you trying to do? Tell us your goal, and we may be able to help you find the best direction.

I wants to parse the JSON to get for example the value of the cell.

JSONItem(variable) has no parameter, beside a string one. So I can’t enter the returned JSON. And because the Return value of CellValueAt is Object I can’ cast it to a JSON.

I see no way in Xojo for a forced casting as in other languages.

I can’t see what this Problem hast to do with a json-item. But it seems to be a Problem.
WebListbox.CellValueAt should NOT return a WebListBoxStyleRenderer-Object (where the value is NOT accessible), it should return the CellValue.
I can’t see why this should be a question of json. Even if this object might be json internally.

When I bring all informations together it is possible that only the type of the return value is wrong. With 2021r1.1 it was String and now Object.

Greg, can you look if this is the problem? And when yes, can you change it.

Your example project did not have JSON in the cell, and a WebListbox cell is a really awkward place to find JSON strings – so I was not certain what you wanted.

To turn a string into a JSONItem you need to load the string in somehow, you can’t cast the string to JSONItem (though that would be cool). There are two ways to do so. You can create the JSONItem and then Load the string in or you can pass the string to the Constructor.

Passing a string to the constructor of JSONItem looks very similar to casting it, however you’ll notice the keyword “new” is what constructs the item calling the constructor. This is different from casting an object.

Edit: And, of course, if you’re getting a WebListboxCellRenderer back, you’ll need to build your own system of getting the “value” – whatever that may be for your cell.