Visual Basic

What is Visual Basic?

Visual Basic is a computer programming language. Where you can create a customized computer programme, using VB features.


How to open Visual Basic?

First type visual in the start menu of windows, if visual basic will installed already then click on it otherwise Install it.


First Screen of Visual Basic 6.

vb6-1

Select Standard EXE 


Now you are in the Visual Basic 6 Integrated Programming Environment as shown in the image below.vb6-2


How to Make the First Programme in Visual Basic?

Step 1: Open VB and Click on the Standard EXE

Step 2: On the next screen double click on the form 1.

Now VB Source Code window will appear as shown below.

vb6-3


Now type the following code

Form1.show

Print “Welcome to VB Tutorial by Rana Mehtab Alam Lunar Computer College”

⇒ The output of the above programme

vb6-4


How to Add Label, TextBox and Button in VB programme?

vb6-5


First, open Standart EXE form and add Label, TextBox and Button as shown in the image below

vb6-6

Step 1. Create Lable

  • Create First Lable
  • Select the created first label, Now Right Click on it then click on the copy, if want to create more labels.
  • Now Right Click on the Fred space of the form and click on the paste. Click on No, if the computer displays any dialogue message.

No drag the label withholding the left mouse button to the location you want to put.


Step 2. Create TextBox

  • Create the First TextBox
  • Select the created first TextBox, Now Right Click on it then click on the copy, if want to create more TextBox.
  • Now Right Click on the Fred space of the form and click on the paste. Click on No, if the computer displays any dialogue message.

No drag the TextBox withholding the left mouse button to the location you want to put.


Step 3. Create Button

Create a button, if you need to more than one button then you can do the same like the label and the textbox.


Step 4. Change Label, TextBox and Button Name

  • Label name changes the Caption.
  • TextBox name changes the Text.
  • Button name changes the Caption.

Now double click on the Result button and type the following codes

Text4.Text = val(Text2.Text) + val(Text3.Text)


How to Add, Multiply, Divide and Subtract in VB?

Step 1. Create the following form 

vb6-7

  • Now double click on the plus button and type the following code.
  • Text3.Text = val(Text1.Text) + val(Text2.Text)

  • Now double click on the minus button and type the following code.
  • Text3.Text = val(Text1.Text) – val(Text2.Text)

  • Now double click on the  mulitiply  button and type the following code.
  • Text3.Text = val(Text1.Text) * val(Text2.Text)

  • Now double click on the  divide  button and type the following code.
  • Text3.Text = val(Text1.Text) / val(Text2.Text)

How to colour your VB Form?

Double click on the Form then type this code

Form1.Backcolour = vbGreen

Execute the form


List of VB Colour

vbColors


How to Connect Database with Visual Basic?

Step 1. Create Your Form (Example Form is as shown below)

database-1


Step 2.  vb toolbarRight Click on the free space of the Toolbar

 

 

 

 

 


Step 3. Select Microsoft ADO Data Control 6.0 (OLED6) as shown in the image below.

ADO Data Control


Now Microsoft ADO Data Control 6.0 (OLED6) icon ado icon will appear in the toolbar.

Step 4. Add this to your Form as shown in the images below.

ado in the form


Step 5. Click on Add-Ins vb6 from the vb menu then click on the Visual Data Manager.

  • On the Next Image Click on File >> New >> Microsoft Access >> Version 7.0 MDB
  • Save your Database

Step 6. Now the following image will show.

new-table-1

Right, Click on the + icon as shown in the image above then click on the New Table.


Step 7. Now Table creating window will appear

vb-table

Type Table Name then Click on the Add Field. 

Now make the table for each field

ID, Name, Mobile, Address and City and close this window


 

Step 8. Now click on the Build The Table. 


Step 9.   Right click on Microsoft ADO Data Control 6.0 (OLED6)

  • Property
  • Build
  • Microsoft Jet 4.0 OLE DB Provider
  • Next
  • Click on  on the right corner button of Select or Enter a Database Name as shown in the image below
  • jet4
  • Attach the Database which you have just created
  • Click on the Test Connection. (If you get a message [Test Connection Succeeded]) your database connected successfully.
  • OK
  • Record Source.
  • Select Table under the Command Type
  • Click on the Table which you have created under the Table or Stored Procedure Name. 
  • OK

Step 10. Attach TextBoxes with Database.

  • Click on the TextBox and click on the  DataSource under the properties of the Textbox at the right side of the form.
  • On the Text1.Text
  • Select ADODC1 and from the DataField Select ID
  • Do this same for all the textboxes according to their field names.

Now your database is attached with this form and can be view.


How to Add Data With Buttons in VB with Database Attachments?

add data with buttons

Create this form and double click on Add New type the following code

  • Adodc1.Recordset.AddNew

Then Double Click on the Save and type the following code.

  • Adodc1.Recordset.Update

⇒Now you can add the data with the button.

If you did not learn how to connect the database with this form then click here to learn it first.


   Home   Courses   

 

 

 

 

 

 

Spread the love
Rana Mehtab Alam Lunar Computer College.