Visual Basic 6.

0
Presented bybySri Jahnab Kr. Deka
1

How to open a Project?

2

How to open a Project-2 Project-

3

How to write codes in an event 4 .

Comments line in VB  How to write comments in VB  ' This is a comment  Some important data types in VB String  Double  Integer  Date   How to declare variables   Implicit  Total = Total + 10 Dim Total as double  Explicit  5 Total= Total + 10 .

The scope is procedure-level or module-level. A variable declared with Dim at the beginning of a procedure is only available in that procedure. When the procedure ends. the variable disappears.Scope of a Variable  The term Scope refers to whether the variable is available outside the procedure in which it appears. proceduremodule-level. Consider the following example: Option Explicit Dim Total2 As Integer Private Sub Command1_Click () Dim Total1 As Integer Static Total3 As Integer Total1 = Total1 + 1 Total2 = Total2 + 1 Total3 = Total3 + 1 End Sub Private Sub Command2_Click () Dim Total1 As Integer Total1 = Total1 + 1 Total2 = Total2 + 1 Total3 = Total3 + 1 End Sub 6 .

What are different properties of a Text Box 7 .

e.FontSize = 20 Text1.tooltiptext=´enter somethingµ Text1.ForeColor = vbYellow Text1.FontBold = True Text1.         Text1.g.BackColor = vbRed Text1.Different controls of a Text Box   Name prefix is as txt. g. txtName E.text=Text1 8 .BorderStyle = 0 Text1.Alignment = 2 Text1.

Multi line property of Text boxes  Select the multi line property as one of the following:   True false  Select the scroll bar option     Horizontal Vertical None Both 9 .

FontSize = 20 Label1.BackColor = vbRed Label1. lblName E.FontBold = True Label1.Caption = "HI" 10 .Alignment = 2 Label1.ToolTipText = "enter Something" Label1.         Label1.Different controls of a label box   Name prefix is as lbl. e.g. g.BorderStyle = 0 Label1.ForeColor = vbYellow Label1.

BackColor = vbRed Frame1.ToolTipText = "enter Something" 11 .FontSize = 20 Frame1.BorderStyle = 1 Frame1.FontBold = True Frame1.Caption = "Hello" Frame1.Frame Control       Frame1.

Caption = "Submit" End Sub 12 .Command button Control Private Sub Command1_Click() MsgBox "You have Clicked Submit button". vbInformation End Sub Private Sub Form_Load() Command1.ToolTipText = "Click here" Command1.

Controls of Check boxes Private Sub Check1_Click() MsgBox "You have Clicked Assam" End Sub Private Sub Command1_Click() Check1.Caption = "Command1" Check2.BackColor = vbBlack Check2.ForeColor = vbWhite End Sub Private Sub Form_Load() Check1.Caption = "Bihar" End Sub 13 .BackColor = vbYellow Check1.Caption = "Assam" Check2.

Controls of Option Button Private Sub Command1_Click() If Option1.Value = True Then MsgBox "You have selected the second option" End If End Sub 14 .Value = True Then MsgBox "You have selected the first option´ End If If Option2.

ForeColor = vbWhite Combo1.Text Text1.List(0) = "Assam" Combo1.AddItem Text1.List(2) = "Urissa" Combo1.FontSize = 5 Combo1.List(3) = "Uttar Pradesh" End Sub 15 .Clear End Sub Private Sub Form_Load() Combo1.List(1) = "Bihar" Combo1.Text = "" End Sub Private Sub cmdClear_Click() Combo1.BackColor = vbRed Combo1.Combo Box Control Private Sub cmdAddNew_Click() Combo1.

BackColor = vbRed List1.List(3) = "Uttar Pradesh" End Sub 16 .FontSize = 5 List1.List Box Control Private Sub cmdAddNew_Click() List1.ForeColor = vbWhite List1.Clear End Sub Private Sub Form_Load() List1.Text Text1.List(2) = "Urissa" List1.List(1) = "Bihar" List1.List(0) = "Assam" List1.Text = "" End Sub Private Sub cmdClear_Click() List1.AddItem Text1.

SetFocus ElseIf IsNumeric(txtNumberTwo) = False Then MsgBox "Please Enter Numberic Value" txtNumberTwo.SetFocus ElseIf IsNumeric(txtFirstNumber) = False Then MsgBox "Please Enter Numberic Value" txtFirstNumber.SetFocus ElseIf txtNumberTwo = ´ ´ Then MsgBox "Please Enter Second Number" txtNumberTwo.IFIF-Else Condition Private Sub cmdAdd_Click() If txtFirstNumber = ´ ´ Then MsgBox "Please Enter First Number" txtFirstNumber.SetFocus Else lblResult = Val(txtFirstNumber) + Val(txtNumberTwo) End If End Sub Private Sub cmdClear_Click() txtNumberTwo = "" txtFirstNumber = "" End Sub 17 .

Else structure.Then.... Private Sub Command1_Click() Select Case Val(txtEnterCase) Case 1: lblResult = "Small" Case 2: lblResult = "Medium" Case 3: lblResult = "big" Case 4: lblResult = "Extra Large" Case Else MsgBox "Invalid Choice" End Select End Sub 18 . especially when many comparisons are involved.SELECT CASE  Can be used as an alternative to the If..

5) "DO-WHILEj=1 Do While j <= i Form1. the condition is tested. the statements are never executed. When it gets to the Loop it goes back to the Do and tests condition again. if condition is True. j As Integer Private Sub Command1_Click() i = InputBox("Enter the limit".LOOP  Used to execute a block of statements an unspecified number of times. Dim i.Print j.. then the statements are executed. Do While condition statements Loop First. "DO-WHILE-LOOP". j=j+1 Loop End Sub 19 .DO«. If condition is False on the first pass.

j As Integer Private Sub Command1_Click() i = InputBox ("Enter the limit".WEND  Used to execute a block of statements an unspecified number of times.Print j. the condition is tested.  Dim i. 5) "DO-WHILEj=1 While j <= i Form1.WHILE«. j=j+1 Wend End Sub 20 . if condition is True. the statements are never executed. While condition statements Wend First. When it gets to the Loop it goes back to the Do and tests condition again. then the statements are executed. If condition is False on the first pass. "DO-WHILE-LOOP".

" Next i End Sub ----------------------------------------------------------------------------------------------------Let us take a closer look at our for loop: ' For .between start and stop value ' 9 .go to next step (if i < 9 then end for loop) Description: ' The for loop will loop from the given start walue to the given stop value.start value = 0 ' To .stop value = 9 ' Next . 21 . ' The amount of loops will then be 10 (first loop i=0).use i as our integer ' 0 .Text = i & ".NET Private Sub Form_Load() 'display the numbers from 0 to 9 For i = 0 To 9 Text1.for loop ' i .FOR«.

Function procedure and Sub Procedure in VB   Difference between Function & Procedure is A procedure is a set of code that does the work but does not return a value whereas a function accepts parameters and does the calculation and does return a value back. How to write Function Procedure and Sub Procedure in Visual Basic Sub tellOperator(ByVal task As String) Dim stamp As Date stamp = TimeofDay() MsgBox ("Starting " & task & " at " & CStr(stamp)) End Sub Private Sub Command1_Click() Call tellOperator("Dwipen Laskar") End Sub Private Function TimeofDay() TimeofDay = Time End Function 22 .

How to Pass Array in a Function Private Sub Command1_Click() Dim x(3) As Integer elements x(0) = 10 x(1) = 20 x(2) = 30 x(3) = 40 Call AcceptArray(x) End Sub 'Declare a Static Integer Array of 4 'Call the procedure and pass the Array Private Sub AcceptArray(intArray() As Integer) Dim obj As Variant For Each obj In intArray Form1.Print obj Next End Sub Private Function ReturnArray() As Variant Dim x(3) As Integer 'Declare a Static Integer Array of 4 elements x(0) = 1 x(1) = 2 x(2) = 3 x(3) = 4 ReturnArray = x 'Pass the array back as a return value End Function Private Sub Command2_Click() Dim retval As Variant 23 .

How to use Message Box  Used for displaying messages     Prompt Symbol Button title 24 .

How to use Input Box?  Used for taking inputs from users      Prompt Title Default X-position Y-position 25 .

Value = 0 HScroll1.Min = 0 Label1.Caption = HScroll1.Min = 0 HScroll1.Horizontal/ Vertical Scroll Bar Private Sub Form_Load() HScroll1.Value End Sub 26 .Value End Sub Private Sub HScroll1_Change() Label1 = "" Label1 = HScroll1.Max = 100 VScroll1.Max = 100 VScroll1.Value = 0 VScroll1.Value End Sub Private Sub VScroll1_Change() Label1 = "" Label1 = VScroll1.

How to include add ins and Libraries 27 .

Enabled = True End Sub Private Sub Timer1_Timer() Text1.Text = Time End Sub 28 .How to use the Timer? Private Sub Command1_Click() Timer1.

How to use Month Viewer Private Sub Form_Load() MonthView1.Appearance = ccFlat MonthView1.Value.BackColor = vbGreen MonthView1.ForeColor = vbRed End Sub Private Sub MonthView1_DateClick(ByVal DateClicked As Date) MsgBox "you have clicked " & Format(MonthView1. vbInformation End Sub 29 . "ddmm-yyyy").

How to use Date Picker 30 .

How to Create Manus 31 .

You have Clicked Display" End Sub 32 .How to use Manus Private Sub mnDisplay_Click() MsgBox "Hello.

Color Exit Sub err: MsgBox "Dialog is canceled" End Sub 33 .Action = 3 'display color dialog box Form2.BackColor = CommonDialog1.How to use Common Dialog Control Private Sub mnDisplay_Click() On Error GoTo err: CommonDialog1.

TextMatrix(1.TextMatrix(2.TextMatrix(0. 2) = 29 MSFlexGrid1. 2) = 0 MSFlexGrid1. 2) = Val(MSFlexGrid1. 1) = "Age" End Sub 34 .TextMatrix(2. 0) = "Total" MSFlexGrid1. 0) = "3" MSFlexGrid1. 2) = 27 MSFlexGrid1.TextMatrix(3. 1) = "S Adarsh" MSFlexGrid1.TextMatrix(9. 0) = "1" MSFlexGrid1.TextMatrix(0.TextMatrix(2. No" MSFlexGrid1. 1) = "Sachin" MSFlexGrid1. 1) = "Name" MSFlexGrid1. 2)) End Sub Private Sub Form_Load() MSFlexGrid1. 2) = "Age" MSFlexGrid1.TextMatrix(3.How to Use MS-Flex Grid MSPrivate Sub Command1_Click() MSFlexGrid1. 0) = "S. 2)) + Val(MSFlexGrid1. 2) = 56 MSFlexGrid1.TextMatrix(3.TextMatrix(3.TextMatrix(9.TextMatrix(1.TextMatrix(1. 1) = "Dwipen" MSFlexGrid1.TextMatrix(9.TextMatrix(1.TextMatrix(9.TextMatrix(0. 0) = "2" MSFlexGrid1.TextMatrix(2. 2)) + Val(MSFlexGrid1.