Using the MSScriptControl in VB6 as the host, I noticed some interesting things about passing parameters to a VBScript function. My The code on the host side is:
This way the script will be executed when I click the button (the script itself is loaded in the Load event in Form1, but I haven't posted that code here, for the sake of simplicity).
And the code in the script is:
After I wrote this script, and ran it, and saw it worked, I noticed an error in the code that should have prevented it from working. In that first line, it says "ByVal Data()" for the first parameter. ByVal though is NOT valid for an array. Only ByRef is valid. But it still worked without giving any errors. And not only did it run, it behaved exactly as expected, as if I had correctly used ByRef, even though it said ByVal instead. I did later correct it to ByRef, and of course that also worked.
Can someone here explain why both of these worked?
Code:
Private Sub Command1_Click()
Dim Data(1, 1) As Variant
Data(0, 0) = 1
Data(1, 0) = &H7FFFFFFF
Data(0, 1) = 1.23
Data(1, 1) = "a"
SC1.CodeObject.ProcessData Data()
End SubAnd the code in the script is:
Code:
Public Sub ProcessData(ByVal Data())
MsgBox Data(0,0)
MsgBox Data(1,0)
MsgBox Data(0,1)
MsgBox Data(1,1)
End SubCan someone here explain why both of these worked?