xsharp.eu • Error XS0023 Operator '+' cannot be applied to operand of type 'string'
Page 1 of 1

Error XS0023 Operator '+' cannot be applied to operand of type 'string'

Posted: Tue Mar 10, 2020 5:55 pm
by ic2
Code:

cDBFFields += "`"+(cFieldName)+"` TEXT NULL "+ e","

Error:

Error XS0023 Operator '+' cannot be applied to operand of type 'string'

Why is this not allowed? It is code to construct an SQL statement. Currently it seems the compiler errors only occurs in the statements within a 2nd DO CASE, no error (yet?) after the CASE .. INSERT but error XS00023 for all following cDBFFields += statementof CASE.. Create

Dick

DO CASE

CASE Type="INSERT"
cDBFFields += cFieldquot+cFieldName+cFieldquot +",

CASE cType="CREATE"
DO CASE
CASE cDataType="C"
IF nFieldLen>255
cDBFFields += "`"+(cFieldName)+"` TEXT NULL "+ e","
ELSE
cDBFFields += "`"+(cFieldName)+"` VARCHAR("+NTrim(nFieldLen) +") NULL "+e","
ENDIF
CASE cDataType="M"
cDBFFields += "`"+(cFieldName)+"` TEXT NULL "+ e","
CASE cDataType="L"
cDBFFields += "`"+(cFieldName)+"` CHAR(1) NULL "+ e"," // For logic we only store Y or N

Error XS0023 Operator '+' cannot be applied to operand of type 'string'

Posted: Tue Mar 10, 2020 7:50 pm
by robert
Dick,
it is difficult to see what exactly causes the problem from the code you have included.
My first impression is that you are missing an end quote in the line after the "INSERT" case.
I also don't understand why you have separate +e"," in all cases, where you could have included the comma in the string before the + , but that is maybe not relevant. And why do you have cFieldName between parentheses ?
Can you upload the whole function/method ?

Robert

Error XS0023 Operator '+' cannot be applied to operand of type 'string'

Posted: Tue Mar 10, 2020 8:05 pm
by ic2
Hello Robert,

The quote was lost in copying it seems. And the +e is also done by the forum editor, it is a square opening bracket, a comma and a square closing bracket. Like this (hopes it works this time by adding some spaces...)

cDBFFields += "`"+cFieldName+"` TEXT NULL "+ [ , ]

But currently the error seems gone. I did also get:

Error XS0118 'cFieldName' is a variable but is used like a type.

And I thought, just like you, why do I have parentheses around the name? It works well without it (although in VO it also works with them).
I've removed them and now both errors seem gone.

Thanks!

Dick

Error XS0023 Operator '+' cannot be applied to operand of type 'string'

Posted: Tue Mar 10, 2020 8:14 pm
by FFF
Dick,
for toename van kennis, would you post the "e" line and apply the "" bracket around?

ARGH: the empty line should be simply code /code, contained in brackets...
Life was easier in NG times ;)

Error XS0023 Operator '+' cannot be applied to operand of type 'string'

Posted: Tue Mar 10, 2020 8:18 pm
by robert
Dick,

That explains the problem:

The compiler interprets your code
cDBFFields += "`"+(cFieldName)+"` TEXT NULL "+ e","

as
<string> += <string> + <Cast to cFieldName> + <string> + <string>

The +<string> after the cast is a 'unary +' like in
? +10
and there is no 'unary +' operator for string (but there is for numbers)

So the problem is that the parenthesized expression is seen as a cast.

We actually already have a ticket and test for this:

https://github.com/X-Sharp/XSharpDev/bl ... g/C708.prg

Robert