Using Dim Statement on Variant Arrays

Using Dim Statement on Variant Arrays

When passing a variant array by reference, make sure to use Dim to declare the statement before using Redim.


 Private Sub Command1_Click()Dim x as integer        ReDim v(2) As Variant    v(0) = "RIN"    v(1) = "A"		    	    Call GetAuthors(v)        Debug.print v(0,0)End SubSub GetAuthors(byref vArray as variant)Dim con As New ADODB.ConnectionDim rs As New ADODB.Recordset    con.ConnectionString = "Driver={SQL Server};Database=Pubs;Server=(local);UID=sa"    con.Open        rs.Source = "select * from AUTHORS where au_lname like '" & vArray(0) & "%'" and " & _ au_fname like '" & vArray(1) & "%'"    Set rs.ActiveConnection = con    rs.Open    vArray = rs.GetRows			'An Error occurs here    rs.Close    con.CloseEnd Sub

Executing this code raises “Run-time error #458 Variable uses an automation type not supported in Visual Basic.” Note that this error is particularly difficult to debug because the compiler will not generate an exception for using Redim without a Dim, event if “Option Explicit” is specified. Declaring the variant with a Dim statement before the Redim will prevent this error from occurring.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several