STRING Function - Type mismatch

Windows specific questions.
Post Reply
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

STRING Function - Type mismatch

Post by Josep Roca »

I have noticed that if this code

Code: Select all

DIM s AS STRING
s = string(10, "a")
print s
is saved in a file with a UTF-8 or UTF-16 BOM it gives error 57 - Type mismatch at parameter 2 when I try to compile it.

Works if I use

Code: Select all

DIM s AS STRING
DIM ch AS STRING = "a"
s = string(10, ch)
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: STRING Function - Type mismatch

Post by counting_pine »

(YMMV, but for easy UTF-8 testing, the below code contains a byte-order mark on the first line, which should save OK under the Latin (1252) codepage):

Code: Select all


DIM s AS STRING
#print typeof("a")
s = string(10, "a")
print s
Anyway.. I think what's happening is:
- String literals in Unicode program files are stored as WSTRINGs (as reported by the typeof() line in the above program)
- STRING() is a quirk-function - i.e. the parsing and resulting function call is handled specially by the compiler - and the compiler's routines for STRING() don't include support for WSTRINGs in the second parameter

The latter effect can be seen in a plain ASCII file using WSTR() to force a WSTRING constant:

Code: Select all

const w = wstr("a")
print string(10, w)
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: STRING Function - Type mismatch

Post by Josep Roca »

Thank you for the explanation.
Post Reply