For Indeks=QuyiChegara To YuqoriChegara Step Qadam
‘ Tsikl tanasi
Next [Indeks]
Misol:
1: Sub AddUsers()
2:
Dim Users(10)
As String
3:
Dim I As Integer
4:
For i=10 to1 Step -1
5:
Users(i)=InputBox(“Foydalanuvchi nomini kiriting = “,
“Foydalanuvchi nomi”.)
6:
Next i
7: End Sub
UBound, LBound funktsiyalari
Takrorlanishlar soni noma’lum bo’lganga, bu funktsiyalardan foydalanish
qo’l keladi. Massiv-ning birinchi elementi nomerini UBound, oxirgi element
nomerini esa LBound funktsi-yalari aniqlab beradi.
Misol:
1: Sub AddUsers ()
2:
Dim Users(10) As String
3:
Dim I As Integer
4:
For i=UBound(Users) To LBound(Users) Step -1
5:
Users(i)=InputBox(“Foydalanuvchi nomini kiriting = “,
“Foydalanuvchi nomi”)
6:
Next i
7: End Sub
‘ UBound, LBound Birinchi va oxirgi elementlari nomerini aniqlash
Ma’lumotlarni tsiklli qayta
ishlash
Umumiy ko’rinishi:
Dim Element As Variant
For Each Element In MassivNomi
‘ Tsikl tanasi
Next Element
Access VBA da massiv elementlarini nomerlash noldan boshlanadi. Demak,
massiv elementlarini n ta desak, unda n+1 ta element bo’ladi. Lekin
Option Base n
(n=0 yoki 1) funktsiya yordamida elementlar sonini 0 yoki 1 dan boshlanishini
dasturning boshlanishida ko’rsatish mumkin.
Exit Do, Exit For buyruqlari yordamida tsiklni to’xtatib, boshqarishni
tsikldan keyingi operatorga boshqarishni o’zatadi.
‘ Option Base n, Exit Do, Exit For
Dastur
yordamida tabliza qurish
Access da tablitsa qurishnin turli usullari mavjud. Masalan Access
interfeysda yoki SQL buyriqlaridan foydalangan holda. Lekin Access VBA da
dastur orqali dinamik holatda ham tablitsa qurish mumkin. Masalan:
1: Sub CreateTable()
2: Const DataBasePath=”d:\Baza\Contacts.mdb”
3: Const ProviderStr=”Provider=Microsoft.Jet.OLEDB.4.0;”+”Data source =
“+DataBasePath
4: Dim Table As New Table
5: Dim Catalog As New ADOX.Catalog
6: Dim Key As New ADOX.Key
7: Catalog.ActiveConnection=ProviderStr
8: Table.Name = “Contacts”
9: Table.ParentCatalog = Catalog
10: TableColumns.Append “ID”, adInteger
11: TableColumns.Append ( “ID” ). Properties ( “AutoIncreement” ) = True
12: TableColumns.Append “First_Name”, adVarWChar, 20
13: TableColumns.Append “Last_Name”, adVarWChar, 20
14: TableColumns.Append “Phone_Nomer”, adVarWChar, 13
15: TableColumns.Append “Email”, adVarWChar, 25
16: TableColumns.Append “WWW”, adVarWChar, 25
17: Catalog.Tables.Append Table
18: Key.Name = “ID”
19: Key Type = adKeyPrimary
20: Key.Columns.Append “ID”
21: Catalog.Tables(“Contacts”).Keys.Append Key, kyPrimary
22: Set Catalog.ActiveConnection = Nothing
23: End Sub
Topshiriq:
O’z variantingiz misoli uchun mos keladigan dasturlar tuzung.