Results 1 to 3 of 3

Thread: Runtime error 13 when copying an array into a usercontrol

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Runtime error 13 when copying an array into a usercontrol

    I have a usercontrol into which I want to copy data.

    The data is in the form of an array of singles.
    The data is loaded using a property. (get/let)
    The data is stored by the usercontrol in an array of singles.

    This goes for two sets of data, each has it's own source array, property and destination array.

    When I copy the first array it works fine.
    When I copy the second array it gives an error:
    Runtime 13: type mismatch.

    I tested this with a second sub that only copies teh data and only a little bit. (second commandbutton)
    This gives the same error.

    What is weird is that the error always comes when I copy the second array, even if I swap the lines.

    I checked that everything involed uses an array of singles.

    What could be the issue?

    The form:
    vb Code:
    1. Private Sub c_Click()
    2. Dim f As Long
    3. Dim ds() As String
    4. Dim i As Long
    5.  
    6. Dim t As Single
    7. Dim dt() As Single
    8. Dim dx() As Single
    9.    
    10.     cd.FileName = vbNullString
    11.     cd.ShowOpen
    12.     If Dir(cd.FileName) <> vbNullString And cd.FileName <> vbNullString Then
    13.         ReDim ds(0)
    14.         f = FreeFile
    15.         Open cd.FileName For Binary As #f
    16.         ds(0) = String(LOF(f), " ")
    17.         Get #f, , ds(0)
    18.         Close #f
    19.         ds = Split(ds(0), vbCrLf)
    20.        
    21.         ReDim d(UBound(ds))
    22.         For i = 0 To UBound(ds)
    23.             d(i) = ProcessData(ds(i), Len(ds(i)), False)
    24.         Next i
    25.         Erase ds
    26.        
    27.         ReDim dt(UBound(d))
    28.         ReDim dx(UBound(d))
    29.         For i = 0 To UBound(d)
    30.             If i > 0 Then
    31.                 If d(i).Lap_Current > d(i - 1).Lap_Current Then t = t + d(i).LapTime_Last
    32.             End If
    33.             dt(i) = t + d(i).LapTime_Current
    34.             dx(i) = d(i).BrakeTemp_LF
    35.         Next i
    36.        
    37.         Erase d
    38.        
    39.         'hgLF is an instance of the usercontrol
    40.         hgLF.DataX = dx
    41.         hgLF.DataY = dt '<-- runtime 13, type mismatch
    42.        
    43.         hgLF.Draw        
    44.     End If
    45.    
    46. End Sub
    vb Code:
    1. Private Sub Command1_Click()
    2. Dim a() As Single
    3. Dim b() As Single
    4.  
    5.     ReDim a(1000)
    6.     ReDim b(1000)
    7.    
    8.     hgLF.DataY = b
    9.     hgLF.DataX = a '<-- runtime 13, type mismatch
    10. End Sub

    The usercontrol:
    vb Code:
    1. Private varDataX() As Single
    2. Private varDataY() As Single
    3.  
    4. Public Property Get DataX() As Single()
    5.     DataX = varDataX
    6. End Property
    7. Public Property Let DataX(nDataX() As Single)
    8.     varDataX = nDataX
    9. End Property
    10.  
    11. Public Property Get DataY() As Single()
    12.     DataY = varDataY
    13. End Property
    14. Public Property Let DataY(nDataY() As Single)
    15.     varDataY = nDataY
    16. End Property

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: Runtime error 13 when copying an array into a usercontrol

    A bit more.

    I tried the same with a class.
    This gives no problems.

    Also, if I send data to the same property of a usercontrol twice it also gives the error.

    Putting the data into the control using public subs/functions is no problem.

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Runtime error 13 when copying an array into a usercontrol

    Interesting. I can replicate the problem too, but don't understand it -- maybe some usercontrol bug. Have you tried googling for related issues with declaring properties as arrays?

    This could be a temporary fix until problem is solved, use of Variants:
    Code:
    Private varDataX() As Single
    Private varDataY() As Single
    
    Public Property Get DataX() As Variant
        DataX = varDataX
    End Property
    Public Property Let DataX(nDataX As Variant)
        varDataX = nDataX
    End Property
    
    Public Property Get DataY() As Variant
        DataY = varDataY
    End Property
    Public Property Let DataY(nDataY As Variant)
        varDataY = nDataY
    End Property

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width