Solved

VBScript and Multidimensional arrays

Posted on 1998-08-31
4
785 Views
Last Modified: 2012-06-27
I get the following error when I run the VBscript below …

Error in the script at Line 5 and column 0
Type mismatch
Microsoft VBScript runtime error

The call below to the function scGetValueArray( ), of the MMLCmdObj object, retrieves the second argument as an array of values(strings). However, If I call the function IsArray() over ValArray, it returns TRUE meaning that it does recognize it as an array. Also, if I comment out the functions to retrieve the values of the array elements, the call to Ubound works fine too.


Sub SetInfo
Dim ParamName, ValArray, Upper, Counter, SQL
ParamName = "DIR"
call MMLCmdObj.scGetValueArray(ParamName, ValArray)
MsgBox ValArray(0,0) ''''''''''''''''''''''''''I get the error here
Upper = UBound(ValArray, 2)
For Counter = 0 To Upper
    SQL = "INSERT INTO extension (Type, startDir, endDir) " & vbNewLine
    SQL = SQL & " VALUES('ANA', " & CStr(ValArray(Counter,0)) &", "& CStr(ValArray(Counter,1)) &")"  '''''''''''''''''''''''''''''I get the error here too
    if Not MMLCmdObj.scInsertValues(SQL)Then
      Exit For
    End If
Next
End Sub

Any ideas ????
0
Comment
Question by:joeslow
  • 2
4 Comments
 
LVL 1

Expert Comment

by:CarlosJac
Comment Utility
Is LBound(ValArray, 2) = 0 ?
0
 

Author Comment

by:joeslow
Comment Utility
Yes it is
0
 
LVL 4

Accepted Solution

by:
mcix earned 100 total points
Comment Utility
In the scGetValueArray method of the  MMLCmdObj object, make sure you define the ValArray parameter ByVal As Variant.

Like this:

Public Sub scGetValueArray(ByVal ParamName as Variant, ByVal ValArray As Variant)

Usually, a Type-Mismatch will occur if it is not declared in this fashion...


0
 

Author Comment

by:joeslow
Comment Utility
Your reply lead me to find the correct answer to my problem which was actually in my C++ code.
I had the ValArray.vt defined as VT_ARRAY instead of VT_ARRAY | VT_VARIANT

Thank you

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now