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

This forum is meant for questions and discussions about the X# language and tools
Post Reply
ic2
Posts: 1798
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

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

Post 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
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

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

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
ic2
Posts: 1798
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

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

Post 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
FFF
Posts: 1522
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

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

Post 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 ;)
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

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

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply