Results 1 to 11 of 11

Thread: Variant array error

  1. #1

    Thread Starter
    Hyperactive Member Daniel Duta's Avatar
    Join Date
    Feb 2011
    Location
    Bucharest, Romania
    Posts
    397

    Variant array error

    For almost a month, after a few updates made by the IT team, I have been facing some issues with variant arrays in the vb6 IDE. Simply I cannot longer assign a variant variable to the well known ADO method GetRows. Each time when I try to get the ADO function's result as below the whole vb6 project crashes severely skipping the error handling procedure.
    Code:
    Dim myArr() As Variant
    myArr = rec.GetRows
    Name:  vb error.PNG
Views: 266
Size:  7.2 KB
    I mention that this annoying error does occur only in the debugging mode, once the project is compiled everything goes well. Does anyone know what update caused this error? Is there any work around to fix it? My OS is Windows 10 vers.1809 and personally I suspect the updates KB4558997 and KB4558998 installed at the end of July.
    "VB code is practically pseudocode" - Tanner Helland
    "When you do things right, people won't be sure you've done anything at all" - Matt Groening
    "If you wait until you are ready, it is almost certainly too late" - Seth Godin
    "Believe nothing you hear, and only one half that you see" - Edgar Allan Poe

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,936

    Re: Variant array error

    I don't use the ADO that much, but I looked at the MSDN, and the example for GetRows doesn't declare a variant array. Rather, it just declares a regular variant, and then puts the array returned by GetRows into that single variant.

    Here's the example, and here's the reference to GetRows.

    What gave me the clue is that the GetRows MSDN says it returns a value with a 2D array.

    -----

    EDIT: Just to talk it through a bit more, an array of variants is quite different than a variant containing array. In fact, you could have an array of variants with each variant in the array containing an array.

    In this GetRows case, it seems you need a single variant (not an array) to contain the array that's returned.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Variant array error

    Sounds like a bug that was patched long ago. I think we had a discussion on that here back a couple of years ago. You seem to be very far behind on updates.

    Windows 10 has been at 2004 now for months.

    Just tried a test case and it works here. Maybe you can track down the discussion thread. It may list the offending patch(es) and subsequent hotfix patch. That or get it in gear and catch up on almost 2 years of updates. Then fire your "IT team" who clearly spend too much time out smoking on the loading dock texting girlfriends.
    Last edited by dilettante; Aug 30th, 2020 at 09:14 PM.

  4. #4

    Thread Starter
    Hyperactive Member Daniel Duta's Avatar
    Join Date
    Feb 2011
    Location
    Bucharest, Romania
    Posts
    397

    Re: Variant array error

    Quote Originally Posted by Elroy View Post
    I don't use the ADO that much, but I looked at the MSDN, and the example for GetRows doesn't declare a variant array. Rather, it just declares a regular variant, and then puts the array returned by GetRows into that single variant.

    Here's the example, and here's the reference to GetRows.

    What gave me the clue is that the GetRows MSDN says it returns a value with a 2D array.

    -----

    EDIT: Just to talk it through a bit more, an array of variants is quite different than a variant containing array. In fact, you could have an array of variants with each variant in the array containing an array.

    In this GetRows case, it seems you need a single variant (not an array) to contain the array that's returned.
    ADO library, at least in my computer has 6 different versions and it is in the windows environment for decades. I don't know how you used to get data from a recordset, perhaps looping through it but for sure even you declare a variant as variable or as array the GetRows method returns a bidimensional array - even you have as result a single value. The idea is the error doesn't depend on how the variant is declared but on some hidden modifications made by MS in the OS. It would be interesting to know how these updates caused this particular error.
    Last edited by Daniel Duta; Aug 31st, 2020 at 12:57 AM. Reason: I forgot to mention the reply
    "VB code is practically pseudocode" - Tanner Helland
    "When you do things right, people won't be sure you've done anything at all" - Matt Groening
    "If you wait until you are ready, it is almost certainly too late" - Seth Godin
    "Believe nothing you hear, and only one half that you see" - Edgar Allan Poe

  5. #5

    Thread Starter
    Hyperactive Member Daniel Duta's Avatar
    Join Date
    Feb 2011
    Location
    Bucharest, Romania
    Posts
    397

    Re: Variant array error

    Quote Originally Posted by dilettante View Post
    Sounds like a bug that was patched long ago. I think we had a discussion on that here back a couple of years ago. You seem to be very far behind on updates.

    Windows 10 has been at 2004 now for months.

    Just tried a test case and it works here. Maybe you can track down the discussion thread. It may list the offending patch(es) and subsequent hotfix patch. That or get it in gear and catch up on almost 2 years of updates. Then fire your "IT team" who clearly spend too much time out smoking on the loading dock texting girlfriends.
    Hello Dilletante, I am glad to found you here active as always and ready to give us a help. Unfortunately the OS updates and patches are under the IT team management and it is really surprising that the latest version is 2004 and we still stay on 1809. Have you succeeded to find out which patch fixed this error? Because I will try to install it myself. Thank you.
    "VB code is practically pseudocode" - Tanner Helland
    "When you do things right, people won't be sure you've done anything at all" - Matt Groening
    "If you wait until you are ready, it is almost certainly too late" - Seth Godin
    "Believe nothing you hear, and only one half that you see" - Edgar Allan Poe

  6. #6

  7. #7

    Thread Starter
    Hyperactive Member Daniel Duta's Avatar
    Join Date
    Feb 2011
    Location
    Bucharest, Romania
    Posts
    397

    Re: Variant array error

    Quote Originally Posted by Eduardo- View Post
    This thread talks about the issue.
    Those discussions do not have a clear conclusion. At least I installed the kb4512534 and the issue remained. But, meanwhile, I have noticed something interesting. This error is somehow related to Forms. If I run my lines from a module using a Main routine (without any Form in the project) everything goes without any errors...
    "VB code is practically pseudocode" - Tanner Helland
    "When you do things right, people won't be sure you've done anything at all" - Matt Groening
    "If you wait until you are ready, it is almost certainly too late" - Seth Godin
    "Believe nothing you hear, and only one half that you see" - Edgar Allan Poe

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Variant array error

    Code:
    Option Explicit
    
    Private Sub Form_Load()
        Dim Rows As Variant
        Dim Row As Long
        Dim Col As Integer
        
        With New ADODB.Recordset
            .Open "[Sample.txt]", _
                  Replace$("Provider=Microsoft.Jet.OLEDB.4.0;" _
                         & "Data Source='$PATH$';" _
                         & "Extended Properties='Text'", _
                           "$PATH$", _
                           App.Path), _
                           adOpenStatic, _
                           adLockReadOnly, _
                           adCmdTable
            Rows = .GetRows(adGetRowsRest)
            .Close
        End With
        For Row = 0 To UBound(Rows, 2)
            For Col = 0 To UBound(Rows, 1)
                Print Rows(Col, Row),
            Next
            Print
        Next
        Print "That's all, folks!"
    End Sub
    Sample.txt:
    Code:
    Column A, Column B
    aaa, bbb
    Aaa, Bbb
    AAA, BBB
    Name:  sshot.png
Views: 181
Size:  1.0 KB

    Change:

    Code:
        Dim Rows() As Variant
    Same results.

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Variant array error

    I'm digging a lot but still have not found a specific patch for this issue.

  10. #10
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: Variant array error

    Quote Originally Posted by Daniel Duta View Post
    Those discussions do not have a clear conclusion. At least I installed the kb4512534 and the issue remained. But, meanwhile, I have noticed something interesting. This error is somehow related to Forms. If I run my lines from a module using a Main routine (without any Form in the project) everything goes without any errors...
    In short, my conclussion, to avoid any such possible problem, avoid using code that can produce variant arrays without elements.

    Did you already tried changing the variable from variant array to a single variant as pointed above by Elroy?

  11. #11
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Variant array error

    Quote Originally Posted by Daniel Duta View Post
    ADO library, at least in my computer has 6 different versions...
    This is a common misconception. Microsoft wrote an old KB article explaining this way back around 1999.

    Ever since the very early Win95 days there is only one ADO core library (ADODB) on the system: msado15.dll. There are compatibility typelibs that define older interfaces implemented by this DLL in addition to the latest set of interfaces, which it contains an embedded typelib for.

    There is one ADODB and a set of "masks" it can wear so older programs can still work. Those false faces point to appcompat adapters within msado15.dll.

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