Solved

Simeple para. passing question --QUICK answer needed

Posted on 1998-12-07
4
176 Views
Last Modified: 2010-05-03
I am tring to pass a Image() to a sub? but I can't seem to get to syntax right.So How do you do this.
image1()

Private Sub Image1_Click(Index As Integer)
    getImageArry Index, Label1, Image1
End Sub

Sub getImageArry(num As Integer, lbl As Label, img() As Image)
    lbl = img(num).Name & "(" & num & ")"
End Sub

I am getting "Type mismatch: array or user defined type expected. Help and a sample of code will be appricieted.
HK

(this is just a test code, I attempted doing something like this in my program but I run in to the same problem
0
Comment
Question by:Hans_Klose
  • 2
4 Comments
 
LVL 2

Expert Comment

by:mkmccreary
Comment Utility
Is Image1 and Image Control, or an array of Image Controls?  Give this a try, it Image1 is a control array.

Private Sub Image1_Click(Index As Integer)
    getImageArry Index, Label1, Image1(Index)
End Sub

Sub getImageArry(num As Integer, lbl As Label, img As Image)
    lbl = img.Name & "(" & num & ")"
End Sub

If Image1 is not a control array, try this.

Private Sub Image1_Click(Index As Integer)
    getImageArry Index, Label1, Image1
End Sub

Sub getImageArry(num As Integer, lbl As Label, img As Image)
    lbl = img.Name & "(" & num & ")"
End Sub

Good Luck,
Martin
0
 
LVL 2

Accepted Solution

by:
trillo earned 50 total points
Comment Utility
When passing arrays of objects or user defined types, you MUST use a variant to recieve the object. When passing an array to a variant object, you also must not supply any index:

Private Sub getImageArry(num As Integer, lbl As Label, img As Variant)
    lbl = img(num).Name & "(" & num & ")"
End Sub


Trillo
0
 
LVL 1

Author Comment

by:Hans_Klose
Comment Utility
I am a c++ and Java programmer, and I run across this while makeing a quick prototype. Do I need to cast it
0
 
LVL 2

Expert Comment

by:trillo
Comment Utility
No, In VB castings are the most of the times not necesary, altouugh its useful in some cases: Example...

Dim s1, s2 as string
dim i as Integer
s1 = "123"
s2 = ""
i = s1       // no error, no casting needed
i = s2       // error casting needed
i = CInt(s2) // No error, casting applied
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now