Finance

Charts

Statistics

Macros

Search

Swapping Two Puzzle Pieces in Excel VBA

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: Piece1 and Piece2.
  • Two temporary variables, TempLeft and TempTop, are used to store the current Left and Top properties (horizontal and vertical positions) of the first puzzle piece.
  • The procedure swaps the Left and Top values of the two puzzle pieces, effectively exchanging their positions on the worksheet.
0 0 votes
Évaluation de l'article
S’abonner
Notification pour
guest
0 Commentaires
Le plus ancien
Le plus récent Le plus populaire
Online comments
Show all comments
Facebook
Twitter
LinkedIn
WhatsApp
Email
Print
0
We’d love to hear your thoughts — please leave a commentx