Hi everyone,
I have been working on a game/small engine for the game, and what part of it is, is to edit the game maps, where you can change the tiles on the ground to different images. However due to a feature to keep things looking the same by randomizing the images from the same type of image. However some will have more randoms than others. I knew that if the random number generated a number higher than the amount of that image type, then it will produce an Error 53, file not found. So my idea on fixing it would be to simply keep repeating the random number till is gets one that works, using the error handler to jump back and retry.
The problem is that it will jump back once only, after that it wont use the error handler.
This is the code.

Code:
Public Function ChangeTile(ByVal Index As Integer, ByVal ChangeDirection As Integer)

Retry:
On Error GoTo Cleanup

Dim RndImg As Integer
Dim Xval As Integer
Dim Yval As Integer
Dim Error As Byte

Xval = Index Mod Map.SizeX
Yval = Index \ Map.SizeX

Error = 1
If ChangeDirection > 0 Then
    Map.Tile(Xval, Yval).Type = Map.Tile(Xval, Yval).Type + 1
ElseIf ChangeDirection < 0 Then
    Map.Tile(Xval, Yval).Type = Map.Tile(Xval, Yval).Type - 1
End If
ChangeDirection = 0
Error = 2
RndImg = Random(0, 3)
frmMain.MapTile(Index).Picture = LoadPicture("C:\Documents and Settings\Mike\My Documents\RPG Game\Images\MAP" & Map.Tile(Xval, Yval).Type & "-" & RndImg & ".gif")

Exit Function
Cleanup:

Err.Clear
If Error = 1 Then
    Map.Tile(Xval, Yval).Type = 0
    RndImg = Random(0, 3)
    frmMain.MapTile(Index).Picture = LoadPicture("C:\Documents and Settings\Mike\My Documents\RPG Game\Images\MAP" & Map.Tile(Xval, Yval).Type & "-" & RndImg & ".gif")
ElseIf Error = 2 Then
    GoTo Retry
End If

End Function
Is there are way to fix it so it will repeat, or is there another way of fixing it without knowing how many files there really is?
Thanks in Advance.

Regards
Michael