dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Enterprise
Expertise: Intermediate
May 6, 1998

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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.

Example:

 
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 Sub


Sub GetAuthors(byref vArray as variant)
Dim con As New ADODB.Connection
Dim 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.Close
End 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.
Jerry Brunning
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date