Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

An object in an array

Status
Not open for further replies.

RClarkeJr

Programmer
Nov 10, 2004
20
US
I am writing some vbscript and I am not sure how to deal with this issue. I need to pass a file to a function but it requires the file to be passed as an object in an array since there could be multiple files.

I am having a hard time figuring out how to add the file as an object to the array. Please see my code below:

Dim iattachments(0)

iattachments(0) = "C:\temp\myfile.xml"
iedrs.ExecuteFile (iAppName, iAppErrorText, iAppID, (iattachments), iCameFrom)
 
Can you provide more detail. what is iedrs? There is no method "ExecuteFile" that I'm aware of.

Also, you don't need parentheses around "(iattachments)" when passing to a function.

-Geates
 
iedrs is a custom built dll which requires the following parameters:

Dim edrs
Set edrs = CreateObject("RoutingService.EDRSccw")

Function ExecuteFile(appName As String, appErrorText As String, appID As String, filesToRoute() As Variant, cameFrom As String) As Boolean
 
It depends on what the function expects the entries of the array of variant (object), ie, their subtypes. Not abstractly, but what it really is, because the function is expected to do some real work on it.

For a file like myfile.xml, I can give you a demo of passing an array of variant of 2 entries: index 0 being File, index 1 being DOMDocument.
[tt]
'givens
[green]sfile="C:\temp\myfile.xml"[/green]

set fso=createobject("scripting.filesystemobject")
set oparser=createobject("msxml2.domdocument")

'suppose sfile being exists and well-formed xml doc for simplicity
set f=fso.getfile(sfile)
with oparser
.validateonparse=false
.resolveexternals=true
.async=false
.load sfile
end with

Dim iattachments(1)
set iattachments(0)=f
set iattachments(1)=oparser

set oparser=nothing
set f=nothing

x iattachments

set iattachments(1)=nothing
set iattachments(0)=nothing

function x (aobj)
wscript.echo ubound(aobj)
wscript.echo aobj(0).openastextstream(1,false).readall
wscript.echo aobj(1).xml
end function
[/tt]
This shows you how to pass the array of object to a function.
 
tsuji,

Why would you set the variables back to nothing after they have been asssigned values? and where did you assigned the aobj values? Don't quite understand the last part. Thanks in advance.
 
>Q: Why would you set the variables back to nothing after they have been asssigned values?
A: I just want to clear the references up and show you that after assigning the object to iattachments array, the original setting up of the entry can be dereferenced as the address is assigned. The final part of cleaning up iattachments has no particular significance. Use the array until it is of no use any more.

>Q: and where did you assigned the aobj values?
A: It is passed by this line. (If you don't understand this, you need to learn elementary stuff before doing that.)
[tt] x iattachments[/tt]
just like passing in any function. In your use, it is like this, if that make you more comfortable.
[tt] iedrs.ExecuteFile[highlight] [/highlight]iAppName, iAppErrorText, iAppID, [red]iattachments[/red], iCameFrom[highlight] [/highlight][/tt]
Note: there is no paratheses enclosing the parameters if the method return is dumped or the method returns nothing at all. (Or you use the call keyword.) Otherwise, it is a compile-time error and the script won't even run.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top