Dim m As Integer, n As Integer Dim i As Integer, j As Integer Dim tbl() As Integer Private Sub Form_Load() Dim temp As String Dim u As Integer ' Dimension du tableau de sortie m = 4 n = 6 ReDim tbl(m * n) i = 1 ' Valeur de départ u = 0 ' Pour la boucle Do While i < m * n Escargot u u = u + 1 Loop ' Mise en forme pour la msgbox For j = 1 To m * n temp = temp & Format$(tbl(j), "00") & " " If j Mod n 0 Then temp temp & vbCrLf Next MsgBox temp End Sub Sub Escargot(p As Integer) 'ligne gauche -> droite For j = n * p + p + 1 To n * (p + 1) - p tbl(j) = i i = i + 1 Next If i > m * n Then Exit Sub 'col haut -> bas For j = n * (p + 2) - p To (m - p) * n - p Step n tbl(j) = i i = i + 1 Next If i > m * n Then Exit Sub 'ligne droite -> gauche For j = (m - p) * n - (p + 1) To (m - (p + 1)) * n + p + 1 Step -1 tbl(j) = i i = i + 1 Next If i > m * n Then Exit Sub 'Colonne bas -> haut For j = n * (m - (p + 2)) + p + 1 To (n * p + 1) + p + 1 Step -n tbl(j) = i i = i + 1 Next End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question