Visual Basic Codes

Posted on  by 



  • Code Library C Implementation of Visual Basic 6 LTrim Function 1.8K views 2 comments 0 points Most recent by uDocProject March 2018 Beginner C/C Code Library C Implementation of Visual Basic 6 RTrim Function.
  • CodeGuru is where developers can come to share ideas, articles, questions, answers, tips, tricks, comments, downloads, and so much more related to programming in.
  • The following Puzzle Game Visual Basic.Net Source Codes project contains the origin rule and VB.NET illustrations used for 15 - Puzzle Game visual basic.NET. This is 15 Puzzle game in which i have included a range of control buttons. Puzzle Game Visual Basic Download Puzzle Game Visual Basic.Net Source Code.
  • Explore Mohd's board 'Visual basic codes' on Pinterest. See more ideas about معرفة, كتب.

Total Visual SourceBook is the world’s most complete collection of truly useful code for Microsoft Office and Visual Basic developers. In addition to providing a rich code library, Total Visual SourceBook acts as a code repository, making it easy to manage your code and share it among your team.

Visual Basic 6 is a third-generation event-driven programming language first released by Microsoft in 1991. In VB 6, there is no limit of what applications you could create, the sky is the limit. You can develop educational apps, financial apps, games, multimedia apps, animations, database applications and more.

Free

The team at vbtutor.net has created many sample codes, please browse them on the sidebar. You are welcome to use the sample codes as a reference for your assignments and projects. However, the usage of the sample codes for commercial purposes without prior consent from the webmaster is strictly prohibited.


Visual Basic Sample Codes E-Book is written by our webmaster, Dr.Liew. It comprises 258 pages of captivating contents and 48 fascinating Sample Codes.Perfect source of reference for your VB projects. Check it out.

About Us

The Tutor and webmaster of Vbtutor.net, Dr.Liew Voon Kiong , holds a Bachelor's Degree in Mathematics, a Master's Degree in Management and a Doctoral Degree in Business Administration. He obtained the DBA degree from the University of South Australia.

Examples

He has been involved in programming for more than years. He created the popular online Visual Basic Tutorial in 1996 and since then the web site has attracted millions of visitors .It is the top-ranked Visual Basic tutorial website in many search engines including Google. Besides that, he has also written a few Visual Basic related books. One of the books, Visual Basic 6 Made Easy was published by Creativespace.com, an Amazon.com publisher.


The Slot Machine created using VB6

Visual basic codes excel

Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy

In this lesson, we shall learn some basic techniques in writing the Visual Basic program code. First of all, we should understand that each control or object in VB are able to run numerous kinds of events. These events are listed in the dropdown list in the code window, that is displayed when you double-click on an object and click on the procedures’ box. Among the events are loading a form, clicking on a command button, pressing a key on the keyboard or dragging an object and more. For each event, you need to write an event procedure so that it can perform an action or a series of actions.

To start writing code for an event procedure, you need to double-click an object to enter the VB code window. For example, if you want to write code for the event of clicking a command button, you double-click the command button and enter the codes in the event procedure that appears in the code window, as shown in Figure 4.1.

The structure of an event procedureis as follows:

You enter the codes in the space between Private Sub Command1_Click............. End Sub.The keyword Sub actually stands for a sub procedure that made up a part of all the procedures in a program or a module. The program code is made up of a number of VB statements that set certain properties or trigger some actions. The syntax of the Visual Basic’s program code is almost like the normal English language, though not exactly the same, so it is fairly easy to learn.

The syntax to set the property of an object or to pass a certain value to it is :

where Object and Property are separated by a period (or dot). For example, the statement Form1.Show means to show the form with the name Form1, Iabel1.Visible=true means label1 is set to be visible, Text1.text=”VB” is to assign the text VB to the text box with the name Text1, Text2.text=100 is to pass a value of 100 to the text box with the name text2, Timer1.Enabled=False is to disable the timer with the name Timer1 and so on. Let’s examine a few examples below:

Example 4.1

Example 4.2

Example 4.3

Example 4.4 A Counter

This is a counter which start counting after the user click on a command button. In this program, we insert a label, two command buttons and a Timer control. The label acts as a counter, one of the command buttons is to start the counter and the other one is to stop the counter. The Timer control is a control that is only used by the developer, it is invisible during runtime and it does not allow the user to interact with it.

The Timer's Interval property determine how frequent the timer changes. A value of 1 is 1 milliseconds which means a value of 1000 represents 1 second. In this example, we set the interval to 100, which represents 0.1 second interval. In addition, the Timer's Enabled property is set to false at design time as we do not want the program to start counting immediately, the program only start counting after the the user clicks on te 'Start Counting' button. You can also reset the counter using another command button.

The Code

* We declare the variable n in the general area. After the Timer1 is enabled, it will add 1 to the preceding number using n=n+1 after every interval untill the user click on the 'Stop Counting' button.

Visual basic codes for word

Visual Basic Codes Pdf

The Output

Example 4.5 Click and Double Click

This program display a message whether the label is being click once or click twice. In this program, insert a label and rename it as MyLabel and change its caption to 'CLICK ME'. Next, key in the following codes:

The Output

Running the program and click the label once, the 'CLICK ME' caption will change to 'You Click Me Once'. If you click the label twice, the 'CLICK ME' caption will change to 'You Click Me Twice!'.

In Visual Basic, most of the syntaxes resemble the English language. Among the syntaxes are Print, If…Then….Else….End If, For…Next, Select Case…..End Select , End and Exit Sub. For example, Print “ Visual Basic” is to display the text Visual Basic on screen and End is to end the program.

Visual Basic Codes Pdf

Program code that involves calculations is fairly easy to write, just like what you do in mathematics. However, in order to write an event procedure that involves calculations, you need to know the basic arithmetic operators in VB as they are not exactly the same as the normal operators , except for + and - .

For multiplication, we use *, for division we use /, for raising a number x to the power of n, we use x ^n and for square root, we use Sqr(x). VB offers many more advanced mathematical functions such as Sin, Cos, Tan and Log, they will be discussed in lesson 10. There are also two important functions that are related to arithmetic operations, i.e. the functions Val and Str$ where Val is to convert text to a numerical value and Str$ is to convert numerical to a string (text). While the function Str$ is as important as VB can display a numeric value as string implicitly, failure to use Val will result in the wrong calculation. Let’s examine Example 4.4 and example 4.5.

Example 4.4

Example 4.5


When you run the program in example 4.4 and enter 12 in textbox1 and 3 in textbox2 will give you a result of 123, which is wrong. It is because VB treat the numbers as string and so it just joins up the two strings. On the other hand, running exampled 4.5 will give you the correct result, i.e., 15.


Visual Basic Codes For Excel

Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy

Free Visual Basic Code Examples






Coments are closed