-
May 17th, 2025, 04:22 PM
#1
Thread Starter
Frenzied Member
Question about array type parameters in VBScript
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:
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 Sub
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:
Code:
Public Sub ProcessData(ByVal Data())
MsgBox Data(0,0)
MsgBox Data(1,0)
MsgBox Data(0,1)
MsgBox Data(1,1)
End Sub
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?
Last edited by Ben321; May 17th, 2025 at 04:30 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|