Page 1 of 1

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

Posted: 2018-03-27T19:37:16-07:00
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,

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

Posted: 2018-03-27T20:04:11-07:00
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 ?

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

Posted: 2018-03-27T21:00:54-07:00
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

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

Posted: 2018-03-28T15:38:34-07:00
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