Thank you @Helvetosaur. I was hoping vbscript already has such functions built in. But this way works too.
Here’s the function I have created to multiply variable A with array B.
Function Multiply(A, B())
Dim i
Dim mult()
Dim temp
For i=0 To UBound(B)
temp = A * B(i)
ReDim Preserve mult(i)
mult(i) = temp
Next
Multiply = mult
End Function
I am having another problem with this code though.
Dim Y()
'Setting array dimension for Y
ReDim Y(1)
Beam = 20
B = Array(0.0, 0.5)
Y = Multiply(Beam, B)
This code is giving error message "Type mismatch" at Y=Multiple(Beam,B). If I dont set Y as a dynamic array, then it works. But I need to use Y multiple times in my code where the size of Y will change.
What is the right way of setting an array to another array variable of same size?
What you can do with dynamic arrays is pretty limited in vbscript. If an array has been defined as dynamic, you can’t redefine it as fixed. But in this case, it doesn’t seem you need it. If Y is not defined as a dynamic array, setting Y=something will always work, even if something is a different sized array from what Y was previously - or even not an array at all, but a string, number etc…
If you’re looking to do extensive array (list) operations, I would highly recommend switching to Python, which has tremendous tools for working with lists.