xsharp.eu • Data conversion array->Object for excel - Page 2
Page 2 of 2

Data conversion array->Object for excel

Posted: Tue Jun 21, 2022 11:37 pm
by Chris
HI Alex,

You can't just cast a OBJECT[] to a STRING[], those are not compatible. Instead, you need to write code that enumerates the OBJECT[] returned by _ArrayToObjectArray() and put each item to the STRING[]. If this still doesn't work, please post a complete code snippet so we can have a look.

About your other function, the correct way to instantiate a STRING[] is this:

Code: Select all

output:=System.String[]{ALen(input)}
.

Data conversion array->Object for excel

Posted: Wed Jun 22, 2022 7:28 pm
by alex_schmitt
Hi Chris,

Thanks, that was doing the trick!

Then this is the successful solution

Code: Select all

FUNCTION XSStringArray2CSStringArray(input as ARRAY) AS System.String[]

LOCAL output as System.String[]
local i as int

output:=System.String[]{ALen(input)}

for i:=1 to ALen(input)
	output[i]:=(System.String)input[i]
next

RETURN output
I have to admit I would not have guessed that the syntax for instantiating an array of string objects is being instantiated that way
but maybe I didn't dig deep enough in the help docs.

Best,
Alex

Data conversion array->Object for excel

Posted: Wed Jun 22, 2022 10:49 pm
by Chris
Hi Alex,

Well, all types instantiate with TypeName{}. Since the type name here is STRING[], then instantiating it with STRING[]{} sort of makes sense ;)

.

Data conversion array->Object for excel

Posted: Thu Jun 23, 2022 11:16 am
by FFF
That I call a short, clear, concise and understandable explanation!
Thx for that.

Data conversion array->Object for excel

Posted: Thu Jun 23, 2022 8:57 pm
by alex_schmitt
@Chris: Well, yes ;) But as I was always instantiating arrays with ArrayNew() I was not able to do this transfer ;)