During both the initial shuffling of all puzzle pieces and when the user clicks to swap pieces, two puzzle pieces are exchanged using the following procedure:
Sub SwapPieces(Piece1 As Shape, Piece2 As Shape)
Dim TempLeft As Integer
Dim TempTop As Integer
TempLeft = Piece1.Left
Piece1.Left = Piece2.Left
Piece2.Left = TempLeft
TempTop = Piece1.Top
Piece1.Top = Piece2.Top
Piece2.Top = TempTop
End Sub
Explanation:
- The procedure receives two references to puzzle pieces (Shape objects) as parameters:
Piece1andPiece2. - Two temporary variables,
TempLeftandTempTop, are used to store the currentLeftandTopproperties (horizontal and vertical positions) of the first puzzle piece. - The procedure swaps the
LeftandTopvalues of the two puzzle pieces, effectively exchanging their positions on the worksheet.