VB6 Array and Type Mismatch
I have a VB6 program that populates a two-dimensional array, passes that array to a COM DLL function, and then the COM DLL executes VBScript, assigning the array to a variable in VBScript.
It sounds confusing and outdated, I agree, but my goal is to fix the error without rewriting a lot of code.
In VB6 and VBScript, the array variable is named "packageDetails". In VBScript and VB6 it is declared as:
dim packageDetails
In VB6 and 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 TXT file generated by a CMS with 10,000 records. I am parsing a TXT file using VB6. For each record, I parse the data from the TXT file, populate the "packageDetails" array, and then pass it to my DLL. 9999 records work without errors, but in ONE of the records I have the following problem:
VB6 packageDetails(3, 0)
stores the string "EA", which is the expected value. But in VBScript, in the same array, when I do msgbox packageDetails(3, 0)
, an exception is thrown with the description, "Mismatch type:" packageDetails ".
Event Viewer under Windows Logs / Application has no messages for this issue.
Given that the maximum 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 looked at the text file in a hex editor and there are no non-printable characters in the file (no NULL ASCII bytes, etc.).
Any thoughts on what might be causing the problem?
source to share
I decided. The original array created in VB6 had a variant of the type. In VB6, after filling the array, we use redim
to add / remove rows. When we redim
, "As String ()" was also accidentally used. In VB6, after renaming, index notation still correctly returns values ββfrom an array. However, in VBScript, it seems that trying to use index notation against an array that has been rendered "as string" is throwing a "type mismatch" error. When I remove "AS String ()" from redim in VB6, the type mismatch error no longer occurs in VBScript.
source to share