mminnder
12 years agoOccasional Contributor
Text Streams and Troubles
So, I'm currently making a program that checks a json returned from a web service against a local json, and if the local doesn't exist, than it should create it using the return. When I do this I want it to return the info inside this newly created json to the previous function.
IE. return text;
Basically:
If (file doesn't exist)
{
var createObject = new ActiveXObject("Scripting.FileSystemObject");
var textDoc = createObject.CreateTextFile("./JSON/Returns/" + key + ".txt", 1);
textDoc.close();
var reopenedTextDoc = OpenTextFile("./JSON/Returns/" + key + ".txt", 1);
var text = reopenedTextDoc.ReadAll();
}
it breaks on var reopenedTextDoc = OpenTextFile("./JSON/Returns/" + key + ".txt", 1);
Error is : Object Expected
I'm assuming that the issue is that it's not done creating the text file by the time it tries to open it, is there any way to say "if this file is done being created, open it"?
IE. return text;
Basically:
If (file doesn't exist)
{
var createObject = new ActiveXObject("Scripting.FileSystemObject");
var textDoc = createObject.CreateTextFile("./JSON/Returns/" + key + ".txt", 1);
textDoc.close();
var reopenedTextDoc = OpenTextFile("./JSON/Returns/" + key + ".txt", 1);
var text = reopenedTextDoc.ReadAll();
}
it breaks on var reopenedTextDoc = OpenTextFile("./JSON/Returns/" + key + ".txt", 1);
Error is : Object Expected
I'm assuming that the issue is that it's not done creating the text file by the time it tries to open it, is there any way to say "if this file is done being created, open it"?
- Hi Mike, no, you do not have to replace the single "\" s returned by Project.Path
JScript uses the "\" character to escape special characters in a literal string, e.g. \t (tab) and \r (carriage return), therefore, "\\" is simply the escape sequence for "\"
E.g. the literal string "C:\\MyFiles\\DemoFile.txt" evaluates to "C:\MyFiles\DemoFile.txt"
For the case with Project.Path as it not a literal string, the escape sequence is not required, e.g.
Project.Path + "\\JSON\\Returns\\test.txt" would evaluate to
"C:\Users\Phil\Documents\TestComplete 9 Projects\TestProject1\JSON\Returns\test.txt"
depending.of course, the actual path to the Project
Phil