You are here: PSPad forum > English discussion forum > assignEditorByName problem
Posted by: edo_nick | Date: 2020-01-31 09:21 | IP: IP Logged
Hello,
I have problem with assignEditorByName() in javascript.
If I use it like this
ed = newEditor ();
ed.assignEditorByName("D:\path\Bratislavský.csv");
I get error Microsoft JSkript - chyba počas práce Module:MyModule Line:x Pos:y
Description: Počas operácie automatizácie sa nenašiel názov súboru alebo triedy.
Briefly: filename or classname not found
I have tried check it by assignEditorByIndex and it looks like it cannot compare string with filename right.
for (i = 0; i < 7; i += 1) {
ed.assignEditorByIndex(i);
if (ed.fileName() == "D:\path\Bratislavský.csv") {
logAddLine("Filename [" + i + "]");
exit;
}
logAddLine("Filename [" + ed.fileName() + "]");
}
How to solve it?
Thank you.
Posted by: pspad | Date: 2020-01-31 09:42 | IP: IP Logged
Hello
Assign editor by name means:
file is open in PSPad
into editor object is assigned existing filetab with name from parameter. It's for moment, you know your file is open, but you don't know the tab.
If you want to open file from disk into new editor, use command:
openFile(file_name: string): boolean
ed = newEditor ();
ed.openFile("D:\path\Bratislavský.csv");
Posted by: hhoefling | Date: 2020-01-31 09:54 | IP: IP Logged
By the way
I use JScript in another Context...
..There i must double the "\" -> "\\"
sample:
Quote:this.filename = GetFFPathEx(1) + "\\" + name + ".log";
your can try:
Quote:ed.openFile("D:\\path\\Bratislavský.csv");
--
by HH
Posted by: edo_nick | Date: 2020-01-31 11:51 | IP: IP Logged
Thank you for reply. I use it this way. File is open in PSPad.
I have tried to use openFile with same problem as assignEditorByName
Posted by: edo_nick | Date: 2020-01-31 12:07 | IP: IP Logged
hhoefling:By the wayI use JScript in another Context...
..There i must double the "\" -> "\\"sample:
Quote:this.filename = GetFFPathEx(1) + "\\" + name + ".log";your can try:
Quote:ed.openFile("D:\\path\\Bratislavský.csv");
I have tried it. With plain string it works well. But I need change filename dynamically. When I tried to use concatenation or template literal it went wrong.
ed.assignEditorByName("D:\\path\\" + filename + ".csv");
ed.assignEditorByName("D:\\path\\${filename}.csv");
Posted by: edo_nick | Date: 2020-01-31 15:07 | IP: IP Logged
For today I solve this problem by array of names synchronized with tabs and assigning editor by index.
Posted by: pspad | Date: 2020-01-31 15:27 | IP: IP Logged
Hello
it works for me.
var module_name = "FileOpenJS";
var module_ver = "1.0";
var module_title = "FileOpenJS";
function openFile() {
var obj = newEditor();
var filename = 'testfile';
obj.openFile('I:\\' + filename + '.txt');
}
function Init() {
addMenuItem("Open file test", "", "openFile", "");
}
It works for me include files with diacritical sign, e.g. with
filename = 'červený'
Edited 1 time(s). Last edit at 2020-01-31 15:29 by pspad.
Posted by: hhoefling | Date: 2020-01-31 16:14 | IP: IP Logged
Assigen it to a variable
Quote:var fs="D:\\path\\" + filename + ".csv";
ed.assignEditorByName(fs);
maybe it must be a simple Parameter, no expression
--
by HH
Edited 1 time(s). Last edit at 2020-01-31 16:14 by hhoefling.
Posted by: pspad | Date: 2020-01-31 16:32 | IP: IP Logged
hhoefling:Assigen it to a variableQuote:var fs="D:\\path\\" + filename + ".csv";
ed.assignEditorByName(fs);maybe it must be a simple Parameter, no expression
It's not important. See my example above, what works.
Editor PSPad - freeware editor, © 2001 - 2024 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR