Справочник Жаркова по проектированию и программированию искусственного интеллекта. Том 5: Программирование искусственного интеллекта на Visual Basic (продолжение 1)

Tekst
0
Recenzje
Przeczytaj fragment
Oznacz jako przeczytane
Czcionka:Mniejsze АаWiększe Aa

19.2. Создание проекта

Создаём проект по обычной схеме: в VS в панели New Project в окне Project types выбираем тип проекта Visual Basic, Windows, в окне Templates выделяем шаблон Windows Forms Application, в окне Name записываем любое имя проекта, например, HangMan и щёлкаем OK. Создаётся проект, появляется форма Form1 на экране в режиме проектирования (рис. 19.15). Оставляем по умолчанию или проектируем форму, как подробно описано в параграфе “Методика проектирования формы”. Например, в панели Properties в свойстве Font выбираем шрифт Times New Roman, 14, Bold.

C панели инструментов Toolbox переносим на форму (слева направо и сверху вниз) следующие элементы управления.

Надпись Label с любым именем Name (т.к. это имя не будет использоваться в программе) и текстом “1. Запишите слово:”.

Окно текста TextBox, для которого в панели Properties: записываем имя Name = Word_in, ограничиваем количество букв двадцатью MaxLenght = 20, скрываем буквы слова за звёздочками (как пароль) PasswordChar = *.

Надпись Label с любым именем Name (т.к. это имя не будет использоваться в программе) и текстом “2. Щёлкните:”.

Кнопка Button, для которой в панели Properties записываем имя Name = Done и текст Text = Старт.

Надпись LinkLabel, для которой в панели Properties записываем имя Name = check_answer (проверка ответа) и текст Text = Проверка.

Двадцать надписей Label, для которых в панели Properties записываем имена Name = Chr1, Chr2, Chr3, …, Chr20 (эти имена будут использоваться в программе) и текст Text во всех надписях – в виде символа подчёркивания “_”.


Рис. 19.15. Форма Form1 в режиме проектирования.

Двадцать надписей Label, для которых в панели Properties записываем имена Name = dash1, dash2, dash3, …, dash20 (эти имена будут использоваться в программе) и текст Text во всех надписях – в виде символа подчёркивания “_”.

Надпись Label с любым именем Name (т.к. это имя не будет использоваться в программе) и текстом “Таблица для 10 допустимых неправильных букв:”.

Ниже последней надписи проектируем таблицу из двух горизонтальных и трёх вертикальных линий из элементов управления типа PictureBox, для которых в панели Properties в свойстве BackColor выбираем чёрный цвет, например, ControlText.

В двенадцати ячейках этой таблицы размещаем двенадцать надписей Label, для которых в панели Properties записываем имена Name = f_chr1, f_chr2, f_chr3, …, f_chr12 (эти имена будут использоваться в программе) и без текста Text во всех первых 11 надписях. Чтобы выделить 11 ошибочных букв в этих 11 ячейках, в свойстве ForeColor этих 11 надписей задаём красный цвет Red. Только в последней надписи с именем Name = f_chr12 в свойстве Text записываем какой-либо символ, например, символ подчёркивания “_”, а в свойстве BackColor выбираем чёрный цвет, например, ControlText (тем самым, выделяя чёрный прямоугольник этой ячейки, как показано на рисунке).

Надпись Label с любым именем Name (т.к. это имя не будет использоваться в программе) и текстом “3. Угадывайте буквы слова:”.

Двадцать шесть (по числу букв в английском алфавите) кнопок Button, для которых в панели Properties записываем имена для букв английского алфавита, Name = A, B, C, D, Er, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z (эти имена будут использоваться в программе) и текст Text, соответствующий этим буквам (как показано на рисунке). Напомним, что язык Visual Basic нечувствителен к регистру букв, и строчную букву “e”, и прописную букву “E” этот язык воспринимает одинаково. Поэтому, чтобы не было конфликта имени “e”, как объекта класса System.EventArgs в параметре метода-обработчика щелчка кнопки, и имени кнопки Name = E, выше мы записали имя кнопки Name = Er.

На форме справа размещаем графический элемент управления PictureBox, для которого в панели Properties записываем имя Name = effects. За маркеры увеличиваем размеры элемента до Size = 125; 314. На этом элементе размещаем рисунок человечка (пока без головы) по стандартной схеме: в панели Properties (для этого элемента) в свойстве Image (рис. 19.16) щёлкаем кнопку с тремя точками, в появившейся панели Select Resource выбираем переключатель Local resource, щёлкаем кнопку Import, в появившейся панели Open находим (например, в папке с загруженными из Интернета файлами) и выделяем графический файл 2.jpg и щёлкаем кнопку Open (или дважды щёлкаем по имени этого файла). Отображение этого файла мы увидим на элементе PictureBox (см. рисунок).



Рис. 19.16. Панели SE и Properties.

Теперь на предыдущем элементе управления PictureBox на месте, где должна находиться голова человечка, размещаем следующий элемент управления PictureBox, для которого в панели Properties записываем или устанавливаем следующие свойства: Name = pic_sad, BackColor = ControlLightLight, SizeMode = StretchImage, Visible = False. За маркеры устанавливаем размеры элемента Size = 58; 46. На этом элементе размещаем рисунок хмурой головы человечка (типа смайлика) по стандартной схеме: в панели Properties (для этого элемента) в свойстве Image щёлкаем кнопку с тремя точками, в появившейся панели Select Resource выбираем переключатель Local resource, щёлкаем кнопку Import, в появившейся панели Open находим (например, в папке с загруженными из Интернета файлами) и выделяем графический файл sad_face.jpg и щёлкаем кнопку Open (или дважды щёлкаем по имени этого файла). Отображение этого файла мы увидим на элементе PictureBox.

На том же элементе управления PictureBox на месте, где должна находиться голова человечка, размещаем следующий элемент управления PictureBox, для которого в панели Properties записываем или устанавливаем следующие свойства: Name = pic_happy, BackColor = ControlLightLight, SizeMode = StretchImage, Visible = False. За маркеры устанавливаем размеры элемента Size = 58; 46. На этом элементе размещаем рисунок веселой головы человечка (типа смайлика) по стандартной схеме: в панели Properties (для этого элемента) в свойстве Image щёлкаем кнопку с тремя точками, в появившейся панели Select Resource выбираем переключатель Local resource, щёлкаем кнопку Import, в появившейся панели Open находим (например, в папке с загруженными из Интернета файлами) и выделяем графический файл happy_face.jpg и щёлкаем кнопку Open (или дважды щёлкаем по имени этого файла). Отображение этого файла мы увидим на элементе PictureBox (см. рисунок).

Два последних элемента управления PictureBox со смайликами накладываем один на другого на месте головы нарисованного человечка. А программа будет показывать нам либо хмурый смайлик (при неправильной букве), либо веселый смайлик (при правильной букве).

Напомним, что, растягивая за маркеры элемент PictureBox, при помощи свойства SizeMode = StretchImage мы можем растягивать голову человечка на всю площадь этого элемента так, чтобы было посмешнее.

Переносим на форму элемент управления MenuStrip – выпадающее меню для команд и опций, сгруппированных по функциональности. Щёлкаем по этому элементу menuStrip1, расположенному ниже формы Form1 в режиме проектирования. На форме Form1 появляются окна с надписью Type Here (Печатайте здесь), в которые записываем команды на английском языке (приведённые далее в программе): Game, New Game, Exit; Help, How to, About. Теперь в панели Properties (для каждой команды этого элемента управления) в свойстве Text изменяем эти английские команды на русские, согласно рис. 19.17 – 19.18.





Рис. 19.17. Команды левого меню. Рис. 19.18. Команды правого меню.

Если в игре применяются звуковые файлы, то их целесообразно разместить в одной папке с именем, например, Sounds. Для добавления в проект этой папки, в панели Solution Explorer выполняем правый щелчок по имени проекта, в контекстном меню выбираем Add, New Folder, в поле появившегося значка папки записываем имя папки и нажимаем клавишу Enter. Добавляем в эту папку звуковые файлы по стандартной схеме: выполняем правый щелчок по имени этой папки, в контекстном меню выбираем Add, Existing Item, в панели Add Existing Item в окне “Files of type” выбираем “All Files”, в центральном окне находим (например, в папке с загруженными из Интернета файлами) и с нажатой клавишей Ctrl выделяем имена файлов и щёлкаем кнопку Add. В панели Solution Explorer мы увидим эти файлы (см. рисунок выше).

Для ввода в проект новой формы (для правил игры) в меню Project выбираем Add Windows Form, в панели Add New Item оставляем заданные по умолчанию параметры и щёлкаем кнопку Add. В ответ VS выводит новую форму Form2 и добавляет в панель Solution Explorer новый пункт Form2.vb. Аналогично, как первую, проектируем вторую форму (рис. 19.18), за маркеры увеличиваем форму до размеров Size (420; 420). Вводим на эту форму элемент управления в виде окна TextBox, для которого в панели Properties в свойстве Multiline выбираем значение True (для многострочного текста). Ниже размещаем кнопку Button со свойством Text = Выход.



Рис. 19.18.

Форма Form2.

19.3. Код и запуск программы


Открываем файл Form1.vb (например, по схеме: File, Open, File) и в классе Form1 записываем следующие переменные и методы.

Листинг 19.1. Переменные и методы.

'Массив для загадываемого слова из 20 (и менее) букв

'с индексами 0,1,2,3,…,19:

Dim str(19) As String

Dim nums As Integer

На первой форме Form1 в режиме проектирования дважды щёлкаем по кнопке Button с именем для первой буквы используемого в данной игре английского алфавита Name = A (или в панели Properties для этого элемента на вкладке Events дважды щёлкаем по имени соответствующего события).

 

Появившийся шаблон метода после записи нашего кода принимает следующий вид.

Листинг 19.2. Метод-обработчик щелчка кнопки.

Private Sub A_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles A.Click

A.Enabled = False

nums = Len(Word_in.Text)

Try

str(0) = Mid(Word_in.Text, nums, 1)

str(1) = Mid(Word_in.Text, nums – 1, 1)

str(2) = Mid(Word_in.Text, nums – 2, 1)

str(3) = Mid(Word_in.Text, nums – 3, 1)

str(4) = Mid(Word_in.Text, nums – 4, 1)

str(5) = Mid(Word_in.Text, nums – 5, 1)

str(6) = Mid(Word_in.Text, nums – 6, 1)

str(7) = Mid(Word_in.Text, nums – 7, 1)

str(8) = Mid(Word_in.Text, nums – 8, 1)

str(9) = Mid(Word_in.Text, nums – 9, 1)

str(10) = Mid(Word_in.Text, nums – 10, 1)

str(11) = Mid(Word_in.Text, nums – 11, 1)

str(12) = Mid(Word_in.Text, nums – 12, 1)

str(13) = Mid(Word_in.Text, nums – 13, 1)

str(14) = Mid(Word_in.Text, nums – 14, 1)

str(15) = Mid(Word_in.Text, nums – 15, 1)

str(16) = Mid(Word_in.Text, nums – 16, 1)

str(17) = Mid(Word_in.Text, nums – 17, 1)

str(18) = Mid(Word_in.Text, nums – 18, 1)

str(19) = Mid(Word_in.Text, nums – 19, 1)

Catch ex As Exception

End Try

If Word_in.TextLength = 1 Then

If str(0) = "a" Then

Chr1.Text = "A"

End If

ElseIf Word_in.TextLength = 2 Then

If str(1) = "a" Then

Chr1.Text = "A"

End If

If str(0) = "a" Then

Chr2.Text = "A"

End If

ElseIf Word_in.TextLength = 3 Then

If str(0) = "a" Then

Chr3.Text = "A"

End If

If str(1) = "a" Then

Chr2.Text = "A"

End If

If str(2) = "a" Then

Chr1.Text = "A"

End If

ElseIf Word_in.TextLength = 4 Then

If str(0) = "a" Then

Chr4.Text = "A"

End If

If str(1) = "a" Then

Chr3.Text = "A"

End If

If str(2) = "a" Then

Chr2.Text = "A"

End If

If str(3) = "a" Then

Chr1.Text = "A"

End If

ElseIf Word_in.TextLength = 5 Then

If str(0) = "a" Then

Chr5.Text = "A"

End If

If str(1) = "a" Then

Chr4.Text = "A"

End If

If str(2) = "a" Then

Chr3.Text = "A"

End If

If str(3) = "a" Then

Chr2.Text = "A"

End If

If str(4) = "a" Then

Chr1.Text = "A"

End If

ElseIf Word_in.TextLength = 6 Then

If str(0) = "a" Then

Chr6.Text = "A"

End If

If str(1) = "a" Then

Chr5.Text = "A"

End If

If str(2) = "a" Then

Chr4.Text = "A"

End If

If str(3) = "a" Then

Chr3.Text = "A"

End If

If str(4) = "a" Then

Chr2.Text = "A"

End If

If str(5) = "a" Then

Chr1.Text = "A"

End If

ElseIf Word_in.TextLength = 7 Then

If str(0) = "a" Then

Chr7.Text = "A"

End If

If str(1) = "a" Then

Chr6.Text = "A"

End If

If str(2) = "a" Then

Chr5.Text = "A"

End If

If str(3) = "a" Then

Chr4.Text = "A"

End If

If str(4) = "a" Then

Chr3.Text = "A"

End If

If str(5) = "a" Then

Chr2.Text = "A"

End If

If str(6) = "a" Then

Chr1.Text = "A"

End If

ElseIf Word_in.TextLength = 8 Then

If str(0) = "a" Then

Chr8.Text = "A"

End If

If str(1) = "a" Then

Chr7.Text = "A"

End If

If str(2) = "a" Then

Chr6.Text = "A"

End If

If str(3) = "a" Then

Chr5.Text = "A"

End If

If str(4) = "a" Then

Chr4.Text = "A"

End If

If str(5) = "a" Then

Chr3.Text = "A"

End If

If str(6) = "a" Then

Chr2.Text = "A"

End If

If str(7) = "a" Then

Chr1.Text = "A"

End If

ElseIf Word_in.TextLength = 9 Then

If str(0) = "a" Then

Chr9.Text = "A"

End If

If str(1) = "a" Then

Chr8.Text = "A"

End If

If str(2) = "a" Then

Chr7.Text = "A"

End If

If str(3) = "a" Then

Chr6.Text = "A"

End If

If str(4) = "a" Then

Chr5.Text = "A"

End If

If str(5) = "a" Then

Chr4.Text = "A"

End If

If str(6) = "a" Then

Chr3.Text = "A"

End If

If str(7) = "a" Then

Chr2.Text = "A"

End If

If str(8) = "a" Then

Chr1.Text = "A"

End If

ElseIf Word_in.TextLength = 10 Then

If str(0) = "a" Then

Chr10.Text = "A"

End If

If str(1) = "a" Then

Chr9.Text = "A"

End If

If str(2) = "a" Then

Chr8.Text = "A"

End If

If str(3) = "a" Then

Chr7.Text = "A"

End If

If str(4) = "a" Then

Chr6.Text = "A"

End If

If str(5) = "a" Then

Chr5.Text = "A"

End If

If str(6) = "a" Then

Chr4.Text = "A"

End If

If str(7) = "a" Then

Chr3.Text = "A"

End If

If str(8) = "a" Then

Chr2.Text = "A"

End If

If str(9) = "a" Then

Chr1.Text = "A"

End If

ElseIf Word_in.TextLength = 11 Then

If str(0) = "a" Then

Chr11.Text = "A"

End If

If str(1) = "a" Then

Chr10.Text = "A"

End If

If str(2) = "a" Then

Chr9.Text = "A"

End If

If str(3) = "a" Then

Chr8.Text = "A"

End If

If str(4) = "a" Then

Chr7.Text = "A"

End If

If str(5) = "a" Then

Chr6.Text = "A"

End If

If str(6) = "a" Then

Chr5.Text = "A"

End If

If str(7) = "a" Then

Chr4.Text = "A"

End If

If str(8) = "a" Then

Chr3.Text = "A"

End If

If str(9) = "a" Then

Chr2.Text = "A"

End If

If str(10) = "a" Then

Chr1.Text = "A"

End If

ElseIf Word_in.TextLength = 12 Then

If str(0) = "a" Then

Chr12.Text = "A"

End If

If str(1) = "a" Then

Chr11.Text = "A"

End If

If str(2) = "a" Then

Chr10.Text = "A"

End If

If str(3) = "a" Then

Chr9.Text = "A"

End If

If str(4) = "a" Then

Chr8.Text = "A"

End If

If str(5) = "a" Then

Chr7.Text = "A"

End If

If str(6) = "a" Then

Chr6.Text = "A"

End If

If str(7) = "a" Then

Chr5.Text = "A"

End If

If str(8) = "a" Then

Chr4.Text = "A"

End If

If str(9) = "a" Then

Chr3.Text = "A"

End If

If str(10) = "a" Then

Chr2.Text = "A"

End If

If str(11) = "a" Then

Chr1.Text = "A"

End If

ElseIf Word_in.TextLength = 13 Then

If str(0) = "a" Then

Chr13.Text = "A"

End If

If str(1) = "a" Then

Chr12.Text = "A"

End If

If str(2) = "a" Then

Chr11.Text = "A"

End If

If str(3) = "a" Then

Chr10.Text = "A"

End If

If str(4) = "a" Then

Chr9.Text = "A"

End If

If str(5) = "a" Then

Chr8.Text = "A"

End If

If str(6) = "a" Then

Chr7.Text = "A"

End If

If str(7) = "a" Then

Chr6.Text = "A"

End If

If str(8) = "a" Then

Chr5.Text = "A"

End If

If str(9) = "a" Then

Chr4.Text = "A"

End If

If str(10) = "a" Then

Chr3.Text = "A"

End If

If str(11) = "a" Then

Chr2.Text = "A"

End If

If str(12) = "a" Then

Chr1.Text = "A"

End If

ElseIf Word_in.TextLength = 14 Then

If str(0) = "a" Then

Chr14.Text = "A"

End If

If str(1) = "a" Then

Chr13.Text = "A"

End If

If str(2) = "a" Then

Chr12.Text = "A"

End If

If str(3) = "a" Then

Chr11.Text = "A"

End If

If str(4) = "a" Then

Chr10.Text = "A"

End If

If str(5) = "a" Then

Chr9.Text = "A"

End If

If str(6) = "a" Then

Chr8.Text = "A"

End If

If str(7) = "a" Then

Chr7.Text = "A"

End If

If str(8) = "a" Then

Chr6.Text = "A"

End If

If str(9) = "a" Then

Chr5.Text = "A"

End If

If str(10) = "a" Then

Chr4.Text = "A"

End If

If str(11) = "a" Then

Chr3.Text = "A"

End If

If str(12) = "a" Then

Chr2.Text = "A"

End If

If str(13) = "a" Then

Chr1.Text = "A"

End If

ElseIf Word_in.TextLength = 15 Then

If str(0) = "a" Then

Chr15.Text = "A"

End If

If str(1) = "a" Then

Chr14.Text = "A"

End If

If str(2) = "a" Then

Chr13.Text = "A"

End If

If str(3) = "a" Then

Chr12.Text = "A"

End If

If str(4) = "a" Then

Chr11.Text = "A"

End If

If str(5) = "a" Then

Chr10.Text = "A"

End If

If str(6) = "a" Then

Chr9.Text = "A"

End If

If str(7) = "a" Then

Chr8.Text = "A"

End If

If str(8) = "a" Then

Chr7.Text = "A"

End If

If str(9) = "a" Then

Chr6.Text = "A"

End If

If str(10) = "a" Then

Chr5.Text = "A"

End If

If str(11) = "a" Then

Chr4.Text = "A"

End If

If str(12) = "a" Then

Chr3.Text = "A"

End If

If str(13) = "a" Then

Chr2.Text = "A"

End If

If str(14) = "a" Then

Chr1.Text = "A"

End If

ElseIf Word_in.TextLength = 16 Then

If str(0) = "a" Then

Chr16.Text = "A"

End If

If str(1) = "a" Then

Chr15.Text = "A"

End If

If str(2) = "a" Then

Chr14.Text = "A"

End If

If str(3) = "a" Then

Chr13.Text = "A"

End If

If str(4) = "a" Then

Chr12.Text = "A"

End If

If str(5) = "a" Then

Chr11.Text = "A"

End If

If str(6) = "a" Then

Chr10.Text = "A"

End If

If str(7) = "a" Then

Chr9.Text = "A"

End If

If str(8) = "a" Then

Chr8.Text = "A"

End If

If str(9) = "a" Then

Chr7.Text = "A"

End If

If str(10) = "a" Then

Chr6.Text = "A"

End If

If str(11) = "a" Then

Chr5.Text = "A"

End If

If str(12) = "a" Then

Chr4.Text = "A"

End If

If str(13) = "a" Then

Chr3.Text = "A"

End If

If str(14) = "a" Then

Chr2.Text = "A"

End If

If str(15) = "a" Then

Chr1.Text = "A"

End If

ElseIf Word_in.TextLength = 17 Then

If str(0) = "a" Then

Chr17.Text = "A"

End If

If str(1) = "a" Then

Chr16.Text = "A"

End If

If str(2) = "a" Then

Chr15.Text = "A"

End If

If str(3) = "a" Then

Chr14.Text = "A"

End If

If str(4) = "a" Then

Chr13.Text = "A"

End If

If str(5) = "a" Then

Chr12.Text = "A"

End If

If str(6) = "a" Then

Chr11.Text = "A"

End If

If str(7) = "a" Then

Chr10.Text = "A"

End If

If str(8) = "a" Then

Chr9.Text = "A"

End If

If str(9) = "a" Then

Chr8.Text = "A"

End If

If str(10) = "a" Then

Chr7.Text = "A"

End If

If str(11) = "a" Then

Chr6.Text = "A"

End If

If str(12) = "a" Then

Chr5.Text = "A"

End If

If str(13) = "a" Then

Chr4.Text = "A"

End If

If str(14) = "a" Then

Chr3.Text = "A"

End If

If str(15) = "a" Then

Chr2.Text = "A"

End If

If str(16) = "a" Then

Chr1.Text = "A"

End If

ElseIf Word_in.TextLength = 18 Then

If str(0) = "a" Then

Chr18.Text = "A"

End If

If str(1) = "a" Then

Chr17.Text = "A"

End If

If str(2) = "a" Then

Chr16.Text = "A"

End If

If str(3) = "a" Then

Chr15.Text = "A"

End If

If str(4) = "a" Then

Chr14.Text = "A"

End If

If str(5) = "a" Then

Chr13.Text = "A"

End If

If str(6) = "a" Then

Chr12.Text = "A"

End If

If str(7) = "a" Then

Chr11.Text = "A"

End If

If str(8) = "a" Then

Chr10.Text = "A"

End If

If str(9) = "a" Then

Chr9.Text = "A"

 

End If

If str(10) = "a" Then

Chr8.Text = "A"

End If

If str(11) = "a" Then

Chr7.Text = "A"

End If

If str(12) = "a" Then

Chr6.Text = "A"

End If

If str(13) = "a" Then

Chr5.Text = "A"

End If

If str(14) = "a" Then

Chr4.Text = "A"

End If

If str(15) = "a" Then

Chr3.Text = "A"

End If

If str(16) = "a" Then

Chr2.Text = "A"

End If

If str(17) = "a" Then

Chr1.Text = "A"

End If

ElseIf Word_in.TextLength = 19 Then

If str(0) = "a" Then

Chr19.Text = "A"

End If

If str(1) = "a" Then

Chr18.Text = "A"

End If

If str(2) = "a" Then

Chr17.Text = "A"

End If

If str(3) = "a" Then

Chr16.Text = "A"

End If

If str(4) = "a" Then

Chr15.Text = "A"

End If

If str(5) = "a" Then

Chr14.Text = "A"

End If

If str(6) = "a" Then

Chr13.Text = "A"

End If

If str(7) = "a" Then

Chr12.Text = "A"

End If

If str(8) = "a" Then

Chr11.Text = "A"

End If

If str(9) = "a" Then

Chr10.Text = "A"

End If

If str(10) = "a" Then

Chr9.Text = "A"

End If

If str(11) = "a" Then

Chr8.Text = "A"

End If

If str(12) = "a" Then

Chr7.Text = "A"

End If

If str(13) = "a" Then

Chr6.Text = "A"

End If

If str(14) = "a" Then

Chr5.Text = "A"

End If

If str(15) = "a" Then

Chr4.Text = "A"

End If

If str(16) = "a" Then

Chr3.Text = "A"

End If

If str(17) = "a" Then

Chr2.Text = "A"

End If

If str(18) = "a" Then

Chr1.Text = "A"

End If

ElseIf Word_in.TextLength = 20 Then

If str(0) = "a" Then

Chr20.Text = "A"

End If

If str(1) = "a" Then

Chr19.Text = "A"

End If

If str(2) = "a" Then

Chr18.Text = "A"

End If

If str(3) = "a" Then

Chr17.Text = "A"

End If

If str(4) = "a" Then

Chr16.Text = "A"

End If

If str(5) = "a" Then

Chr15.Text = "A"

End If

If str(6) = "a" Then

Chr14.Text = "A"

End If

If str(7) = "a" Then

Chr13.Text = "A"

End If

If str(8) = "a" Then

Chr12.Text = "A"

End If

If str(9) = "a" Then

Chr11.Text = "A"

End If

If str(10) = "a" Then

Chr10.Text = "A"

End If

If str(11) = "a" Then

Chr9.Text = "A"

End If

If str(12) = "a" Then

Chr8.Text = "A"

End If

If str(13) = "a" Then

Chr7.Text = "A"

End If

If str(14) = "a" Then

Chr6.Text = "A"

End If

If str(15) = "a" Then

Chr5.Text = "A"

End If

If str(16) = "a" Then

Chr4.Text = "A"

End If

If str(17) = "a" Then

Chr3.Text = "A"

End If

If str(18) = "a" Then

Chr2.Text = "A"

End If

If str(19) = "a" Then

Chr1.Text = "A"

End If

End If

If InStr(Word_in.Text, "a", CompareMethod.Text) = 0 Then

If f_chr1.Text = "" Then

f_chr1.Text = "A"

ElseIf f_chr2.Text = "" Then

f_chr2.Text = "A"

ElseIf f_chr3.Text = "" Then

f_chr3.Text = "A"

ElseIf f_chr4.Text = "" Then

f_chr4.Text = "A"

ElseIf f_chr5.Text = "" Then

f_chr5.Text = "A"

ElseIf f_chr6.Text = "" Then

f_chr6.Text = "A"

ElseIf f_chr7.Text = "" Then

f_chr7.Text = "A"

ElseIf f_chr8.Text = "" Then

f_chr8.Text = "A"

ElseIf f_chr9.Text = "" Then

f_chr9.Text = "A"

ElseIf f_chr10.Text = "" Then

f_chr10.Text = "A"

ElseIf f_chr11.Text = "" Then

f_chr11.Text = "A"

End If

End If

End Sub

Дважды щёлкаем по кнопке Button с именем для 2-й буквы алфавита Name = B. Появившийся шаблон метода после записи нашего кода принимает следующий вид.

Листинг 19.3. Метод-обработчик щелчка кнопки.

Private Sub B_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles B.Click

B.Enabled = False

nums = Len(Word_in.Text)

Try

str(0) = Mid(Word_in.Text, nums, 1)

str(1) = Mid(Word_in.Text, nums – 1, 1)

str(2) = Mid(Word_in.Text, nums – 2, 1)

str(3) = Mid(Word_in.Text, nums – 3, 1)

str(4) = Mid(Word_in.Text, nums – 4, 1)

str(5) = Mid(Word_in.Text, nums – 5, 1)

str(6) = Mid(Word_in.Text, nums – 6, 1)

str(7) = Mid(Word_in.Text, nums – 7, 1)

str(8) = Mid(Word_in.Text, nums – 8, 1)

str(9) = Mid(Word_in.Text, nums – 9, 1)

str(10) = Mid(Word_in.Text, nums – 10, 1)

str(11) = Mid(Word_in.Text, nums – 11, 1)

str(12) = Mid(Word_in.Text, nums – 12, 1)

str(13) = Mid(Word_in.Text, nums – 13, 1)

str(14) = Mid(Word_in.Text, nums – 14, 1)

str(15) = Mid(Word_in.Text, nums – 15, 1)

str(16) = Mid(Word_in.Text, nums – 16, 1)

str(17) = Mid(Word_in.Text, nums – 17, 1)

str(18) = Mid(Word_in.Text, nums – 18, 1)

str(19) = Mid(Word_in.Text, nums – 19, 1)

Catch ex As Exception

End Try

If Word_in.TextLength = 1 Then

If str(0) = "b" Then

Chr1.Text = "B"

End If

ElseIf Word_in.TextLength = 2 Then

If str(1) = "b" Then

Chr1.Text = "B"

End If

If str(0) = "b" Then

Chr2.Text = "B"

End If

ElseIf Word_in.TextLength = 3 Then

If str(0) = "b" Then

Chr3.Text = "B"

End If

If str(1) = "b" Then

Chr2.Text = "B"

End If

If str(2) = "b" Then

Chr1.Text = "B"

End If

ElseIf Word_in.TextLength = 4 Then

If str(0) = "b" Then

Chr4.Text = "B"

End If

If str(1) = "b" Then

Chr3.Text = "B"

End If

If str(2) = "b" Then

Chr2.Text = "B"

End If

If str(3) = "b" Then

Chr1.Text = "B"

End If

ElseIf Word_in.TextLength = 5 Then

If str(0) = "b" Then

Chr5.Text = "B"

End If

If str(1) = "b" Then

Chr4.Text = "B"

End If

If str(2) = "b" Then

Chr3.Text = "B"

End If

If str(3) = "b" Then

Chr2.Text = "B"

End If

If str(4) = "b" Then

Chr1.Text = "B"

End If

ElseIf Word_in.TextLength = 6 Then

If str(0) = "b" Then

Chr6.Text = "B"

End If

If str(1) = "b" Then

Chr5.Text = "B"

End If

If str(2) = "b" Then

Chr4.Text = "B"

End If

If str(3) = "b" Then

Chr3.Text = "B"

End If

If str(4) = "b" Then

Chr2.Text = "B"

End If

If str(5) = "b" Then

Chr1.Text = "B"

End If

ElseIf Word_in.TextLength = 7 Then

If str(0) = "b" Then

Chr7.Text = "B"

End If

If str(1) = "b" Then

Chr6.Text = "B"

End If

If str(2) = "b" Then

Chr5.Text = "B"

End If

If str(3) = "b" Then

Chr4.Text = "B"

End If

If str(4) = "b" Then

Chr3.Text = "B"

End If

If str(5) = "b" Then

Chr2.Text = "B"

End If

If str(6) = "b" Then

Chr1.Text = "B"

End If

ElseIf Word_in.TextLength = 8 Then

If str(0) = "b" Then

Chr8.Text = "B"

End If

If str(1) = "b" Then

Chr7.Text = "B"

End If

If str(2) = "b" Then

Chr6.Text = "B"

End If

If str(3) = "b" Then

Chr5.Text = "B"

End If

If str(4) = "b" Then

Chr4.Text = "B"

End If

If str(5) = "b" Then

Chr3.Text = "B"

End If

If str(6) = "b" Then

Chr2.Text = "B"

End If

If str(7) = "b" Then

Chr1.Text = "B"

End If

ElseIf Word_in.TextLength = 9 Then

If str(0) = "b" Then

Chr9.Text = "B"

End If

If str(1) = "b" Then

Chr8.Text = "B"

End If

If str(2) = "b" Then

Chr7.Text = "B"

End If

If str(3) = "b" Then

Chr6.Text = "B"

End If

If str(4) = "b" Then

Chr5.Text = "B"

End If

If str(5) = "b" Then

Chr4.Text = "B"

End If

If str(6) = "b" Then

Chr3.Text = "B"

End If

If str(7) = "b" Then

Chr2.Text = "B"

End If

If str(8) = "b" Then

Chr1.Text = "B"

End If

ElseIf Word_in.TextLength = 10 Then

If str(0) = "b" Then

Chr10.Text = "B"

End If

If str(1) = "b" Then

Chr9.Text = "B"

End If

If str(2) = "b" Then

Chr8.Text = "B"

End If

If str(3) = "b" Then

Chr7.Text = "B"

End If

If str(4) = "b" Then

Chr6.Text = "B"

End If

If str(5) = "b" Then

Chr5.Text = "B"

End If

If str(6) = "b" Then

Chr4.Text = "B"

End If

If str(7) = "b" Then

Chr3.Text = "B"

End If

If str(8) = "b" Then

Chr2.Text = "B"

End If

If str(9) = "b" Then

Chr1.Text = "B"

End If

ElseIf Word_in.TextLength = 11 Then

If str(0) = "b" Then

Chr11.Text = "B"

End If

If str(1) = "b" Then

Chr10.Text = "B"

End If

If str(2) = "b" Then

Chr9.Text = "B"

End If

If str(3) = "b" Then

Chr8.Text = "B"

End If

If str(4) = "b" Then

Chr7.Text = "B"

End If

If str(5) = "b" Then

Chr6.Text = "B"

End If

If str(6) = "b" Then

Chr5.Text = "B"

End If

If str(7) = "b" Then

Chr4.Text = "B"

End If

If str(8) = "b" Then

Chr3.Text = "B"

End If

If str(9) = "b" Then

Chr2.Text = "B"

End If

If str(10) = "b" Then

Chr1.Text = "B"

End If

ElseIf Word_in.TextLength = 12 Then

If str(0) = "b" Then

Chr12.Text = "B"

End If

If str(1) = "b" Then

Chr11.Text = "B"

End If

If str(2) = "b" Then

Chr10.Text = "B"

End If

If str(3) = "b" Then

Chr9.Text = "B"

End If

If str(4) = "b" Then

Chr8.Text = "B"

End If

If str(5) = "b" Then

Chr7.Text = "B"

End If

If str(6) = "b" Then

Chr6.Text = "B"

End If

If str(7) = "b" Then

Chr5.Text = "B"

End If

If str(8) = "b" Then

Chr4.Text = "B"

End If

If str(9) = "b" Then

Chr3.Text = "B"

End If

If str(10) = "b" Then

Chr2.Text = "B"

End If

If str(11) = "b" Then

Chr1.Text = "B"

End If

ElseIf Word_in.TextLength = 13 Then

If str(0) = "b" Then

Chr13.Text = "B"

End If

If str(1) = "b" Then

Chr12.Text = "B"

End If

If str(2) = "b" Then

Chr11.Text = "B"

End If

If str(3) = "b" Then

Chr10.Text = "B"

End If

If str(4) = "b" Then

Chr9.Text = "B"

End If

If str(5) = "b" Then

Chr8.Text = "B"

End If

If str(6) = "b" Then

Chr7.Text = "B"

End If

If str(7) = "b" Then

Chr6.Text = "B"

End If

If str(8) = "b" Then

Chr5.Text = "B"

End If

If str(9) = "b" Then

Chr4.Text = "B"

End If

If str(10) = "b" Then

Chr3.Text = "B"

End If

If str(11) = "b" Then

Chr2.Text = "B"

End If

If str(12) = "b" Then

Chr1.Text = "B"

End If

ElseIf Word_in.TextLength = 14 Then

If str(0) = "b" Then

Chr14.Text = "B"

End If

If str(1) = "b" Then

Chr13.Text = "B"

End If

If str(2) = "b" Then

Chr12.Text = "B"

End If

If str(3) = "b" Then

Chr11.Text = "B"

End If

If str(4) = "b" Then

Chr10.Text = "B"

End If

If str(5) = "b" Then

Chr9.Text = "B"

End If

If str(6) = "b" Then

Chr8.Text = "B"

End If

If str(7) = "b" Then

Chr7.Text = "B"

End If

If str(8) = "b" Then

Chr6.Text = "B"

End If

If str(9) = "b" Then

Chr5.Text = "B"

End If

If str(10) = "b" Then

Chr4.Text = "B"

End If

If str(11) = "b" Then

Chr3.Text = "B"

End If

If str(12) = "b" Then

Chr2.Text = "B"

End If

If str(13) = "b" Then

Chr1.Text = "B"

End If

ElseIf Word_in.TextLength = 15 Then

If str(0) = "b" Then

Chr15.Text = "B"

End If

If str(1) = "b" Then

Chr14.Text = "B"

End If

If str(2) = "b" Then

Chr13.Text = "B"

End If

If str(3) = "b" Then

Chr12.Text = "B"

End If

If str(4) = "b" Then

Chr11.Text = "B"

End If

If str(5) = "b" Then

Chr10.Text = "B"

End If

If str(6) = "b" Then

Chr9.Text = "B"

End If

If str(7) = "b" Then

Chr8.Text = "B"

End If

If str(8) = "b" Then

Chr7.Text = "B"

End If

If str(9) = "b" Then

Chr6.Text = "B"

End If

If str(10) = "b" Then

Chr5.Text = "B"

End If

If str(11) = "b" Then

Chr4.Text = "B"

End If

If str(12) = "b" Then

Chr3.Text = "B"

End If

If str(13) = "b" Then

Chr2.Text = "B"

End If

If str(14) = "b" Then

Chr1.Text = "B"

End If

ElseIf Word_in.TextLength = 16 Then

If str(0) = "b" Then

Chr16.Text = "B"

End If

If str(1) = "b" Then

Chr15.Text = "B"

End If

If str(2) = "b" Then

Chr14.Text = "B"

End If

If str(3) = "b" Then

Chr13.Text = "B"

End If

If str(4) = "b" Then

Chr12.Text = "B"

End If

If str(5) = "b" Then

Chr11.Text = "B"

End If

If str(6) = "b" Then

Chr10.Text = "B"

End If

If str(7) = "b" Then

Chr9.Text = "B"

End If

If str(8) = "b" Then

Chr8.Text = "B"

End If

If str(9) = "b" Then

Chr7.Text = "B"

End If

If str(10) = "b" Then

Chr6.Text = "B"

End If

If str(11) = "b" Then

Chr5.Text = "B"

End If

If str(12) = "b" Then

Chr4.Text = "B"

End If

If str(13) = "b" Then

Chr3.Text = "B"

End If

If str(14) = "b" Then

Chr2.Text = "B"

End If

If str(15) = "b" Then

Chr1.Text = "B"

End If

ElseIf Word_in.TextLength = 17 Then

If str(0) = "b" Then

Chr17.Text = "B"

End If

If str(1) = "b" Then

Chr16.Text = "B"

End If

If str(2) = "b" Then

Chr15.Text = "B"

End If

If str(3) = "b" Then

Chr14.Text = "B"

End If

If str(4) = "b" Then

Chr13.Text = "B"

End If

If str(5) = "b" Then

Chr12.Text = "B"

End If

If str(6) = "b" Then

Chr11.Text = "B"

End If

If str(7) = "b" Then

Chr10.Text = "B"

End If

If str(8) = "b" Then

Chr9.Text = "B"

End If

If str(9) = "b" Then

Chr8.Text = "B"

End If

If str(10) = "b" Then

Chr7.Text = "B"

End If

If str(11) = "b" Then

Chr6.Text = "B"

End If

If str(12) = "b" Then

Chr5.Text = "B"

End If

If str(13) = "b" Then

Chr4.Text = "B"

End If

If str(14) = "b" Then

Chr3.Text = "B"

End If

If str(15) = "b" Then

Chr2.Text = "B"

End If

If str(16) = "b" Then

Chr1.Text = "B"

End If

ElseIf Word_in.TextLength = 18 Then

If str(0) = "b" Then

Chr18.Text = "B"

End If

If str(1) = "b" Then

Chr17.Text = "B"

End If

If str(2) = "b" Then

Chr16.Text = "B"

End If

If str(3) = "b" Then

Chr15.Text = "B"

End If

If str(4) = "b" Then

Chr14.Text = "B"

Inne książki tego autora