Билеты по информатике 10 класс: Visual Basic

Билет №2

1

Do While L } S выполняется

S }если L-истина

Loop }

Do }S выполняется

S }пока L-истина

Loop While L }

Do }S выполняется

S }вечно, пока не

[exit do] } будет перехода

Loop } к exit do

While L }то же, что и

S }Do while…Loop

Wend }

Do Until L }S выполняется

S }если L-ложь

Loop }

Do }S выполняется

S }пока L-ложь

Loop Until L}

For i=i0 to iк step h}S выполняется

S }пока i0 не дос-

[Exit for] }тигнет значения

Next i }ik. Шаг – h

2

Sub Знаки()

Dim S As String, En As String

Dim nEn As Integer, i As Long

S = InputBox(“Введите текст”)

En = “abcdefghijklmnopqrstuvwxyz”

NEn = 0

For i = 1 To Len(S)

If (InStr(En, Mid(S, i, 1), 1)) > 0 Then

NEn = nEn + 1

End If

Next i

MsgBox (“Кол-во =” + Str(nEn))

End Sub

3

Sub Swap(S As String, i As Long, j As Long)

Dim c As String

C = Mid(S, i, 1)

Mid(S, i, 1) = Mid(S, j, 1)

Mid(S, j, 1) = c

End Sub

Sub шифр()

Dim S As String, Sogl As String

Dim S1 As String, c As String

Dim Gl As String, K As Long

Dim i As Long

Sogl = “аеиоуыэюяе”

S = InputBox(“Ввод строки”)

Gl = “бвгджзклмнпрстфхцчшщъь”

For i = 1 To Len(S)

C = Mid(S, i, 1)

S1 = S1 + c

If InStr(Gl, c) > 0 Then

K = K + 1

If K > Len(Sogl) Then K = 1

S1 = S1 + Mid(Sogl, K, 1)

End If

Next i

For i = 1 To Len(S1) – 5 Step 6

Call Swap(S1, i, i + 5)

Call Swap(S1, i + 2, i + 3)

Call Swap(S1, i + 1, i + 4)

Next i

S = S1

MsgBox (S)

End Sub

4

Sub Раскодировщик()

Dim S As String, i As Long

Dim S1 As String, c As String

Dim Gl As String, K As Long

S = InputBox(“Ввод шифра”)

Gl = “бвгджзклмнпрстфхцчшщъь”

For i = 1 To Len(S) – 5 Step 6

Call Swap(S, i, i + 5)

Call Swap(S, i + 2, i + 3)

Call Swap(S, i + 1, i + 4)

Next i

For i = 1 To Len(S)

C = Mid(S, i, 1)

S1 = S1 + c

If InStr(Gl, c) > 0 Then i = i + 1

Next i

MsgBox (S1)

End Sub

5

Sub Замена()

Dim S As String, S1 As String

Dim n As Long, C As String

Dim Name As String

S = InputBox(“Ввод строки”)

Name = InputBox(“Ввод Имени”)

N = 0

For i = 1 To Len(S)

C = Mid(S, i, 1)

If Mid(S, i, 3) = “Имя” Then

S1 = S1 + Name

n = n + 1

i = i + 2

ElseIf Mid(S, i, 7) = “Фамилия” Then

S1 = S1 + Name

i = i + 6

n = n + 1

Else

S1 = S1 + C

End If

Next i

MsgBox (S1)

MsgBox (n)

End Sub

Билет №3

1

If L then }S выполняется

S }если L – истина

End If }

If L1 then }S1 выполняется

S1 }еслиL1 -истина.

Elseif L2 then }если нет, то про-

S2 }веряется L2 и. т.д

– – – – – – – – }если Ln-не истина

Elseif Ln then }то выполняется

Sn }Sn+1

Else }

Sn+1 }

End if }

2

Sub Знаки( )

Dim S As String, Rus As String

Dim nRus As Integer, i As Long

S = InputBox(“Введите текст”)

Rus = “абвгдежзиклмнопрстуфхцчшщъыьэюяе”

NRus = 0

For i = 1 To Len(S)

If (InStr(Rus, Mid(S, i, 1))) > 0 Then

NRus = nRus + 1

End If

Next i

MsgBox (“Кол-во =” + Str(nRus))

End Sub

3

Sub шифр()

Dim S As String, Sogl As String

Dim S1 As String, c As String

Dim Gl As String, K As Long

Dim i As Long

S = InputBox(“Ввод строки”)

Gl = “аеиоуыэюяе”

For i = 1 To Len(S)

C = Mid(S, i, 1)

S1 = S1 + c

K = K + 1

If K > Len(Gl) Then K = 1

S1 = S1 + Mid(Gl, K, 1)

Next i

For i = 1 To (Len(S1)) / 2

Call Swap(S1, i, Len(S1) – (i – 1))

Next i

S = S1

MsgBox (S)

End Sub

4

Sub шифр()

Dim S As String, Sogl As String

Dim S1 As String, c As String

Dim Gl As String, K As Long

Dim i As Long

S = InputBox(“Ввод шифра”)

For i = 1 To (Len(S)) / 2

Call Swap(S, i, Len(S) – (i – 1))

Next i

For i = 1 To Len(S) Step 2

C = Mid(S, i, 1)

S1 = S1 + c

Next i

S = S1

MsgBox (S)

End Sub

5

Sub Замена()

Dim S As String, S1 As String

Dim n As Long, C As String

S = InputBox(“Ввод строки”)

N = 0

For i = 1 To Len(S)

C = Mid(S, i, 1)

If Mid(S, i, 1) = “&;” Then

S1 = S1 + “имя”

n = n + 1

ElseIf Mid(S, i, 1) = “#” Then

S1 = S1 + “имя”

n = n + 1

Else

S1 = S1 + C

End If

Next i

MsgBox (S1)

MsgBox (n)

End Sub

Билет №4

1

Select Case УСЛ} Если УСЛ равно

Case ЗН1 }ЗН1 то выполня-

S1 }ется S1, если ЗН2

Case ЗН2 }то S2 и т. д. Если

S2 }УСЛ не равно ни

– – – – – – – – }одному из ЗН, то

Case ЗНn }выполняется Sn+1

Sn }

Case Else }

Sn+1 }

End Select }

2

Sub Знаки( )

Dim S As String, Rus As String

Dim nRus As Integer, i As Long

S = InputBox(“Введите текст”)

Rus = “абвгдежзиклмнопрстуфхцчшщъыьэюяе”

NRus = 0

For i = 1 To Len(S)

If (InStr(Rus, Mid(S, i, 1))) > 0 Then

NRus = nRus + 1

End If

Next i

MsgBox (“Кол-во =” + Str(nRus))

End Sub

3

Sub Swap(S As String, i As Long, j As Long)

Dim c As String

c = Mid(S, i, 1)

Mid(S, i, 1) = Mid(S, j, 1)

Mid(S, j, 1) = c

End Sub

Sub шифр( )

Dim S As String, Sh As String

Dim S1 As String, c As String

Dim Gl As String, K As Long

Dim i As Long

Sh = “Шаблон”

S = InputBox(“Ввод строки”)

Gl = “аеиоуыэюяе”

For i = 1 To Len(S)

c = Mid(S, i, 1)

S1 = S1 + c

If InStr(Gl, c) > 0 Then

K = K + 1

If K > Len(Sh) Then K = 1

S1 = S1 + Mid(Sh, K, 1)

End If

Next i

For i = 1 To (Len(S1)) / 2

Call Swap(S1, i, Len(S1) – (i – 1))

Next i

S = S1

MsgBox (S)

End Sub

4

Sub шифр()

Dim S As String, Sh As String

Dim S1 As String, c As String

Dim Gl As String, K As Long

Dim i As Long

Sh = “Шаблон”

S = InputBox(“Ввод строки”)

Gl = “аеиоуыэюяе”

For i = 1 To (Len(S1)) / 2

Call Swap(S1, i, Len(S1) – (i – 1))

Next i

For i = 1 To Len(S)

C = Mid(S, i, 1)

S1 = S1 + c

If InStr(Gl, c) > 0 Then

I = i + 1

End If

Next i

S = S1

MsgBox (S)

End Sub

5

Sub Замена()

Dim S As String, S1 As String

Dim n As Long, C As String

S = InputBox(“Ввод строки”)

N = 0

For i = 1 To Len(S)

C = Mid(S, i, 1)

If Mid(S, i, 1) = “#” Then

S1 = S1 + “Имя”

I = i + 2

N = n + 1

ElseIf Mid(S, i, 3) = “Имя” Then

S1 = S1 + “#”

I = i + 2

N = n + 1

Else

S1 = S1 + C

End If

Next i

MsgBox (S1)

MsgBox (n)

End Sub

Билет №5

1

Операторы описания типов переменных

DIM-описывает переменные и выделяет для них память.

Dim String as Type

String – имя переменной

Type – описание переменной

ОписаниеРазмерТип данныхДиапазон
ByteЦелое число0-255
IntegerЦелое число

+ 32768

LongЦелое число

+ 2 млрд.

DoubleВеществ.

+10+304

StringLen(String)Символы0-~64000
BooleanTrue/False1;0
Variant16бПроизвольнПроизв.

2

Sub Знаки( )

Dim S As String, Pr As String

Dim nPr As Integer, i As Long

S = InputBox(“Введите текст”)

Pr = “,.?!:;”

nPr = 0

For i = 1 To Len(S)

If (InStr(Pr, Mid(S, i, 1))) > 0 Then

nPr = nPr + 1

End If

Next i

MsgBox (“Кол-во =” + Str(nPr))

End Sub

3

Sub Swap(S As String, i As Long, j As Long)

Dim c As String

c = Mid(S, i, 1)

Mid(S, i, 1) = Mid(S, j, 1)

Mid(S, j, 1) = c

End Sub

Sub шифр( )

Dim S As String, Sh As String

Dim S1 As String, c As String

Dim Gl As String, K As Long

Dim i As Long

Sh = “Шаблон”

S = InputBox(“Ввод строки”)

Gl = “аеиоуыэюяе”

For i = 1 To Len(S)

c = Mid(S, i, 1)

S1 = S1 + c

If InStr(Gl, c) > 0 Then

K = K + 1

If K > Len(Sh) Then K = 1

S1 = S1 + Mid(Sh, K, 1)

End If

Next i

For i = 1 To Len(S1) – 1 Step 2

Call Swap(S1, i, i + 1)

Next i

For i = 1 To Len(S1) – 2 Step 3

Call Swap(S1, i, i + 2)

Next i

S = S1

MsgBox (S)

End Sub

4

Sub Раскодировщик( )

Dim S As String, i As Long

Dim S1 As String, c As String

Dim Gl As String, K As Long

S = InputBox(“Ввод шифра”)

Gl = “аеиоуыэюяе”

For i = 1 To Len(S) – 2 Step 3

Call Swap(S, i, i + 2)

Next i

For i = 1 To Len(S) – 1 Step 2

Call Swap(S, i, i + 1)

Next i

For i = 1 To Len(S)

c = Mid(S, i, 1)

S1 = S1 + c

If InStr(Gl, c) > 0 Then i = i + 1

Next i

MsgBox (S1)

End Sub

5

Sub Замена()

Dim S As String, S1 As String

Dim n As Long, C As String

S = InputBox(“Ввод строки”)

n = 0

For i = 1 To Len(S)

C = Mid(S, i, 1)

If Mid(S, i, 1) = “&;” Then

S1 = S1 + “Фамилия”

n = n + 1

ElseIf Mid(S, i, 3) = “Имя” Then

S1 = S1 + “Фамилия”

i = i + 2

n = n + 1

Else

S1 = S1 + C

End If

Next i

MsgBox (S1)

MsgBox (n)

End Sub

Билет №6

1 Array(Список)

Возвращает значение типа Variant,

Содержащее массив

Пример:

Dim m as Variant

M=Array(1,7,-1,2,3)

M(0)=1

M(1)=7

M(2)=-1

M(3)=2

M(4)=3

2

Sub Знаки( )

Dim S As String, Pr As String

Dim nPr As Integer, i As Long

S = InputBox(“Введите текст”)

Pr = “,.?!:;”

nPr = 0

For i = 1 To Len(S)

If (InStr(Pr, Mid(S, i, 1))) > 0 Then

nPr = nPr + 1

End If

Next i

MsgBox (“Кол-во =” + Str(nPr))

End Sub

3

Sub Swap(S As String, i As Long, j As Long)

Dim C As String

C = Mid(S, i, 1)

Mid(S, i, 1) = Mid(S, j, 1)

Mid(S, j, 1) = C

End Sub

Sub шифр()

Dim S As String, Sh As String

Dim S1 As String, c As String

Dim Gl As String, K As Long

Dim i As Long

Sh = “Шаблон”

S = InputBox(“Ввод строки”)

Gl = “бвгджзклмнпрстфхцчшщъь”

For i = 1 To Len(S)

C = Mid(S, i, 1)

S1 = S1 + c

If InStr(Gl, c) > 0 Then

K = K + 1

If K > Len(Sh) Then K = 1

S1 = S1 + Mid(Sh, K, 1)

End If

Next i

For i = 1 To Len(S1) – 3 Step 4

Call Swap(S1, i, i + 3)

Call Swap(S1, i + 1, i + 2)

Next i

S = S1

MsgBox (S)

End Sub

4

Sub Раскодировщик()

Dim S As String, i As Long

Dim S1 As String, c As String

Dim Gl As String, K As Long

S = InputBox(“Ввод шифра”)

Gl = “бвгджзклмнпрстфхцчшщъь”

For i = 1 To Len(S) – 3 Step 4

Call Swap(S, i, i + 3)

Call Swap(S, i + 1, i + 2)

Next i

For i = 1 To Len(S)

C = Mid(S, i, 1)

S1 = S1 + c

If InStr(Gl, c) > 0 Then i = i + 1

Next i

MsgBox (S1)

End Sub

Билет №1

1

Len (String)-Возвращает длину

Строки String

Left (String, Length)-Возвращает левые

Length символов строки String

Right (String, Length)-Возвращает правые

Length символов строки String

Mid (String, Start[,Length] )-Возвращает

Length символов из строк String,

Начиная с символа с номером Start

Trim(String)-Убирает начальные и конеч-

Ные пробелы в строке String

Ltrim(String)-Убирает начальные

пробелы в строке String

Rtrim(String)-Убирает конечные

пробелы в строке String

InStr ([Start,] String, String1[,Comp] )-Возв-

Ращает позицию первого вхождения

String1 в строку String

2

Sub Знаки( )

Dim S As String, Num As String

Dim nNum As Integer, i As Long

S = InputBox(“Введите текст”)

Num = “0123456789”

NNum = 0

For i = 1 To Len(S)

If (InStr(Num, Mid(S, i, 1))) > 0 Then

NNum = nNum + 1

End If

Next i

MsgBox (“Кол-во =” + Str(nNum))

End Sub

3

Sub Swap(S As String, i As Long, j As Long)

Dim C As String

C = Mid(S, i, 1)

Mid(S, i, 1) = Mid(S, j, 1)

Mid(S, j, 1) = C

End Sub

Sub шифр( )

Dim S As String, Sogl As String

Dim S1 As String, c As String

Dim Gl As String, K As Long

Dim i As Long

Sogl = “бвгджзклмнпрстфхцчшщъь”

S = InputBox(“Ввод строки”)

Gl = “аеиоуыэюяе”

For i = 1 To Len(S)

C = Mid(S, i, 1)

S1 = S1 + c

If InStr(Gl, c) > 0 Then

K = K + 1

If K > Len(Sogl) Then K = 1

S1 = S1 + Mid(Sogl, K, 1)

End If

Next i

For i = 1 To Len(S1) – 4 Step 5

Call Swap(S1, i, i + 4)

Call Swap(S1, i + 1, i + 3)

Next i

S = S1

MsgBox (S)

End Sub

4

Sub Раскодировщик()

Dim S As String, i As Long

Dim S1 As String, c As String

Dim Gl As String, K As Long

S = InputBox(“Ввод шифра”)

Gl = “аеиоуыэюяе”

For i = 1 To Len(S) – 4 Step 5

Call Swap(S, i, i + 4)

Call Swap(S, i + 1, i + 3)

Next i

For i = 1 To Len(S)

C = Mid(S, i, 1)

S1 = S1 + c

If InStr(Gl, c) > 0 Then i = i + 1

Next i

MsgBox (S1)

End Sub

5

Sub Замена( )

Dim S As String, S1 As String

Dim n As Long, C As String

S = InputBox(“Ввод строки”)

N = 0

For i = 1 To Len(S)

C = Mid(S, i, 1)

If Mid(S, i, 3) = “Имя” Then

S1 = S1 + “Фамилия Имя Отчество”

n = n + 1

i = i + 2

ElseIf Mid(S, i, 7) = “Фамилия” Then

S1 = S1 + “Фамилия Имя Отчество”

i = i + 6

n = n + 1

Else

S1 = S1 + C

End If

Next i

MsgBox (S1)

MsgBox (n)

End Sub


Билеты по информатике 10 класс: Visual Basic