Link to home
Start Free TrialLog in
Avatar of ragnorus
ragnorus

asked on

Image Control Array Help

I am trying to dynamically create image controls by a loop with an array, but I keep getting: "Type Mismatch" in the debugger.  Here is the code:

Private Sub mnuNewGame_Click()
    varLastLeft = 16
    i = 0
    While i <= 10
        Load imgHand(i)
        imgHand(i).Visible = True
        imgHand(i).Left = varLastLeft + 89
        imgHand(i).Top = 456
        imgHand(i).Width = 65
        imgHand(i).Height = 89
        imgHand(i).Picture = LoadPicture(App.Path + "images\" + i + ".jpg")
        i = i + 1
    Wend
End Sub

Thanks :)
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

on which line?

try:
set imgHand(i).Picture = LoadPicture(App.Path + "images\" + i + ".jpg")
ASKER CERTIFIED SOLUTION
Avatar of Hossy
Hossy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Hossy
Hossy

What line is the debugger stopping on?
I get a type mismatch just trying to make your string:
To fix:

app.path + "images\" + cstr(i) + ".jpg"

You probably also wanted it to be:
app.path + "\images\" + cstr(i) + ".jpg"

Instead of the + symbol, try &:

imgHand(i).Picture = LoadPicture(App.Path & "images\" & i & ".jpg")
+ is used for addition, & is used for concatenation
Avatar of ragnorus

ASKER

the debugger points to Load imgHand(i)
Well for the + or & suggestion, I read from this book that either works for concatenation, just that & is more conventional.  I am used to + for javascript, so I'm sticking with it..until it's really a problem (ha ha)

Thanks for the help
Oh for varLastLeft = 16..don't mind that.  At one point, I thought it was the imgHand(i).left that was causing the problem.
Oh for varLastLeft = 16..don't mind that.  At one point, I thought it was the imgHand(i).left that was causing the problem.
& and + sometimes have behave differently.
shouldn't you initialize i to 1 (because normally the instance of imgHand on the form is set to 0) ?
Hossy and emoreau, you were right.  I got the problem fixed..and it was mainly some error I made when making the object (it wasn't declared as an array yet!).  Then, that new type mismatch error came up, and I had to use &.

Thanks for the help guys. :)