3
votes

I have a VB6 program which populates a two-dimensional array, passes that array into a function of a COM DLL, and then the COM DLL executes a VBScript assigning the array to a variable within the VBScript.

It sounds convoluted and antiquated, I agree, but my job is to fix the bug not re-write a lot of code.

In the VB6 program and in the VBScript the array variable is named "packageDetails". In VBScript and VB6 it is declared as:

dim packageDetails

In both VB6 and the VBScript I observe the following:

msgbox isArray(packageDetails) ' True
msgbox ubound(packageDetails, 1) ' 37
msgbox ubound(packageDetails, 2) ' 1

...this is as expected.

I have a CMS-generated TXT file with 10,000 records. I parse the TXT file with VB6. For each record I parse the data from the TXT file, populate array "packageDetails", then pass it to my DLL. 9,999 records work without error, but in ONE of the records I have the following issue:

In VB6 packageDetails(3, 0) stores the string "EA", this is the expected value. But in VBScript on that same array when I do msgbox packageDetails(3, 0) an exception is thrown with the description, "Type mismatch: 'packageDetails'".

The Event Viewer under Windows Logs/Application does not have any message for this issue.

Given that the max indices are 37 for the first dimension and 1 for the second, why does (3, 0) cause a type mismatch in VBScript but not in VB6 for the same array?

The array is populated by reading from a text file generated by the CMS operating system. I've observed the text file in a hex editor, and there are no unprintable characters in the file (no ASCII NUL bytes, etc).

Any thoughts on what might cause the issue?

2
What are you doing with packageDetails(3, 0), are you assigning it to some variable, printing it, etc? Would be useful if you show the whole statement, or more code. Best is to post an MCVE.A.S.H
I'm doing, msgbox packageDetails(3, 0) in VBScript. In VB6 I'm just debugging and using a combination of the immediate window and the "Watches".Developer Webs
Any other error info ? like Event Viewer > Application error. Also, whats the declaration of packageDetails in vb6 and vbscript.Mukul Varshney
packageDetails is a variant in VB6 and VBScript. It's delcared as, "dim packageDetails". I don't see anything in the Event Viewer under Windows Logs > Application.Developer Webs
show us how the content of the array is being parsed and stored into the arrayderloopkat

2 Answers

0
votes

Solved it. The original array created in VB6 was of type variant. In VB6 after the array is populated we use redim to add/remove rows. When we redim, "As String()" was also accidentally used. In VB6, after the redim, index notation still properly returns values from the array. However, in VBScript it seems that trying to use index notation against the array which had been redimmed with "as string" causes the "type mismatch" error. When I remove the "AS String()" from the redim in VB6 the type mismatch error is no longer raised in VBScript.

-1
votes

Array should be declared using parenthesis, in VBScript also (as in VB6)

VBScript Arrays

https://www.tutorialspoint.com/vbscript/vbscript_arrays.htm