Visual Basic 2008

 

More Lessons

Convert Words to Codes  - Visual Basic 2008

 

This tutorial will show you how to convert the list of English words to codes to be used in the dictionary project:

Open Visual Basic 2008 Express Edition. (If you don't have the program click here to download it for free.)

Click on Project next to Create:

Click on Windows Form Application, and name the project "Your name's project" and then click Ok.

Change the text property of the form to "your name's project".

For this project add a text box, listbox and a button:

Go to Notepad in your computer, and add the list of the words you want to convert to codes.

Save your file on your desktop and name it WordList. The extension should be .txt

Close the notepad and you should see a text file with the name WordList.

Go back to Visual Basic designer and double click on the form:

Add the following highlighted code:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim reader As IO.StreamReader = New IO.StreamReader("C:\Desktop\WordList.txt")

Do While reader.EndOfStream = False

ListBox1.Items.Add(reader.ReadLine)

Loop

reader.Close()

ListBox1.Items.Add("")

ListBox1.SelectedIndex = 0

End Sub

The code we just entered will add all the text in the text file to the list box.

Before we go on, we should add a timer. Change the timer interval to 1

Double click on the button and add the following highlighted code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Timer1.Start()

If ListBox1.SelectedIndex = ListBox1.Items.Count - 1 Then

Timer1.Stop()

Else

TextBox1.Text = "Listbox1.items.add(""" & ListBox1.SelectedItem & """)" & Environment.NewLine

ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1

My.Computer.FileSystem.WriteAllText("C:\Desktop\Codes.txt", TextBox1.Text, True)

End If

End Sub

The code will start the timer. Every time the timer ticks, the button will click. When the button clicks, one of the words from the list box will be converted to a code and saved into a text file on the desktop called Codes.

Go back to the designer and double click on the alarm and add the following highlighted code:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

Button1.PerformClick()

End Sub

 

Run the program and click on the button. Notice that the words you added to the text file appear in the list box. They will be converted to codes and saved on your desktop in file called Codes.

Copy the codes from the text file and insert them in the dictionary project.

 

More Lessons

 

 

 

 

 

 

 

 

Copyright visual-basic-tutorials.com 2014    All Rights Reserved.