160 likes | 169 Views
Learn about the different types of variables, including static, public, private, and dim, as well as how to declare and reference arrays in Visual Basic. Also, discover how to sort arrays using the Bubblesort algorithm.
E N D
Typy dat • Static - Statická proměnná dokud pro danou proceduru, zachovává si platnost. • Public - Ve všech modulech a procedurách zachovává si platnost i po skončení danné procedury. • Private - dostupné pro všechny procedury v daném modulu • Dim - dostupné pro jednu proceduru v daném modulu. Jen když tento modul běží. Nebo pro procedury v daném modulu. Záleží kde je deklarace uvedena.
Příklad deklarace proměnné • DimModHodnotaLg As Long • Dim a As Integer, b As Integer
Deklarace pole • Dim MojePole (9) As Boolean • Dim MojePole (0 To 9) As Boolean • Dim FakturyPole (2009 To 2011) As Double • DimListPole () As Double • DimMojePole(9, 9) As Integer • DimMojePole(0 To 9, 0 To 9) As Integer
Odkazování na prvky pole • ListPole(i) = ....
Příklad DimArr(5) Arr(0) = "Pondělí" Arr(1) = "Úterý" Arr(2) = "Středa" Arr(3) = "Čtvrtek" Arr(4) = "Pátek" ' Vypíšeme do dialogového okna. MsgBoxArr(0) & "-" & Arr(1) & "-" & Arr(2) & "-" & Arr(3) & "-" & Arr(4)
Příklad For i = 1 to 20 p(i) = ActiveSheet.Cells(i,1).Value Next i For i=1 to 20 ActiveSheet.Cells(i,1).Value = p(i) Next i
35 12 77 101 5 42 Řazení podle velikosti - Bubblesort • Sorting takes an unordered collection and makes it an ordered one. 1 2 3 4 5 6 101 12 42 35 5 77 1 2 3 4 5 6
"Bubbling Up" the Largest Element • Traverse a collection of elements • Move from the front to the end • “Bubble” the largest value to the end using pair-wise comparisons and swapping 1 2 3 4 5 6 101 12 42 35 5 77
42 77 "Bubbling Up" the Largest Element • Traverse a collection of elements • Move from the front to the end • “Bubble” the largest value to the end using pair-wise comparisons and swapping Swap 1 2 3 4 5 6 101 12 42 35 5 77
35 77 "Bubbling Up" the Largest Element • Traverse a collection of elements • Move from the front to the end • “Bubble” the largest value to the end using pair-wise comparisons and swapping 1 2 3 4 5 6 Swap 101 12 77 35 5 42
12 77 "Bubbling Up" the Largest Element • Traverse a collection of elements • Move from the front to the end • “Bubble” the largest value to the end using pair-wise comparisons and swapping 1 2 3 4 5 6 Swap 101 12 35 77 5 42
"Bubbling Up" the Largest Element • Traverse a collection of elements • Move from the front to the end • “Bubble” the largest value to the end using pair-wise comparisons and swapping 1 2 3 4 5 6 101 77 35 12 5 42 No need to swap
5 101 "Bubbling Up" the Largest Element • Traverse a collection of elements • Move from the front to the end • “Bubble” the largest value to the end using pair-wise comparisons and swapping 1 2 3 4 5 6 Swap 101 77 35 12 5 42
"Bubbling Up" the Largest Element • Traverse a collection of elements • Move from the front to the end • “Bubble” the largest value to the end using pair-wise comparisons and swapping 1 2 3 4 5 6 101 5 77 35 12 42 Largest value correctly placed