Oh, so you think it’ll retain it’s “type” upon assignment to the JSON? Cool if it does. I’ll give that a try.
Saves a lot of “select cases” and conversions.
Yes, but Variants can take any data type. A Variant doesn’t turn into a datatype when you assign it a value, rather it holds data of that type. As long as we’re talking about basic types a Variant will convert its value to the type of the variable it is assigned to:
dim i as Integer = 3
dim v as Variant = i
dim s as String = v // s = "3"
// or
dim b as Boolean = true
dim v as Variant = b
dim i as Integer = v // i = 1
dim s as String = v //s = "true"
You’re missing the part about editing the JSON using a ListBox. All ListBox cells are strings. So, I guess I could use a columnTag to keep track of the type of data.
Sub Parse(Extends myVariant As Variant, newValue As Variant) As Variant
Select Case myVariant.Type
Case Variant.TypeInteger
return newValue.IntegerValue
Case Variant.TypeString
return newValue.StringValue
Case ...
...
else
return newValue // just to be sure you didn't miss a type...
End Select
End Sub
And then
myVariant = myVariant.Parse(myStringValue)
Or to make the method more generic:
Sub Parse(data As Variant, intoType As Integer) As Variant
Select Case intoType
Case Variant.TypeInteger
return data.IntegerValue
...
End Select
End Sub
...
myVariant = Parse(myStringValue, Variant.TypeInteger)