Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with generalising Code, and calliing it Function call failed 1

Status
Not open for further replies.

PraveenMenon

Programmer
Oct 19, 2002
208
IN
Helo All,

I am having a problem with generalising the following piece of code. I need it as a function, so that i can call it with different arguments.
===========================================================
with Img1
Load Img1((.UBound) + 1)
Img1(.UBound).Picture = Source.Picture
Img1((.UBound)).Visible = True
If (.UBound) = 1 Then
Img1((.UBound)).Move 0, 0
Else
If ((.UBound)) Mod 3 = 1 Then
Img1((.UBound)).Move 0, Img1((.UBound) - 1).Top + Img1((.UBound) - 1).Height
Else
Img1((.UBound)).Move Img1((.UBound) - 1).Left + Img1((.UBound) - 1).Width, Img1((.UBound) - 1).Top
End If

End If
End with
===========================================================
My idea was to write this in a function, and give arguments, so that i can call it like this.

I tried this
===========================================================
Function PopPicBox(Img1() As Image, ImgSource As Control)
Load Img1((Img1.UBound) + 1)
Img1(Img1.UBound).Picture = Source.Picture
Img1((Img1.UBound)).Visible = True
If (Img1.UBound) = 1 Then
Img1((Img1.UBound)).Move 0, 0
Else
If ((Img1.UBound)) Mod 3 = 1 Then
Img1((Img1.UBound)).Move 0, Img1((Img1.UBound) - 1).Top + Img1((Img1.UBound) - 1).Height
Else
Img1((Img1.UBound)).Move Img1((Img1.UBound) - 1).Left + Img1((Img1.UBound) - 1).Width, Img1((Img1.UBound) - 1).Top
End If
End If

End Function
===========================================================


===========================================================
and call it like this
popPicBox Img1(),Image1
===========================================================
This is not working...
It says "Array or User Defined Type Expected"

Can experts suggest an idea?

Thanks In advance All the Best
Praveen Menon
pcmin@rediffmail.com
 
Hi PraveenMenon

In this peace of code, you are declaring img1 as an array.
If you which to access a control array declare as follow:

Function PopPicBox(Img1, ImgSource As Control)

This way you can pass args like

...
PopPicBox Img(4), Picture1
...

where Img is the control array name

I hope this helps you
Good luck.
Carlos Paiva
 
CmPaiva,
Thanx for your response..
I tried that out too.. but when you go through the code in the function, u will notice that i need the ubound of the array too. So it means an array has to be passed to the function. I also tried passing the individual member of the array and passing Ubound as another parameter, it faild as well...

All the Best
Praveen Menon
pcmin@rediffmail.com
 
Hi PraveenMenon

I did a small test. Test it and tell me something.It works!

-Open a new project
-Place a textbox named Ctl.
-Change its index to 0. (to create a control array)
-Copy the following code to form code pane.
-Run
'=====================================================
Private Sub Form_Load()
Dim n As Integer
For n = 1 To 3
PopPicBox Ctl
Next
End Sub

Sub PopPicBox(Img1) ', ImgSource As Control)
Load Img1((Img1.UBound) + 1)
'Img1(Img1.UBound).Picture = Source.Picture
Img1((Img1.UBound)).Visible = True
If (Img1.UBound) = 1 Then
Img1((Img1.UBound)).Move 0, 0
Else
If ((Img1.UBound)) Mod 3 = 1 Then
Img1((Img1.UBound)).Move 0, Img1((Img1.UBound) - 1).Top + Img1((Img1.UBound) - 1).Height
Else
Img1((Img1.UBound)).Move Img1((Img1.UBound) - 1).Left + Img1((Img1.UBound) - 1).Width, Img1((Img1.UBound) - 1).Top
End If
End If
End Sub
'=====================================================

This process of dynamic loading of controls is used a lot by me , but normaly done in batch mode. [sunshine]

Good luck,
Carlos Paiva
 
It worked Carlos... Thanx for the response... even if it didnt work, you will gete a star for you attitutde...

Keep the good work... All the Best
Praveen Menon
pcmin@rediffmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top