Sorting output of Dir()

New to FreeBASIC? Post your questions here.
Xusinboy Bekchanov
Posts: 880
Joined: Jul 26, 2018 18:28

Re: Sorting output of Dir()

Post by Xusinboy Bekchanov »

dodicat wrote: Apr 12, 2025 8:16 So you are saying that on UEZ's computer, literal strings like "abc" become wstr("abc") after a var, which is not allowed for var.
Not only in UEZ's computer, this happens in all computers if you save a file in Unicode format (UTF8 (BOM), UTF16 (BOM), UTF32 (BOM), ...).
UEZ
Posts: 1079
Joined: May 05, 2017 19:59
Location: Germany

Re: Sorting output of Dir()

Post by UEZ »

Thank you Xusinboy Bekchanov for clarifying this issue.

I need to remember this for the future, that if the code is stored in UTF format, I use Str() or use text format to avoid problems and don't waste time in troubleshooting.
Xusinboy Bekchanov
Posts: 880
Joined: Jul 26, 2018 18:28

Re: Sorting output of Dir()

Post by Xusinboy Bekchanov »

UEZ wrote: Apr 12, 2025 11:35 Thank you Xusinboy Bekchanov for clarifying this issue.

I need to remember this for the future, that if the code is stored in UTF format, I use Str() or use text format to avoid problems and don't waste time in troubleshooting.
On the contrary, I need a unicode string and always include #define UNICODE before #include once "windows.bi". In my case, the Str function is not needed, because all WinAPI functions require WString string.
dodicat
Posts: 8267
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Sorting output of Dir()

Post by dodicat »

But not accepting var s="abc" say should not make "abc" wstr("abc") on some computers, it is surely a bug in this case.
fxm
Moderator
Posts: 12577
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Sorting output of Dir()

Post by fxm »

Code: Select all

Var s1 = "FreeBASIC"        '' ok
Var s2 = Str("FreeBASIC")   '' ok
Var s3 = Wstr("FreeBASIC")  '' error 24: Invalid data types in 'Var s3 = Wstr("FreeBASIC")'
Xusinboy Bekchanov
Posts: 880
Joined: Jul 26, 2018 18:28

Re: Sorting output of Dir()

Post by Xusinboy Bekchanov »

dodicat wrote: Apr 13, 2025 9:05 But not accepting var s="abc" say should not make "abc" wstr("abc") on some computers, it is surely a bug in this case.
At the moment, the compiler has String (a dynamically resizing ANSI string) for ZString, but there is no UnicodeString or UString for WString yet, if this is added, then Var s = "қандай - what" will also be possible.
Xusinboy Bekchanov
Posts: 880
Joined: Jul 26, 2018 18:28

Re: Sorting output of Dir()

Post by Xusinboy Bekchanov »

fxm wrote: Apr 13, 2025 9:21

Code: Select all

Var s1 = "FreeBASIC"        '' ok
Var s2 = Str("FreeBASIC")   '' ok
Var s3 = Wstr("FreeBASIC")  '' error 24: Invalid data types in 'Var s3 = Wstr("FreeBASIC")'
You didn't check, I think, the example Var s1 = "FreeBASIC" with the UTF8 (BOM) file format.
fxm
Moderator
Posts: 12577
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Sorting output of Dir()

Post by fxm »

Xusinboy Bekchanov wrote: Apr 13, 2025 9:47
fxm wrote: Apr 13, 2025 9:21

Code: Select all

Var s1 = "FreeBASIC"        '' ok
Var s2 = Str("FreeBASIC")   '' ok
Var s3 = Wstr("FreeBASIC")  '' error 24: Invalid data types in 'Var s3 = Wstr("FreeBASIC")'
You didn't check, I think, the example Var s1 = "FreeBASIC" with the UTF8 (BOM) file format.
Yes.
dodicat
Posts: 8267
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Sorting output of Dir()

Post by dodicat »

Code: Select all

#print typeof("literal string") 
I get
ZSTRING * 15
Shouldn't all computers get this message (i.e. a zstring) in the comiler message window?
Xusinboy Bekchanov
Posts: 880
Joined: Jul 26, 2018 18:28

Re: Sorting output of Dir()

Post by Xusinboy Bekchanov »

dodicat wrote: Apr 14, 2025 10:17

Code: Select all

#print typeof("literal string") 
I get
ZSTRING * 15
Shouldn't all computers get this message (i.e. a zstring) in the comiler message window?
If you make the source file format ANSI then: ZSTRING * 15
If you make the source file format UTF8 (BOM) then: WSTRING * 15
dodicat
Posts: 8267
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Sorting output of Dir()

Post by dodicat »

I added a bom, should be wstring now for literal strings under var, with the compile error at line 3 accordingly.
Thanks for explaining - everybody.


Code: Select all



var k="hi"
print k
 #print typeof("literal string")
 Sleep
sleep 
Xusinboy Bekchanov
Posts: 880
Joined: Jul 26, 2018 18:28

Re: Sorting output of Dir()

Post by Xusinboy Bekchanov »

dodicat wrote: Apr 15, 2025 8:05 I added a bom, should be wstring now for literal strings under var, with the compile error at line 3 accordingly.
Thanks for explaining - everybody.


Code: Select all



var k="hi"
print k
 #print typeof("literal string")
 Sleep
sleep 
Maybe your IDE does not support UTF8 (BOM), try compiling using command line.
dodicat
Posts: 8267
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Sorting output of Dir()

Post by dodicat »

By adding the BOM to the .bas file, as I have done, the file is UTF8 (BOM).
I can compile via command line or fbide (my choice of ide), and a literal string will be a wstring * (some size).
Thus It will error on var s="some string".
So as UEZ says, there is a bug, (an inconsistency under var).
Or maybe you get a different compile error?
I get
FBIDETEMP.bas(3) error 24: Invalid data types
fxm
Moderator
Posts: 12577
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Sorting output of Dir()

Post by fxm »

This is not a bug but rather a deficiency well-specified in the documentation:
Note: Wstring is not supported with Var, due to the fact that there is no var-len Wstring type. This isn't likely to change, due to the complexities involved with handling Unicode.

Otherwise this below compiles:

Code: Select all



var k=Str("hi")
print k
 #print typeof("literal string")
sleep

Code: Select all

hi

Code: Select all

WSTRING * 15
dodicat
Posts: 8267
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Sorting output of Dir()

Post by dodicat »

I think that you still might use fbide fxm, with the console open (you don't usually sleep at the end)

What does UEZ use these days, to automatically load .bas files as a utf-8 with BOM?
I think that automatically making all literal strings wstring might produce some more strange results. Who knows?
Post Reply