Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Option Base 1
- Sub tab1vba4()
- Dim i As Integer, tbl(10) As Integer, tmp As Integer
- ' tworzy tablice z losowymi liczbami i wpisuje do arkusza
- For i = 1 To 10
- tbl(i) = 1 + Int(Rnd * (10 - 1 + 1))
- Cells(i, 1) = tbl(i)
- Next i
- ' przesuwa elementy w tablicy wg następującego wzoru: T(1) -> T(2) -> ... -> T(10) -> T(1)
- tmp = tbl(10)
- For i = 10 To 2 Step -1
- tbl(i) = tbl(i - 1)
- Cells(i, 2) = tbl(i)
- Next i
- Cells(1, 2) = tmp
- End Sub
- Sub tab2vba4()
- Dim i As Integer, pom As Integer, ileLiczb As Integer
- ileLiczb = InputBox("Podaj ile liczb ma zawierać tablica")
- ReDim t(ileLiczb) As Integer ' ReDim pozwala deklarować tablice dynamiczne
- For i = 1 To ileLiczb
- t(i) = 1 + Int(Rnd * (9))
- Cells(i, 1) = t(i)
- Next i
- For i = 1 To ileLiczb / 2
- pom = t(i)
- t(i) = t(ileLiczb - i + 1)
- t(ileLiczb - i + 1) = pom
- Next i
- For i = 1 To ileLiczb
- Cells(i, 2) = t(i)
- Next i
- End Sub
- Sub tab3vba4()
- Dim i As Integer, j As Integer, t(20) As Integer
- j = 1
- For i = 1 To 20 Step 2
- t(i) = j
- t(i + 1) = j
- j = j + 1
- Next i
- For i = 1 To 20
- Cells(1, i) = t(i)
- Next i
- End Sub
- Sub tab4vba4()
- Dim i As Integer, j As Integer, t(10, 10) As Integer, n As Integer
- 'umieszcznie na obydwu przekątnych liczbę 1
- ' dla drugiej przekątnej wycznaczyć zależność j od i (kolumny od wiersza)
- n = 10 ' rozmiar macierzy (tablicy)
- For i = 1 To n
- For j = 1 To n
- If (i = j) Or (j = n - i + 1) Then
- t(i, j) = 1
- Else
- t(i, j) = -1
- End If
- Next j
- Next i
- ' wypisanie wyniku do arkusza
- For i = 1 To n
- For j = 1 To n
- Cells(i, j) = t(i, j)
- Next j
- Next i
- End Sub
- Sub tab5avba4()
- 'Szyfr Cezara - szyfrowanie
- Dim i As Byte, tekst As String, szyfr As String, v As Integer, lenght As Byte, a As Byte, code As Byte, pom As Byte
- et: tekst = InputBox("Podaj słowo")
- v = InputBox("Podaj przesunięcie")
- lenght = Len(tekst)
- For i = 1 To lenght
- a = Asc(Right(Left(tekst, i), 1))
- pom = a + v
- If (pom < 65) And (a <> 32) Then
- pom = pom + 26
- ElseIf pom > 90 And pom < 97 And (v > 0) Then
- pom = pom - 26
- ElseIf pom > 90 And pom < 97 And (v < 0) Then
- pom = pom + 26
- ElseIf pom > 122 Then
- pom = pom - 26
- ElseIf a = 32 Then
- pom = 32
- End If
- szyfr = szyfr & Chr(pom)
- Next i
- MsgBox szyfr
- code = MsgBox("Jeszcze raz?", vbYesNo + vbQuestion)
- If code = vbYes Then
- szyfr = ""
- GoTo et
- End If
- End Sub
- Sub tab5bvba4()
- 'Szyfr Cezara - deszyfrowanie
- Dim szyfr As String, slowo As String, dl As Integer, v As Integer, pom As String, a As String, i As Integer, kod As Byte
- et: szyfr = InputBox("Podaj zaszyfrowaną wiadomość")
- v = InputBox("Podaj przesunięcie")
- dl = Len(szyfr)
- For i = 1 To dl
- a = Asc(Right(Left(szyfr, i), 1))
- pom = a - v
- If pom > 90 And pom < 97 And v > 0 Then
- pom = pom + 26
- ElseIf pom > 90 And pom < 97 And v < 0 Then
- pom = pom - 26
- ElseIf (pom < 65) And (a <> 32) Then
- pom = pom + 26
- ElseIf pom > 122 Then
- pom = pom - 26
- ElseIf (a = 32) Then
- pom = 32
- End If
- slowo = slowo & Chr(pom)
- Next i
- MsgBox slowo
- kod = MsgBox("Jeszcze raz?", vbYesNo + vbQuestion)
- If kod = vbYes Then
- slowo = ""
- GoTo et
- End If
- End Sub
- Sub tab6vba4()
- ' Bubble Sort
- Dim t() As Variant, i As Integer, j As Integer, n As Integer, tmp As Integer
- 'n = InputBox("")
- n = 10
- t = Array(1, 3, 4, 3, 2, 5, 6, 8, 2, 7)
- For i = 1 To 10
- Cells(1, i) = t(i)
- Next i
- For j = 1 To n - 1
- For i = 1 To n - 1
- If (t(i) > t(i + 1)) Then
- tmp = t(i + 1)
- t(i + 1) = t(i)
- t(i) = tmp
- End If
- Next i
- Next j
- For i = 1 To 10
- Cells(2, i) = t(i)
- Next i
- End Sub
- Sub tab7vba4()
- Dim i As Integer, j As Integer, k As Integer, t() As Variant, n As Integer, min As Integer
- t = Array(2, 3, 4, 3, 1, 5, 6, 8, 1, 7)
- n = 10
- For i = 1 To n
- Cells(1, i) = t(i)
- Next i
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- For j = 1 To 10 - 1
- min = t(j)
- k = j
- For i = j + 1 To 10
- If (t(i) < min) Then
- min = t(i)
- k = i
- End If
- Next i
- t(k) = t(j)
- t(j) = min
- Next j
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- For i = 1 To 10
- Cells(3, i) = t(i)
- Next i
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement