Data conversion array->Object for excel

This forum is meant for questions and discussions about the X# language and tools
User avatar
Chris
Posts: 4584
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Data conversion array->Object for excel

Post 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)}
.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
alex_schmitt
Posts: 85
Joined: Wed Jan 23, 2019 7:54 pm
Location: Germany

Data conversion array->Object for excel

Post 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
User avatar
Chris
Posts: 4584
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Data conversion array->Object for excel

Post 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 ;)

.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
FFF
Posts: 1532
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Data conversion array->Object for excel

Post by FFF »

That I call a short, clear, concise and understandable explanation!
Thx for that.
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
alex_schmitt
Posts: 85
Joined: Wed Jan 23, 2019 7:54 pm
Location: Germany

Data conversion array->Object for excel

Post by alex_schmitt »

@Chris: Well, yes ;) But as I was always instantiating arrays with ArrayNew() I was not able to do this transfer ;)
Post Reply