SOLVED : Use a variable number of arguments in VbScript / Asp

ImageMagickObject is a Windows COM+ interface to ImageMagick. COM+, Visual Basic, and Delphi users should post to this discussion group.
Post Reply
Alexvb6
Posts: 49
Joined: 2012-10-12T16:50:15-07:00
Authentication code: 67789

SOLVED : Use a variable number of arguments in VbScript / Asp

Post by Alexvb6 »

Hi,

In Vbscript, How could I use a variable number of arguments ? (In IM v 6.9.9)

Code: Select all

'Declare my arguments
Dim arg(1)
arg(0) = "c:\Source.jpg"
arg(1) = "c:\Destination.jpg"

'The following works, but I have to know the number of arguments, they will never be the same in my program
Set ImgObj = CreateObject("ImageMagickObject.MagickImage.1")
	ImgObj.Convert( arg(0), arg(1) )
Set ImgObj = Nothing

'The following does not work : IM does not like to receive an Array as argument
Set ImgObj = CreateObject("ImageMagickObject.MagickImage.1")
	ImgObj.Convert( arg )
Set ImgObj = Nothing
I thank you very much,
Last edited by Alexvb6 on 2018-03-27T20:05:24-07:00, edited 1 time in total.
Alexvb6
Posts: 49
Joined: 2012-10-12T16:50:15-07:00
Authentication code: 67789

Re: Use a variable number of arguments in VbScript / Asp

Post by Alexvb6 »

It seems that IM does not like to receive an Array containing the source and destination files.
The source and destination file have to be included in the arguments, and the Array containing optional arguments have to be included between them.

So the following will not generate any error, BUT ImageMagick will simply ignore all the arguments ! (The image will not be rotated in this case).
The Source will be converted to the Destinaiton, but nothing more... :-/ :/

Code: Select all

'Declare optional arguments
Dim arg(1)
arg(0) = "-rotate"
arg(1) = "90"

'Execute
Set ImgObj = CreateObject("ImageMagickObject.MagickImage.1")
	ImgObj.Convert "c:\Source.jpg", arg, "c:\Destination.jpg"
Set ImgObj = Nothing
How to solve that ?
Alexvb6
Posts: 49
Joined: 2012-10-12T16:50:15-07:00
Authentication code: 67789

Re: SOLVED : Use a variable number of arguments in VbScript / Asp

Post by Alexvb6 »

Ok.. So IM made me crazy on this one !

I have found how to proceed : You have to list all the args, but set the ones you do not need as "Empty" !

Code: Select all

'Declare optional arguments
Dim arg(3)
arg(0) = "-rotate"
arg(1) = "67"
arg(2) = Empty
arg(3) = "-negate"

'Execute
Set ImgObj = CreateObject("ImageMagickObject.MagickImage.1")
	ImgObj.Convert "c:\Source.jpg", arg(0), arg(1), arg(2), arg(3), "c:\Destination.jpg"
Set ImgObj = Nothing
Alexvb6
Posts: 49
Joined: 2012-10-12T16:50:15-07:00
Authentication code: 67789

Re: SOLVED : Use a variable number of arguments in VbScript / Asp

Post by Alexvb6 »

UPDATE :

The IM COM+ Object DOES accept the Source file and the Destination file to be specified in an Array.
So, as long as the empty argumets are assigned the VBScript type Empty, it is OK.

The following will work :

Code: Select all

'Declare optional arguments
Dim arg(5)
arg(0) = "c:\Source.jpg"
arg(1) = "-rotate"
arg(2) = "27"
arg(3) = Empty
arg(4) = "-negate"
arg(5) = "c:\Destination.jpg"

'Execute
Set ImgObj = CreateObject("ImageMagickObject.MagickImage.1")
	ImgObj.Convert arg(0), arg(1), arg(2), arg(3), arg(4), arg(5)
Set ImgObj = Nothing
Post Reply