PDA

View Full Version : [tut] Extracting data from a list for to a text box



Blinger1
30-01-2007, 12:21 AM
Welcome to my first tutorial on Visual Basic (or any language for that matter ;))


This tutorial is extremely easy and can be used in programs.

Rating, 1/5 (extremely easy).

Now to get started!

Step one: Open Visual Basic, go to File -> New Project (Ctrl + N) and click on Standard EXE when the box pops up

http://img408.imageshack.us/img408/7563/18582441to4.png (http://imageshack.us)

Step two: Click on the List box and make the box as big as you want, do the same with a text box

http://img201.imageshack.us/img201/3784/64228212dl9.png (http://imageshack.us)

Now it should look a bit like the picture below

http://img408.imageshack.us/img408/1742/43002552qr2.png (http://imageshack.us)

Step three: Now comes the actual coding part, double click on the form and you should see

Private Sub Form_Load()

End Sub

In the space above End Sub type in the following
With List1, this makes it so instead of having to type in List1.AddItem all the time we just have to type in ".AddItem". After you typed With List1 in add the following code
.AddItem "A"
.AddItem "B"
.AddItem "C"
.AddItem "D"
.AddItem "E"
.AddItem "F"
.AddItem "G"
.AddItem "H"
.AddItem "I"
.AddItem "J"
.AddItem "K"
.AddItem "L"
.AddItem "M"
.AddItem "N"
.AddItem "O"
.AddItem "P"
.AddItem "Q"
.AddItem "R"
.AddItem "S"
.AddItem "T"
.AddItem "U"
.AddItem "V"
.AddItem "W"
.AddItem "X"
.AddItem "Y"
.AddItem "Z"
please note: you can change the letters to different things like words, numbers, characters and such.

So now our code should be
Private Sub Form_Load()
With List1
.AddItem "A"
.AddItem "B"
.AddItem "C"
.AddItem "D"
.AddItem "E"
.AddItem "F"
.AddItem "G"
.AddItem "H"
.AddItem "I"
.AddItem "J"
.AddItem "K"
.AddItem "L"
.AddItem "M"
.AddItem "N"
.AddItem "O"
.AddItem "P"
.AddItem "Q"
.AddItem "R"
.AddItem "S"
.AddItem "T"
.AddItem "U"
.AddItem "V"
.AddItem "W"
.AddItem "X"
.AddItem "Y"
.AddItem "Z"
End With
End Sub

Step Four: Double click on the list box and add this code to it
Text1.Text = List1.Text
this basically tells the text box when we click on a value in the list box we want it to appear in the text box.


Your finished code should look a bit like this (i added some comments so you get the drift what is happening ;))


Private Sub Form_Load()
With List1 ' we add the letters to our list when the form opens
.AddItem "A" 'you can change the letters to words, characters, numbers etc.
.AddItem "B"
.AddItem "C"
.AddItem "D"
.AddItem "E"
.AddItem "F"
.AddItem "G"
.AddItem "H"
.AddItem "I"
.AddItem "J"
.AddItem "K"
.AddItem "L"
.AddItem "M"
.AddItem "N"
.AddItem "O"
.AddItem "P"
.AddItem "Q"
.AddItem "R"
.AddItem "S"
.AddItem "T"
.AddItem "U"
.AddItem "V"
.AddItem "W"
.AddItem "X"
.AddItem "Y"
.AddItem "Z"
End With
End Sub

Private Sub List1_Click()
Text1.Text = List1.Text 'When you click a letter from the list box it shows up in the text box


End Sub


That is the end of my tutorial have fun with it.

C+C is welcome thanks.

ZAG
30-01-2007, 07:49 AM
Thats very good for a first tutorial. Well explained, with pictures.

+rep

But as you said, it is extremely easy.

Blinger1
30-01-2007, 08:22 AM
I'll make another tut when i have time :)

Want to hide these adverts? Register an account for free!