Sparx Systems Forum
Enterprise Architect => Bugs and Issues => Topic started by: nilspc on January 02, 2023, 09:08:53 pm
-
Hi,
I'm importing files in UTF-8 format and Scripting.FileSystemObject apparently does not support UTF-8. When importing nordic characters are randomly corrupted so I'm testing using ADODB.Stream instead.
The code work in JScript but NOT in JavaScript. The JavaScript code runs with no errors but the file appears to be empty.
Can anyone explain why it works in JScript but not in JavaScript? se the code below
Or rather, how I can get it to work in JavaScript (prefer JavaScript because of the built-in debugger)
Running 16.1
Regards
Nils
JavaScript
var fileName;
var file;
fileName = "c:/temp/storutftestfil.csv";
var stream = new COMObject("ADODB.Stream");
stream.Type = 2 // text data (as apposed to binary data)
stream.Charset = "utf-8";
stream.LineSeparator = -1; // carriage return line feed
stream.Open();
stream.LoadFromFile = fileName;
file = stream.ReadText();
Session.Output("Stream : " + stream.Size);
Session.Output("Line : " + file);
stream.Close();
JScript
var fileName;
var file;
fileName = "c:/temp/storutftestfil.csv";
var stream = new ActiveXObject("ADODB.Stream");
stream.Type = 2 // text data (as apposed to binary data)
stream.Charset = "utf-8";
stream.LineSeparator = -1; // carriage return line feed
stream.Open();
stream.LoadFromFile = fileName;
file = stream.ReadText();
Session.Output("Stream : " + stream.Size);
Session.Output("Line : " + file);
stream.Close();
-
The post is old so I think the answer is no longer expected but if anyone goes through it there will be the answer.
I came across the same thing.
The issue is that the LoadFromFile is not an attribut but a function.
Here is the correction:
var fileName;
var file;
fileName = "c:/temp/storutftestfil.csv";
var stream = new COMObject("ADODB.Stream");
stream.Type = 2 // text data (as apposed to binary data)
stream.Charset = "utf-8";
stream.LineSeparator = -1; // carriage return line feed
stream.Open();
stream.LoadFromFile(fileName);
file = stream.ReadText();
Session.Output("Stream : " + stream.Size);
Session.Output("Line : " + file);
stream.Close();
-
Hi,
Thank you ;D
Seems to work
Regards
Nils