Билеты по информатике 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=i>0> to i> step h}S выполняется

S }пока i>0> не дос-

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

Next i }i>k >.Шаг – 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 L>1 >then }S1 выполняется

S>1 >}если> >L1 –истина.

Elseif L>2 >then }если нет, то про-

S>2 >}веряется L2 и.т.д

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

Elseif L>n >then }то выполняется

S>n >}Sn+1

Else }

S>n+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

String

Len(String)

Символы

0-~64000

Boolean

True/False

1;0

Variant

16б

Произвольн

Произв.

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>