Joe M
Joe M

Reputation: 3400

How can I convert a string array to a variant array in VBscript?

I'm using a function in vbscript which returns a variant array of strings.

JobIDs = objDoc.ConnectedSubmit(objServer)

The problem is I can't get the Job ID values from that array, as vbscript doesn't handle typed variables. It just gives a type mismatch when I attempt to do ANYTHING with the JobIDs array. I found some promising information here, but when I used the conversion function:

Set objConverter = CreateObject("ADS.ArrayConvert")
ConvertedJobIDs = objConverter.CStrArray(JobIDs())

It is giving me the same type mismatch error. Am I missing something obvious here? This is, apparently, an official microsoft solution, so I'm not sure why it seems to have the same problem, namely, not being able to actually do anything with a string array in the first place. I've seen the first part of my question answered in many places, all pointing to the MS solution, but I have yet to see any follow up reports of someone successfully using that solution.

Upvotes: 4

Views: 3001

Answers (2)

Safwan
Safwan

Reputation: 360

This behavior is by design, VBScript can't do anything with a non-variant array, there was a KB article from Microsoft that explained this but it is not on-line anymore:

Q165967 - PRB: Script Error Occurs When Referencing Non-variant Array

An archived copy of the article can be found at:

https://ftp.zx.net.nz/pub/archive/ftp.microsoft.com/MISC/KB/en-us/165/967.HTM

Upvotes: 1

Hans Olsson
Hans Olsson

Reputation: 54999

I'm not sure if I understand why it doesn't work, so this answer might not be very helpful. I would have thought that something like this might work (following on from your previous question I'm assuming you're trying to get the cancellation to work):

For Each id In JobIDs
    WScript.Echo id
    YourJob = YourOutgoingFaxQueue.GetJob(id)
    YourJob.Cancel()
Next

Upvotes: 1

Related Questions