shit_code

Vba1

Sep 11th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private Function check(number As Integer) As Boolean
  2.    If number Mod 2 = 0 Then
  3.     cheñk = False
  4.    Else
  5.     cheñk = True
  6.    End If
  7. End Function
  8. Sub Êíîïêà1_Ùåë÷îê()
  9.    Dim N As Byte, i As Byte, m As Byte
  10.    Dim num As Integer
  11.    Dim n_spir As Integer
  12.    Dim r As Range
  13.    
  14.    Cells.ClearContents
  15.    Cells.Borders.LineStyle = xlNone
  16.    Cells.Interior.Color = vbWhite
  17.    Set r = Range("A4")
  18.    
  19.    num = 1
  20.    N = Val(InputBox("Ââåäèòå ÷èñëî n:", , 7))
  21.    If N = 0 Then Exit Sub
  22.    
  23.    ReDim a(1 To N, 1 To N) As Integer
  24.  
  25.    For n_spir = 0 To N \ 2 - 1
  26.                    m = N - 1 - 2 * n_spir
  27.       For i = 1 To m
  28.          a(n_spir + 1, i + n_spir) = num: num = num + 1 '??????
  29.      Next i
  30.      
  31.       For i = 1 To m
  32.          a(i + n_spir, N - n_spir) = num: num = num + 1   '????
  33.      Next i
  34.      
  35.       For i = 1 To m
  36.          a(N - n_spir, N - n_spir - i + 1) = num: num = num + 1     '?????
  37.      Next i
  38.      
  39.       For i = 1 To m
  40.          a(N - n_spir - i + 1, n_spir + 1) = num: num = num + 1  '?????
  41.      Next i
  42.    Next n_spir
  43.    If N Mod 2 = 1 Then a(N \ 2 + 1, N \ 2 + 1) = N ^ 2
  44.    
  45.     r.Resize(N, N) = a:   Alg r, N
  46. End Sub
  47.  
  48. Sub Alg(r As Range, N As Byte)
  49.    Dim i As Byte, n_spir As Byte
  50.    If N Mod 2 = 0 Then n_spir = N \ 2 Else n_spir = N \ 2 + 1
  51.    For i = 0 To n_spir - 1
  52.       With r.Offset(i, i).Resize(N - 2 * i, N - 2 * i)
  53.          .Borders(xlEdgeLeft).Weight = xlMedium
  54.          .Borders(xlEdgeTop).Weight = xlMedium
  55.          .Borders(xlEdgeBottom).Weight = xlMedium
  56.          .Borders(xlEdgeRight).Weight = xlMedium
  57.       End With
  58.       With r.Offset(i, i)
  59.          .Borders(xlEdgeBottom).Weight = xlMedium
  60.          If i >= 1 Then .Borders(xlEdgeLeft).LineStyle = xlNone
  61.       End With
  62.       For Each r In Range("A4:G11")
  63.   If check(r.Value) = False Then
  64.    r.Interior.Color = vbBlue
  65.   End If
  66.   Next
  67.    Next i
  68. End Sub
Add Comment
Please, Sign In to add comment