Lint Integer LautFileSystemObject :'Windows Script Host Object Model'.FileSystemObject LautFolder :'Windows Script Host Object Model'.Folder LautFolder2 :'Windows Script Host Object Model'.Folder LautFolders :'Windows Script Host Object Model'.Folders
CREATE(LautFileSystemObject); LautFolder := LautFileSystemObject.GetFolder('c:\temp'); LautFolders := LautFolder.SubFolders(); FOR Lint := 1 TO LautFolders.Count() DO BEGIN LautFolder2 := LautFolders.Item(Lint); // This goes wrong END; CLEAR(LautFileSystemObject);When I run this peace of code I get the error:"An exception occurred from an external component. The component did not provide the exception description".
Answers
It seems, that the index is not no. but may be some other key...
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
I suppose your trying to get a list of folders using Navision.
If I were you I would not use Windows Script Host Object Model. Navision has the table file that you can use to walk through Files & Folders.
Here's an example:
I think this will be a easier way to accomplish the same. Hope this is some help!
http://www.codegeniusstudio.com
http://www.facebook.com/CodeGeniusStudio
I think you are suffering the Friday-afternoon-disease.
I know very well this table. Problem is that it doesn't work if the path goes to deep. So I am forced to find another solution.
I tried that automation, but I got stuck on retrieving all the subdirs and files in a subdir.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
No Friday-afternoon-disease, just looking for an alternative for your problem. Collection types in WSH do not work very well with Navision. Why? I cannot tell you, I didn't make the IFolderCollection interface
I was just trying to be helpful...
http://www.codegeniusstudio.com
http://www.facebook.com/CodeGeniusStudio
But you should read the problem better. I wrote in it that I had problems with the File-table.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Use Microsoft Script Control:
Variables:
scr Automation 'Microsoft Script Control 1.0'.ScriptControl
txtCode Text 1024
RetVal Variant
count Integer
i Integer
txtCR Text 30
FolderName Text 1024
And code:
txtCR := ' '; txtCR[1] := 13;
create(scr);
scr.Language := 'VBScript';
//declare global collection
txtCode :=
'dim Folders' + txtCR;
scr.AddCode(txtCode);
//find folders and copy them to collection
txtCode :=
'sub LoadFolderList(folderspec)' + txtCR +
' Dim fso, f, f1, s, sf' + txtCR +
'' + txtCR +
' set Folders = CreateObject("Scripting.Dictionary")' + txtCR +
'' + txtCR +
' Set fso = CreateObject("Scripting.FileSystemObject")' + txtCR +
' Set f = fso.GetFolder(folderspec)' + txtCR +
' Set sf = f.SubFolders' + txtCR +
' For Each f1 in sf' + txtCR +
' Folders.Add (Folders.Count+1), f1' + txtCR +
' Next' + txtCR +
'End sub' + txtCR;
scr.AddCode(txtCode);
txtCode :=
'function GetCount' + txtCR +
' GetCount = Folders.Count' + txtCR +
'end function' + txtCR;
scr.AddCode(txtCode);
txtCode :=
'function GetFolder(i)' + txtCR +
' getFolder = Folders(i)' + txtCR +
'end function' + txtCR;
scr.AddCode(txtCode);
scr.ExecuteStatement('LoadFolderList "C:\temp\"');
RetVal := scr.Eval('GetCount');
count := RetVal;
for i:=1 to count do begin
RetVal := scr.Eval('GetFolder(' + format(i) + ')');
FolderName := RetVal;
message(FolderName);
end;
CLEAR(scr);
I know that in VB no problem... but... ](*,)
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
This is a very clever technique. Thanks for sharing it.
nice!
I used to write and run *.vbs files dynamically at runtime, but your code is in navision - that's cool 8)
Script control allows to add Automation controls from your code, so there is another solution. This time VBScript is used only for copying folders objects from collection indexed by folder name to collection indexed by integer value.
Variables from oryginal code:
LautFileSystemObject Automation 'Windows Script Host Object Model'.FileSystemObject
LautFolder Automation 'Windows Script Host Object Model'.Folder
LautFolder2 Automation 'Windows Script Host Object Model'.Folder
LautFolders Automation 'Windows Script Host Object Model'.Folders
LInt Integer
My new variables:
FoldersCol Automation 'Microsoft Scripting Runtime'.Dictionary
txtCode Text 250
txtCR Text 30
scr Automation 'Microsoft Script Control 1.0'.ScriptControl
Code:
CREATE(LautFileSystemObject);
LautFolder := LautFileSystemObject.GetFolder('c:\temp');
LautFolders := LautFolder.SubFolders();
create(FoldersCol);
create(scr);
scr.Language := 'VBScript';
//variable LautFolders is visible in script as FoldersByName
scr.AddObject('FoldersByName', LautFolders);
//variable FoldersCol is visible in script as FoldersById
scr.AddObject('FoldersById', FoldersCol);
//copy objects using VBScript
txtCR := ' '; txtCR[1] := 13;
txtCode :=
'dim f1' + txtCR +
'For Each f1 in FoldersByName' + txtCR +
' FoldersById.Add (FoldersById.Count+1), f1' + txtCR +
'Next' + txtCR;
scr.ExecuteStatement(txtCode);
clear(scr);
//now we can use collection of folders in Navision
FOR Lint := 1 TO FoldersCol.Count() DO BEGIN
LautFolder2 := FoldersCol.Item(Lint);
message(LautFolder2.Name);
END;
It works! (I have finally time to check it out. And I am still trying to understand it)
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
I've used it today and added the files to it.
Variables:
I'll send it to the downloads also.
But I am not sure where it is.
Found it : It was a reply to a problem I had.... :oops: I need to install some more memory in my head!
This is the link: http://www.mibuso.com/forum/viewtopic.php?t=7855
Maybe you can post some code that is usable for all kind of problems in the tips&tricks
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
i had the same problem as well it turned out that i was getting the message for trying to "get" a non existing folder.
i hope this solves ur problem
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
I have the same problem...
It works as expected... More or Less...
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
It works as expected... More or Less...
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
It works as expected... More or Less...
http://blogs.msdn.com/b/nav/archive/201 ... 09-r2.aspx
It works as expected... More or Less...