PRB: Passing Variant Array to WriteFields Method Generates Error (180456)



The information in this article applies to:

  • Microsoft eMbedded Visual Basic 3.0
  • Microsoft Windows CE Toolkit for Visual Basic 6.0

This article was previously published under Q180456

SYMPTOMS

When a Variant array is passed as a parameter, one of the following errors might occur:
Subscript out of range.

RESOLUTION

To work around this behavior, pass arrays without parenthesis, as follows:
File1.WriteFields sData
				

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new Windows CE project in eMbedded Visual Basic or Visual Basic 6.0. Form1 is created by default.
  2. From the Project menu, click Components, select "Microsoft CE File System Control", and click OK.
  3. Add a File control and a Command Button to Form1.
  4. Paste the following code in to Form1:
          Dim sData()
          Dim iLoop
    
          Private Sub Command1_Click()
             On Error Resume Next
             'Build Array
             ReDim sData(3)
             For iLoop = 0 To 3
                 sData(iLoop) = "Some Text" & iLoop
             Next
             File1.Open "\test.txt", 2
             File1.WriteFields sData()   'This line generates an error.
             MsgBox Err.Number & " " & Err.Description
             File1.Close
         End Sub
    						
  5. Press F5 to run the project and note that a message box appears indicating that error 9 "subscript out of range" occurred.

Modification Type:MinorLast Reviewed:3/11/2005
Keywords:kbpending kbprb kbToolkit KB180456