Some example of visual basic program




















The properties displayed at any one time are related to the currently selected control in the Form. If you click on the Label and then the Button in your Form you will see the properties panel change to reflect the current selection. To begin with, we will change the text of the Label control. Select the Label control in the form and then scroll down the list of properties until you find Text. This is the property which defines the text to be displayed on the currently selected Label control.

Notice that as soon as you change this property the Label in the Form changes to reflect the new property setting. Re-position the controls in the Form if necessary. You should now have a Form which looks something like the following:. The next step is to make the Close button do something when it is pressed. Before we do that, however, we need to give the button a more meaningful name.

Visual Studio has given the button a default name of Button1. While this is fine for a small design, it will quickly become difficult to work with such names in larger applications containing many buttons. With the Button selected in the Form, scroll up to the top of the properties list and change Name from Button1 to closeButton. Having changed the name we can now add an event to the button. Double click on the Button in the Form to display the event code for the closeButton control.

Accessing databases using the Data Environment control. Mike Rounding Rod Stephens. Building a Transparent ActiveX Control that lets you click on a non-rectangular image.

Mike Rounding Shaun Kaasten. Dynamic queries and databases: simple example on how you can use sliders to build a query to a database. The "Bitton" control, beginning guide to building ActiveX controls a few different ways along with some ActiveX explanation.

This program demonstrates dragging and dropping from explorer and between forms and also includes a cool control moving code module. This is a step-by-step tutorial for how to integrate Macromedia Flash into your VB applications.

A simple hello world program that illustrates a basic VB program as well as the command button and timer control.

Saul Greenberg. We use this nonsense program as a first VB exercise for students to do. These two vb Projects illustrates two ways to cycle through images stored in a local directory. A marquee an automatically scrolling text region is used to illustrate a Timer, a status bar and a checkbox control, and simple graphical repositioning,. An example of how to use listboxes as well as how to put images into buttons.

Rod Stephens, modified by Saul Greenberg. Illustrates how to play a wave file in Visual Basic. Illustrates two simple sketchpads. A simple object-oriented drawing editor that allows a user to create, move and erase squares. The program illustrates how to do simple object-based interactive graphics in VB how to use a collection how to use a class.

This program is similar to the drawing editor above, but used for completely different purposes. Illustrates how to create a very simple table lens that toggles cells between graphical and textual views. Illustrates how to Bitblit a picture on another picture, and how to drag it around. Illustrates how to use the Tree control and how to drag items around different parts of the tree.

An example application that lets a user interactively move different kinds of controls on a display. Illustrates how to create a simple class that raises events. Illustrates a database with the flex control. Illustrates how you can clip the shape of a control or form to a variety of regions.

A tutorial and example project that shows you how to build a TickerTape control out of a label. A function is either being defined or called. You define the function and what you want it to do first. Then in the main program you call the function that you have created. This program will ask the user to enter a price and then calculate the VAT by calling a function.

Like any Visual Basic program you need to create the interface, the interface for this program is shown below:. Once the function is defined you can write whatever code you want to execute inside of it. The final step is to return the VAT value back to the main program, therefore you need to add the code:. Once you have created the necessary functions you can create the main program. You would write the code for this for when the button is clicked, like you have done in other programs.

Now you have the input stored from the user you need to display the VAT. To do this you will need to use the a message box like you normally would but inside of it call the function you created earlier.

Add the following code:. The first part of the message box command works like it always would, but then it called the function calculate and passes the amount that was entered into the function. Once the amount is in the function it is referred to as price.

This is known as a local variable that can only be used within that function. This program will ask the user to enter two numbers. A function will then be called that checks which number is the highest and then output which one is the largest. If they are the same it will say they are the same. This program will ask the user what conversion method they want to use. After the user has chosen an option it will then ask them to enter a value.

It will then call the relevant function and convert the number. Program Examples. Inputting - Creating an Interface Visual Basic have two main parts to it. Some of those that you will use are: Label - used to display text on an interface Text Box - used to allow the user to type in some text Combo Box - used to give a set of options to the user List Box - used to provide a list of options to choose from or display a list of information that has been calculated in the program.

Button - these are often used so when the user clicks on them something happens. It looks like this: When you have dragged your form controls onto your form, you need to name them.

You should add a prefix to any form control, the common ones are: Labels - lbl Text Boxes - txt Combo Boxes - cmb List Boxes - lst Buttons - btn If you had a text box where the user enters their name a suitable name would be txtName. Difference between naming a control and changing the text You must always name controls, this can be done in the properties next to the option name , as shown below: If you want to change what the form control says on it, you change the option text , as shown below: Outputting Data - Message Boxes Below is an interface where the user will enter a word.

Interface Code when btnRun clicked MessageBox. Example program 1 - Birthday Program The code for the program below will allow the user to enter their name, select the day of the week that their birthday falls on this year and then choose the month of their birthday from the list box. Interface Code when btnBirthday clicked MessageBox. Text This is what happens when the button is clicked: Example program 2 - Address Program The code for the program below will allow the user to enter various pieces of information.

Interface Code when btnDisplay clicked MessageBox. Text This is what happens when the button is clicked: You can concatenate join together controls with strings in a MessageBox. Outputting Data - List Boxes One of the other methods of outputting data is through a list box. To add data to a list box you need to use the following code: Listboxname. Add Data to add to list box Consider the following interface: To add the name entered and the email address entered to the list box when the button is clicked you need the following code: Code when btnAdd clicked lstOutput.

Add txtName. Text This is what happens when the button is clicked: You can add multiple rows of data to a list box. With a list view box you can add columns and headings to make it look like a table, like the example shown below: When you add a list view control, you have to change a property to get it to work. Text, txtEmail. Object, e As System. EventArgs Handles MyBase. Load lstOutput. Add "Name", , HorizontalAlignment.

Left lstOutput. Add "Email", , HorizontalAlignment. EventArgs Handles btnAdd. Click lstOutput. Text, txtScore1. Text, txtScore2. Text, txtScore3. Add "Score 1", 75, HorizontalAlignment. Center lstOutput. Add "Score 2", 75, HorizontalAlignment.

Add "Score 3", 75, HorizontalAlignment. Center End Sub This is what happens when the button is clicked: Variables A variable is used to temporarily store a piece of data. Round capacity, 2. Example program 2 - Cylinder Volume Program The code for the program below will allow the radius and height of a circle, then calculate and output the volume and surface area.

Round volume, 2. Round surfaceArea, 2. Add number. ToString Next. Where str is a variable of string type. Below is the code to Concat two string in visual basic. Which contains 3 strings str1, str2,str3.

I am Bhupendra Patidar, full-stack Java developer, and Automation engineer. I am enjoying programming since last 6 years and sharing my experiences with the community.

Thank You to visit this article:.



0コメント

  • 1000 / 1000