Tuesday, December 30, 2008

New Lesson: Handling Graphics in Visual Basic 6

Graphics is a very important part of visual basic programming as an attractive interface will be appealing to the users. In the old BASIC, drawing and designing graphics are considered as difficult jobs, as they have to be programmed line by line in a text-based environment. However, in Visual Basic, these jobs have been made easy. There are four basic controls in VB that you can use to draw graphics on your form: the line control, the shape control, the image box and the picture box.

Please learn more about graphics in our newest lesson by clicking the link below:

http://www.vbtutor.net/lesson18.html

Sunday, December 28, 2008

Reorganization of vbtutor content page

We have had a major reorganization of the vbtutor content page. We have also corrected some errors and bad links. Now it is easier to navigate. Log on to

http://www.vbtutor.net/vbtutor.html

to see the changes.

Compiling and Distributing Your VB Programs

Once your have completed a VB program, you can compile the program to run as a standalone windows application, without having to launch the Visual Basic IDE. However, before you compile your program, you have to debug your program to make sure it is errors free. Once the program is compiled into an EXE file (executable file), you can not debug it anymore. If you wish to do so, you have to correct the errors and recompile it.

Other than that,
you might want to market your product, either online or offline. This means that you need to create a package that can be distributed to your potential customers. The package created can be distributed using CD ROM, diskette or the Internet. The package will allow the user to install the program to install in the computer with the standard setup routine.

Learn how to compile and distribute your VB programs in our new lesson at:

http://www.vbtutor.net/lesson29.html

Tuesday, December 23, 2008

Merry Chritsmas

Merry Christmas to everybody, particularly to our Christian friends! Even if you are not a Christian, I'm sure you still would like to have fun in this festive season.

This year seems to be a particularly cold year, with many places in North America, Europe and East Asia experiencing sub -zero degree temperature, some places even dipped below -20 degree Celsius. I have a daughter who is studying at Drake University, Des Moines, Iowa, and she has hard time adjusting to the severe temperature. She is staying there for winter break and it would take one day for her to fly home across the Pacific Ocean.

For those VB friends who are experiencing severe weather, I hope you can take good care of yourself and your loved ones. And since you will spend more time indoor, why not learn more about VB programming?

Wish everybody good luck and have a great festival!

Friday, December 19, 2008

Reading and Writing Text File in VB2008

To be able to open a file and read the data from a storage unit of a computer, such as a hard drive and able to save the data into the storage unit are important functions of a computer program. In fact, the ability to store, retrieve and modify data makes a computer a powerful tool in database management.

Reading and writing to a text file in VB2008 required the use of the StreamReader class and the StreamWriter class respectively. StreamReader is a tool that enables the streaming of data by moving it from one location to another so that it can be read by the user. For example, it allows the user to read a text file that is stored in a hard drive. On the other hand, the StreamWriter class is a tool that can write data input by the use to a storage device such as the hard drive.

To learn further, please view our new Vb2008 lesson at:

http://www.vbtutor.net/vb2008/vb2008_lesson21.html

Monday, December 15, 2008

Counting items in a Combo Box

In Visual Basic, the combo box is a control that can store a list of items. Is it possible to count the number of items that is stored in the combo box? The answer is yes. The keyword to use is the ListCount property. However, in order to count the items according to categories, we have to use the For....Next loop to accomplish the task.

I have written a program to count the number of students who score A, B, C and D respectively. In this program, the user click the "Add Item" button to enter the grades from an Input Box. After entering all the grades, the user can get the statistics by pressing the 'Count" button.

The code is as follows:


Private Sub Command1_Click()
Dim item As String

item = InputBox("Enter an item")

Combo1.AddItem item



End Sub




Private Sub Command2_Click()
Dim count, i As Integer
Dim item1, item2, item3, item4 As Variant

count = Combo1.ListCount

For i = 0 To count

Combo1.Text = Combo1.List(i)

If Combo1.Text = "A" Then
item1 = item1 + 1
ElseIf Combo1.Text = "B" Then
item2 = item2 + 1
ElseIf Combo1.Text = "C" Then
item3 = item3 + 1
ElseIf Combo1.Text = "D" Then
item4 = item4 + 1
End If
Next

Lbl_A.Caption = item1
Lbl_B.Caption = item2
Lbl_C.Caption = item3
Lbl_D.Caption = item4



End Sub

The Output Screen:





Friday, December 12, 2008

Errors Handling in Visual Basic 2008

Dear Readers

I have written about errors handling in Visual Basic 6 the other day. Now, I have written errors handling in VB2008. In this new lesson, you will learn how to use the Try...Catch....End try statement to manage exceptions or errors in a VB2008 program. For detail info, please view

http://www.vbtutor.net/vb2008/vb2008_lesson20.html

Wednesday, December 10, 2008

Revamp of my website

Dear Vbtutor.net readers,

I have carried out quite a major revamp to the Vbtutor website. It looks much more streamlined and systematic now. It has also becoming easier to navigate. Please check out the lessons at

http://www.vbtutor.net/vbtutor.html

Monday, December 8, 2008

Error Handling in Visual Basic

HTML clipboardError handling is an essential procedure in Visual Basic programming because it can help make the program error-free. An error-free program can run smoothly and efficiently, and the user does not have to face all sorts of problems such as program crash or system hang.
ML clipboard

Errors often occur due to incorrect input from the user. For example, the user might make the mistake of attempting to ask the computer to divide a number by zero which will definitely cause system error. Another example is the user might enter a text (string) to a box that is designed to handle only numeric values such as the weight of a person, the computer will not be able to perform arithmetic calculation for text therefore will create an error. These errors are known as synchronous errors.


Learn how to write errors handling procedure in Visual Basic in our new lesson at

http://www.vbtutor.net/lesson28.html


Thursday, December 4, 2008

Chinese Visual Basic Tutorial

If you have Chinese friends who is interested in learning Visual Basic programming but can't understand the concepts in English, please ask them to visit the Chinese version of vbtutor.net at

http://www.vbtutor.net/chinese/vbtutor_Chinese.html

Wednesday, December 3, 2008

Temperature Converter


With winter around and daily temperature change has become a concern for many people especially those who travel a lot. They are constantly checking out temperature readings everyday However, different parts of the world often use different temperature scales, some of them use Fahrenheit and some use Celsius, so the readings can be confusing. Therefore, it is nice if we have a program that can convert Celsius to Fahrenheit and vice versa. And I have done just that using Visual Basic 6. The code is like this:

Private Sub Command1_Click()
Dim cel, Fah As Single
cel = Val(txtC.Text)
Fah = Val(txtF.Text)

If txtC.Text <> "" And txtF = "" Then
Fah = ((9 / 5) * cel + 32)
txtF.Text = Round(Fah, 1)
Else
cel = (5 / 9) * (Fah - 32)
txtC.Text = Round(cel, 1)
End If

End Sub

Private Sub Command2_Click()
txtC.Text = ""
txtF.Text = ""

End Sub