How could I get an empty array?
The array()-function doesn’t work without without any parameter.
ReDim does only work on array that is not Nil.
Here is some Code:
Dim tmpObjectNames() As String = RaiseEvent getObjects
If tmpObjectNames = Nil Then tmpObjectNames = array()
If the Event “getObjects” is not implemented, tmpObjectNames is Nil. In this case it should be set to an empty array. So do I really have to do something like:
If tmpObjectNames = Nil Then
Dim bla() as String
tmpObjectNames = bla
EndIf
I’m not sure if I understand your question correctly.
Initiate an empty array with Var arsContent() As String. Alternatively, you can also write Var arsContent(-1) As String. Does it help? A nil array = empty array in my eyes.
Yes, that’ll work. It’s just not pretty. I like nice code.
Thanks for the code.
Okay, we agree on that. I was hoping I had overlooked something. It would be too easy if array() simply worked without parameters. But let’s be honest, it’s a Xojo feature (not a bug) that I just don’t understand and after all, there is a workaround…
I don’t need that, and I don’t want that. There are simply situations where Xojo gives me that back.
If it is Nil you could not do .count()… But even if you could, that qould not change anything, because there is no problem finding out if the array is nil. The problem is to return it back to a functioning state.
Yes, thank you. Now we are at the “what workarounds can we find” level. To be honest, I can think of a few variants myself. I just don’t like workarounds and I was (once again) hoping that “it must work out of the box”
But my question was how to get an empty array in a “proper” way without having to create one
It has simply become completely normal here in the forum for some people to immediately help with a workaround for every problem.
That’s the real problem, you create workarounds all day long.
But there would be no need for a workaround if (as in other languages I know) you could simply make a variable = array().
My hope was that someone would say: Sure it works, you just overlooked the function XYZ.
I am very pleased that you wanted to help! It’s just a difference whether I’m looking for a workaround to be able to continue working, or whether I just wanted confirmation that I haven’t overlooked anything