function  · web view2018. 5. 5. · label3.caption = 2 * (val(text1.text) + val(text2.text)) end...

49
UNIVERSITY OF ENGINEERING & MANAGEMENT, KOLKATA DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE) LAB MANUAL SUBJECT NAME: SOFTWARE TOOLS USING VB 6.0 SUBJECT CODE: <>

Upload: others

Post on 13-Apr-2021

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

UNIVERSITY OF ENGINEERING & MANAGEMENT, KOLKATA

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE)

LAB MANUAL

SUBJECT NAME: SOFTWARE TOOLS USING VB 6.0

SUBJECT CODE: <>

2ND YEAR 2ND SEMESTER

Page 2: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

SOFTWARE TOLLS LAB USING VISUAL BASIC 6.0

INTRODUCTION TO VISUAL BASIC 6.0

VISUAL BASIC is a high level programming language evolved from the earlier DOS version called BASIC.

BASIC stands for Beginners' All-purpose Symbolic Instruction Code

The program codes in Visual Basic resemble the English language

Different software companies produce different versions of BASIC, such as Microsoft QBASIC, QUICKBASIC, GWBASIC, and IBM BASICA and so on.

VISUAL BASIC is a VISUAL and events driven Programming Language

Visual Basic is event-driven because users may click on a certain object randomly, so each object has to be programmed independently to be able to response to those actions (events).

Examples of events are clicking a command button, entering text into a text box, selecting an item in a list box etc. Therefore, a VISUAL BASIC Program is made up of many subprograms; each with its own program code which can be executed independently and at the same time can be linked together in one way or another.

Page 3: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

VISUAL BASIC ENVIRONMENT

Page 4: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

VISUAL BASIC ENVIRONMENT

a- Menu Bar: It contains a standard command like: File, Edit, View, Window, Help menus, and specific command such as: Project, Format, or Debug menus.

b- Toolbar: it contains the most commonly used commands (button), if clicked an action represented by that button is carried out.

c- Toolbox: it contains a collection of tools that are needed for project design.

d- form Designer: it is a window for each form to customize the designed

interface of the application. Using the form designer, the user can add controls, graphics, and text to create the desired form appearance.

e- Properties Window: it is a List of properties settings for a selected form or

a control. These properties are characteristics (such as size, visible, or color) of the selected object it provides an easy way to set properties.

f- Project Explorer Window: it is a list of the forms and modules for the

current projects. It is a hierarchical tree- branch structure, where the project at top of tree and other parts like forms ,modules) descend from this tree.

g- Form Layout Window: The Form Layout window is a small screen. Which is used to reposition the form of the application so that it appears in proper place when project is run.

h- Code Editor Window: Code Editor Window is used to write a VB code for an application. For each form there is a separate code editor window. It is displayed when user clicks on form or object in form.

Page 5: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

LIST OF CONTROLS AVAILABLE IN A STANDARD VB PROJECT

The toolbox includes many tools and in general they are:

1) Pointer (not control) : used to select tools already on form

2) Picture box : Used to display images in any of the following

formats: BMP, DIB (bitmap), ICO (icon), CUR (cursor), WMF, (metafile), EMF (enhanced metafile), GIF, and JPEG.

3) Label : Fixed text appears on form for remark.

4) Textbox : For text edit .Like note pad.

5) Frame : To group tools together (container).

6) Command button : Used as a switch (such as OK and Cancel) buttons. Code

is written in the Click event procedure of this control

7) Check box : For a yes/ no (true /false) selection.

8) Option button : For selection as group. Many options are placed inside

Page 6: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

container (grouped) (a Frame control). One control is selected from the group all

others of the group are automatically deselected.

9) Combo box : consists of (list and arrow when clicked a small a list appears), if user selects item from the list, it will be displayed in TextBox. Vertical size is fixed.

10) List box : For a list, user adds to and deletes from this list. It takes any size.

11) Horizontal Scrollbar : Create stand-alone Horizontal scroll bars.

12) Vertical Scrollbar : Create stand-alone vertical scroll bars.

13) Timer : Used to control object movement.

14) Drive List Box : It is a special ListBox filled automatically with names, of the files in a specified directory. It is a list invariant.

15) Dir List Box : It is a special ListBox filled with drives (Hard disc, Flopy, CD) in the system. It is an invariant.

16) File List Box : It is a special ListBox filled automatically with the names of all DirListBox. It is a list invariant.

17) Shape : Used only to display rectangles, circles, and ovals on the forms. Never raises any events

18) Line :Used only to display lines on the forms. It never raises any events.

19) Image : Used instead of PictureBox because it consumes fewer system resources.

20) Data : used for data base.

21) OLE : used for joining with another programs.

Page 7: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

DATA TYPES:

Variables are placeholders used to store values.

They have names and data types.

Data type of a variable determines how the bits representing those values are stored in the computer‘s memory.

While declaring a variable, you can also supply a data type for it.

All variables have a data type that determines what kind of data they can store.

Two major data types: Numeric data types: It consists of numbers that can be computed

mathematically with standard operators. Non-numeric data types: It cannot be manipulated mathematically. It

comprises string data types, date data types, boolean data types that store only two values (true or false), object data type and Variant data type.

IF...THEN SELECTION STRUCTURE

If <condition> ThenstatementEnd If

e.g.: If average>75 ThentxtGrade.Text = "A"End If

If <condition > ThenstatementsElsestatementsEnd If

e.g.: If average>50 ThentxtGrade.Text = "Pass"ElsetxtGrade.Text = "Fail"End If

Page 8: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

NESTED IF...THEN...ELSE SELECTION STRUCTURE

If < condition 1 > ThenstatementsElseIf < condition 2 > ThenstatementsElseIf < condition 3 > ThenstatementsElseStatementsEnd If

SELECT...CASE SELECTION STRUCTURE

Select Case IndexCase 0StatementsCase 1StatementsEnd Select

LISTBOX

The function of the ListBox is to present a list of items where the user can click and select the items from the list. In order to add items to the list, we can use the AddItem method.

The items in the list box can be identified by the ListIndex property, the value of the ListIndex for the first item is 0, the second item has a ListIndex 1, and the third item has a ListIndex 2 and so on….

THE COMBOBOX

The function of the Combo Box is also to present a list of items where the user can click and select the items from the list. However, the user needs to click on the small arrowhead on the right of the combo box to see the items which are presented in a drop-down list. In order to add items to the list, you can also use the AddItem method

OPTIONBUTTON

The OptionButton control also lets the user selects one of the choices. However, two or more Option buttons must work together because as one of the option buttons is selected, the other Option button will be unselected. In fact, only one Option Box can be selected at one time. When an option box is selected, its value is set to “True” and when it is unselected; its value is set to “False”.

Page 9: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

THE CHECKBOX

The Check Box control lets the user  selects or unselects an option. When the Check Box is checked, its value is set to 1 and when it is unchecked, the value is set to 0.  You can include the statements Check1.Value=1 to mark the Check Box and Check1.Value=0 to unmark the Check Box, as well as  use them to initiate certain actions.

VB REPETITION

Visual Basic repetition or looping statements

Do WhileRepeat/Loop while trueOften called pretest loop (also has posttest form)

Do UntilRepeat/Loop until trueOften called posttest loop (also has pretest form)

For...NextRepeat/Loop a specified number of times

DO WHILE STATEMENT SYNTAX

Do While expressionstatement(s)

Loop

Syntax explanation:

Do, While, and Loop are keywordsDo While statement marks the beginning of the loop and the Loop statement marks the endThe statement(s) to repeat are found between these and called the body of the loopExpression – True/False value, variable, function call or expression that serves as test for repetition

DO UNTIL STATEMENT SYNTAX

Do statement(s)

Loop Until expression

Page 10: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

Syntax explanation:

Do, Loop, and Until are keywordsDo statement marks the beginning of the loop and the Loop Until statement marks the endThe statement(s) to be repeated are found between these and called the body of the loopExpression – True/False value, variable, function call or expression that serves as test for repetition

FOR NEXT STATEMENT SYNTAX

For Counter = StartValue To EndValue[Step Value]statement[s]

Next [Counter]

Syntax explanation: For, To, and Next are keywords Counter – Variable to track/control number of iterations StartValue is initial value of counter EndValue is counter value at final iteration

Step (optional) – determines counter increment amount for each iteration of the loop (if not specified the default is +1; if specified can be positive – add or count up, or negative – subtract or count down

DIFFERENT MODULAR TECHNIQUES

VISUAL BASIC PROVIDES US WITH THE ABILITY TO REPRESENT MODULES THROUGH THE USE OF THE FOLLOWING:-

• Sub Procedures• Function Procedures• Event Procedures

Page 11: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

ASSIGNMENTS

1. Write a program to display the sentence “I like Visual Basic”.

Private Sub Form_Load()Form1.ShowPrint "I like Visual Basic"End Sub

2. Write a program to compute the value of 1500+1000-450*10+300÷5

Private Sub Form_Activate()Print 1500 + 1000 - (450 * 10) + (300 / 5)End Sub

Page 12: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

3. Using a value of 9 to x and a value of 13 to y, write a program to compute the values of 2x+y, (x+y)÷2 and x2y

Private Sub Form_Activate()x = 9y = 13Print 2 * x + yPrint (x + y) / 2Print x ^ 2 * yEnd Sub

4. Insert two text boxes, one label and four command buttons, then write the program to compute the sum, difference, product, division of two numbers that are entered into the text boxes and display the result in the label.

Private Sub Command1_Click()Label2.Caption = Val(Text1.Text) + Val(Text2.Text)End Sub

Private Sub Command2_Click()Label2.Caption = Val(Text1.Text) - Val(Text2.Text)End Sub

Private Sub Command3_Click()Label2.Caption = Val(Text1.Text) * Val(Text2.Text)End Sub

Private Sub Command4_Click()

Page 13: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

Label2.Caption = Val(Text1.Text) / Val(Text2.Text)End Sub

5. Write a program to change temperature from Celsius to Fahrenheit.

Private Sub Command1_Click()celsius = Val(Text1.Text)fahrenheit = (1.8 * celsius) + 32Label2.Caption = fahrenheitEnd Sub

6. Write a program to find area and perimeter of a rectangle.

Private Sub Command1_Click()Label2.Caption = Val(Text1.Text) * Val(Text2.Text)End Sub

Private Sub Command2_Click()Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text))End Sub

Page 14: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

7. Design a form with three command buttons “red ", “green " and " blue " such that when we click on button the color of the form colored by red, green and blue respectively.

Private Sub Command1_Click()Me.BackColor = vbRedEnd Sub

Private Sub Command2_Click()Me.BackColor = vbGreenEnd Sub

Private Sub Command3_Click()Me.BackColor = vbBlueEnd Sub

Page 15: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

8. Listbox: Write a VB program to add the name of department available in your university and list them sequentially in a textbox. Take three commands to add, remove and clear the names of the department from the list.

Solution:a. Double Click on the 1st text box and write the code:

Private sub Text1_Change()Add.enabled=(Len(Text1.Text)>0)End Sub

This will allow you to add the text in the list box. If the text box is blank the add button will be shown blured.

b. Double click on the ADD button and write the code: Private sub Add_Click()

List1.AddItem Text1.Text Text1.Text=”” End Sub

c. Double click on the DELETE button and write the code: Private sub Delete_Click() Dim ind As Integer ind =List1.ListIndex If ind >=0 Then List1.RemoveItem ind End if End sub

d. Double click on the CLEAR button and write the code: Private sub Clear_Click() Clear End Sub

9. Combox: Write a VB program to list the names of the states in INDIA and display their corresponding Capital through a text box.

Solution:

a. Insert a combo box and add caption as per your wish.b. Double click on form & write the code:

Private Sub Form_Load() Combo1.AddItem “West Bengal”Combo1.AddItem “Orissa”Combo1.AddItem “Bihar”End Sub

Page 16: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

Now Insert the blank textbox where the capital will be shown..c. Double click on the combo box and write the code:

Private sub Combo_Click()If Combo1.Text=” West Bengal” ThenText1.Text= “KOLKATA”ElseIf Combo1.Text=” Orissa” ThenText1.Text= “BHUBANESWAR”ElseIf Combo1.Text=” BIHAR” ThenText1.Text= “PATNA”ElseEnd IfEnd Sub

10. Write a VB code to take a name as input from user, three check boxes to adjust the font of the name in BOLD, ITALICS, SIZE and two option boxes to choose their gender and display in another text box.

Solution:

a. Private Sub Form_Load()Text1.Text=”YOUR NAME”Text1.Fontsize=8End SubOn load it will show the text in the Text boxInsert a Frame Control in your form and insert three check box BOLD, ITALICS, SIZE with proper labeling.

b. Double click on each of the check boxesPrivate Sub Bold_click()If bold.Value=1 Then Text1.FontBold=TrueElseText1.FontBold=FalseEnd IfEnd SubSimilarly with the rest of the check boxes….Private Sub Italic_click()If Italic.Value=1 Then Text1.FontItalic=TrueElseText1. FontItalic =FalseEnd IfEnd Sub

Page 17: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

Private Sub Size_click()If Size.Value=1 Then Text1.FontISize=10ElseText1. FontSize =8End IfEnd Sub

Insert another frame in which you will insert the gender option to choose which be shown through a text box.

Private Sub option1_click()Txtgen.Text=”Male”Txtgen.FontBold=TrueEnd Sub

Private Sub option2_click()Txtgen.Text=”Female”Txtgen.FontBold=TrueEnd Sub

11. Write a VB project to determine the final amount by making monthly deposits into a savings account with following definition:

F = D [ (1 + I)M - 1] / IWhereF - Final amountD - Monthly deposit amountI - Monthly interest rateM - Number of months

Declare four variables in the general declarations area of your form. This makes them available to all the form procedures:

Option ExplicitDim Deposit As Single

Page 18: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

Dim Interest As SingleDim Months As SingleDim Final As Single

Attach code to the cmdCalculate command button Click event.Private Sub cmdCalculate_Click ()

Dim IntRate As Single

‘Read values from text boxesDeposit = Val(txtDeposit.Text)Interest = Val(txtInterest.Text)IntRate = Interest / 1200Months = Val(txtMonths.Text)

‘Compute final value and put in text boxFinal = Deposit * ((1 + IntRate) ^ Months - 1) / IntRatetxtFinal.Text = Str$(Final)

End Sub

12. Write a VB project to calculate Body mass Index of a person.

BMI= weight (kg) ÷ height2 (m2)

Expand the above example displaying appropriate message as mentioned below; also change the textbox color (usage of If-then-else):

If BMI<18.5, display message: Underflow, change textbox color as REDIf BMI between 18.5 and 24.9, display message: Normal, change textbox color as

GREENIf BMI between 25.5 and 29.9, display message: Overweight, change textbox color as

AMBERIf BMI >=30,, display message: Obese, change textbox color as RED

Page 19: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

Private Sub Command1_Click() Dim height, weight As Integer height = Text1.Text weight = Text2.Text BMIValue = (weight) / (height ^ 2) Label4.Caption = Format(BMIValue, "0.00")End Function

Private Sub Command1_Click() If BMIValue < 18.5 Then Label4.BackColor = vbRed MsgBox ("Underweight") ElseIf (BMIValue > 18.5 And BMIValue <= 24.9) Then Label4.BackColor = vbGreen MsgBox ("Normal") ElseIf (BMIValue > 25.5 And BMIValue <= 29.5) Then Label4.BackColor = vbAmber Label4.ForeColor = vbWhite MsgBox ("Overweight") ElseIf (BMIValue >= 30) Then Label4.BackColor = vbRed MsgBox ("Obese") End IfEnd Sub

Page 20: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

13. Write a VB project to demonstrate Shopping cart:Select from the following items using adjacent checkbox, and calculate the total price on selected items on clicking Calculate.

Private Sub Command1_Click()Const LX As Integer = 100Const BN As Integer = 500Const SD As Integer = 300Const HD As Integer = 5Dim sum As IntegerIf Check1.Value = 1 Thensum = sum + LXEnd IfIf Check2.Value = 1 Thensum = sum + BNEnd IfIf Check3.Value = 1 Thensum = sum + SDEnd IfIf Check4.Value = 1 Thensum = sum + HDEnd IfLabel3.Caption = sumEnd Sub

Private Sub Command2_Click()Check1.Value = 0Check2.Value = 0Check3.Value = 0Check4.Value = 0

Page 21: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

End Sub

14. Create a Multiplication table by using a do-while loop. One label, Listbox, Textbox and command button is required and clicking on the command button Listbox is populated.

Private Sub Command1_Click()a = Text1.Textb = 1Do While b < 12List1.AddItem (b & " * " & a & "=" & b * a)b = b + 1LoopEnd Sub

15.Write a VB application to have the user input a binary number via input box. Use a validation loop ensure the input is a valid binary number. When valid, convert the number to a decimal value (use a function) and report the results via message box.

Private Sub Form_Activate()n = InputBox("Enter a binary number")n1 = nStatus = TrueDo While n > 0r1 = n Mod 10If r1 > 1 ThenStatus = FalseEnd Ifn = n / 10Loop

Page 22: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

If Status = False ThenMsgBox ("Not valid")ElseMsgBox ("go")Dim sum, i, r As Doublesum = 0i = 0Do While (n1)r = n1 Mod 10sum = sum + (2 ^ i) * ri = i + 1n1 = n1 / 10LoopPrint sumLabel1.Caption = sumEnd IfEnd Sub

16. Have the user input a positive number via input box. Use a validation loop to prompt for input until valid. Display message indicating when valid input is received.

Private Sub Form_Load()intCount = 0Do MsgBox ("The current number is: " & intCount & "Not valid") intCount = InputBox("Enter positive number")Loop Until (intCount > -1) MsgBox ("valid")End Sub

17. Write a VB application to have the user input via textbox an integer from 1 t0 10 (inclusive) to specify the height and base of a right triangle. Display the triangle in a list box using strings made up of the ‘#’ character. Create and display strings - one char at a time - using nested loops. Input: 4 Output: #

#########

Page 23: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

Private Sub Text1_Change()Dim a As IntegerDim str As Stringa = Text1.TextFor i = 1 To a Step 1str = ""For j = 1 To i Step 1str = str + "#"NextList1.AddItem strNextEnd Sub

18. How to get data from one form to another form

Page 24: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

Form1:

Private Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""End Sub

Private Sub Command1_Click()Form2.ShowEnd Sub

Form2:

Private Sub Command1_Click()Text1.Text = Form1.Text1.TextText2.Text = Form1.Text2.TextEnd Sub

Private Sub Command2_Click()Text1.Text = ""Text2.Text = ""End Sub

Function

Page 25: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

19. String And Numeric Function In Visual Basic

Dim i As IntegerDim str As StringPrivate Sub CmdASC_Click()i = Asc(Txtnum1.Text)MsgBox "asc value is: " & iEnd Sub

Private Sub CmdCHR_Click()str = Chr(Val(Txtnum1.Text))MsgBox "chr code is: " & strEnd SubPrivate Sub CmdLcase_Click()str = LCase(Txtnum1.Text)MsgBox "lower case text is: " & strEnd Sub

Page 26: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

Private Sub CmdUcase_Click()str = UCase(Txtnum1.Text)MsgBox "upper case text is: " & strEnd SubPrivate Sub CmdLEN_Click()i = Len(Txtnum1.Text)MsgBox "length is: " & iEnd SubPrivate Sub CmdLeft_Click()Dim size As Integersize = InputBox("enter size: ")str = Left(Txtnum1.Text, size)MsgBox "left part of string is: " & strEnd SubPrivate Sub Cmdright_Click()Dim size As Integersize = InputBox("enter size: ")str = Right(Txtnum1.Text, size)MsgBox "right part of string is: " & strEnd Sub

Private Sub CmdMID_Click()Dim start, size As Integerstart = InputBox("enter starting point: ")size = InputBox("enter size: ")str = Mid(Txtnum1.Text, start, size)MsgBox "mid part of string is: " & strEnd SubPrivate Sub CmdTRIM_Click()str = Trim(Txtnum1.Text)MsgBox "string is:" & strEnd SubPrivate Sub CmdLtrim_Click()str = LTrim(Txtnum1.Text)MsgBox "string is: " & Txtnum1.TextMsgBox "after trim string is:" & strEnd SubPrivate Sub CmdRtrim_Click()str = RTrim(Txtnum1.Text)MsgBox "string is: " & Txtnum1.TextMsgBox "after trim string is:" & strEnd SubPrivate Sub CmdInstr_Click()i = InStr(1, Txtnum1.Text, Txtnum2.Text, vbBinaryCompare)

Page 27: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

MsgBox "string found at pos: " & iEnd SubPrivate Sub CmdSpace_Click()MsgBox Txtnum1.Text & Space(10) & Txtnum2.TextEnd SubPrivate Sub CmdStrcomp_Click()i = StrComp(Txtnum1.Text, Txtnum2.Text, vbBinaryCompare)MsgBox iEnd SubPrivate Sub CmdString_Click()str = String(15, "#")MsgBox strEnd Sub

Private Sub CmdABS_Click()i = Abs(Val(Txtnum1.Text))MsgBox "absolute value is: " & iEnd SubPrivate Sub CmdEXP_Click()Dim e As Doublee = Exp(Val(Txtnum1.Text))MsgBox "exponent value is: " & eEnd SubPrivate Sub CmdINT_Click()i = Int(Val(Txtnum1.Text))MsgBox "integer value is: " & iEnd SubPrivate Sub CmdFIX_Click()i = Fix(Val(Txtnum1.Text))MsgBox "fix value is: " & iEnd SubPrivate Sub CmdLOG_Click()Dim l As Double l = Log(Val(Txtnum1.Text))MsgBox "logarithm value is: " & lEnd Sub

Private Sub CmdRnd_click()For i = 1 To 5i = 10 * RndMsgBox iNextEnd Sub

Page 28: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

Private Sub CmdSGN_Click()i = Sgn(Val(Txtnum1.Text))MsgBox "sgn value is: " & iEnd SubPrivate Sub CmdSQR_Click()i = Sqr(Val(Txtnum1.Text))MsgBox "square value is: " & iEnd Sub

Private Sub CmdVAL_Click()MsgBox ("This is no  " & Val(Txtnum1.Text))End SubPrivate Sub CmdExit_click()EndEnd Sub   

20. Function (Swaping)

Dim a, b As Integer

Private Sub CmdTable_Click()

Page 29: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

List1.Cleartable (Val(Text1.Text))End Sub

Public Sub table(ByVal t As Integer)Dim i As IntegerFor i = 1 To 10List1.AddItem i * tNextText1.Text = ""Text1.SetFocusEnd Sub

Private Sub CmdFact_Click()fact (Val(Text4.Text))End Sub

Public Function fact(ByVal num As Integer)Dim i, f As Longf = 1For i = 1 To numf = f * iNextfact = fMsgBox "Factorial is: " & factText4.Text = ""Text4.SetFocusEnd Function

Private Sub Cmdswap_Click()x = Val(Text2.Text)y = Val(Text3.Text)MsgBox "Before calling Sub Procedure x= " & x & " and y= " & yswap x, yMsgBox "After calling Sub Procedure x= " & x & " and y= " & yEnd SubSub swap(ByVal x As Integer, ByVal y As Integer)Dim z As Integerz = xx = yy = zMsgBox "In Sub Procedure x= " & x & " and y= " & yEnd Sub

Page 30: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

Private Sub CmdSwap1_Click()a = Val(Text5.Text)b = Val(Text6.Text)MsgBox "Before calling Sub Procedure= " & a & " and b= " & bswap1 a, bMsgBox "After calling Sub Procedure= " & a & " and b= " & bEnd SubSub swap1(ByRef a As Integer, ByRef b As Integer)Dim c As Integerc = aa = bb = cMsgBox "In Sub Procedure a= " & a & " and b= " & bEnd SubPrivate Sub CmdExit_Click()EndEnd Sub

21. Function: Write a Program to search an user defined word from a pre populated text.

Private Sub cmdSearch_Click()Dim n, m, l As IntegerDim myAricle, myWord As StringmyArticle = TxtArticle.TextmyWord = TxtWord.Textl = Len(myWord)n = InStr(1, myArticle, myWord)

Page 31: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

If n = 0 ThenLblResult.Caption = "Your word not found, try again."

ElseLblResult.Caption = "Found your word " & myWord & " at " & " Position " & nTxtArticle.SetFocusTxtArticle.SelStart = n - 1TxtArticle.SelLength = Len(myWord)End IfEnd Sub

22. Road Traffic lights animated system

Private Sub Timer1_Timer()Static state As IntegerSelect Case stateCase 0Shape3.BackColor = vbRedShape4.BackColor = vbWhiteShape5.BackColor = vbWhiteLabel2.Caption = "STOP"Label2.ForeColor = vbRedTimer1.Interval = 7000state = 1Case 1Shape3.BackColor = vbWhiteShape4.BackColor = vbYellowShape5.BackColor = vbWhiteLabel2.Caption = "wait"Label2.ForeColor = vbYellowTimer1.Interval = 3000state = 2Case 2Shape3.BackColor = vbWhiteShape4.BackColor = vbWhiteShape5.BackColor = vbGreenLabel2.Caption = "GO"Label2.ForeColor = vbGreenTimer1.Interval = 5000state = 0End SelectEnd Sub

Page 32: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

23. Develop a VB application that allows a user to change the shape by selecting a particular shape from a list of options from a list box, as well as changing its color through a common dialog box.

Private Sub Form_Load()List1.AddItem "Rectangle"List1.AddItem "Square"List1.AddItem "Oval"List1.AddItem "Circle"List1.AddItem "Rounded Rectangle"List1.AddItem "Rounded Square"End SubPrivate Sub List1_Click()Select Case List1.ListIndexCase 0Shape1.Shape = 0Case 1Shape1.Shape = 1Case 2Shape1.Shape = 2Case 3Shape1.Shape = 3

Page 33: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

Case 4Shape1.Shape = 4Case 5Shape1.Shape = 5End SelectEnd SubPrivate Sub Command1_Click()CommonDialog1.Flags = &H1&CommonDialog1.ShowColorShape1.FillColor = CommonDialog1.ColorEnd Sub

24. Matrix Multiplication And Transpose In Visual Basic With Two-2 Array

Dim a(2, 2), b(2, 2), result(2, 2) As IntegerPrivate Sub CmdCreate_Click()List1.ClearDim str As StringFor i = 0 To 2str = ""For j = 0 To 2a(i, j) = InputBox("Enter No. for Row " & i & " and Column " & j)str = str & Space(3) & a(i, j)NextList1.AddItem strNextEnd Sub

Private Sub CmdTranspose_Click()List2.ClearDim str As StringFor i = 0 To 2

Page 34: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

str = ""For j = 0 To 2b(i, j) = a(j, i)str = str & Space(3) & b(i, j)NextList2.AddItem strNextEnd SubPrivate Sub CmdAdd_Click()List3.ClearDim str As StringFor i = 0 To 2str = ""For j = 0 To 2result(i, j) = Val(a(i, j)) + Val(b(i, j))str = str & Space(3) & result(i, j)NextList3.AddItem strNextEnd SubPrivate Sub CmdMul_Click()List3.ClearDim str As StringFor i = 0 To 2str = ""For j = 0 To 2result(i, j) = 0For k = 0 To 2result(i, j) = Val(result(i, j)) + Val(Val(a(k, j)) * Val(b(i, k)))NextNextNextFor i = 0 To 2str = ""For j = 0 To 2str = str & Space(3) & result(i, j)NextList3.AddItem strNextEnd SubPrivate Sub CmdExit_Click()Unload MeEnd Sub

Page 35: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

25. 1 D Array

Dim num As IntegerDim marks(10) As Integer

Private Sub CmdCreate_Click()List1.ClearFor i = 0 To 10marks(i) = InputBox("enter marks")List1.AddItem marks(i)NextEnd SubPrivate Sub CmdSearch_Click()num = InputBox("Enter number to be search")For i = 0 To 10If (num = marks(i)) ThenMsgBox "No. Found at Pos " & (i + 1)Exit SubEnd IfNextMsgBox "No. not Found"End Sub

Page 36: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

Private Sub CmdSortAsc_Click()List2.ClearDim temp As IntegerFor i = 0 To 10For j = i + 1 To 10If marks(i) > marks(j) Thentemp = marks(i)marks(i) = marks(j)marks(j) = tempEnd IfNextNextFor i = 0 To 10List2.AddItem marks(i)NextEnd SubPrivate Sub CmdSortDesc_Click()List2.ClearDim temp As IntegerFor i = 0 To 10For j = i + 1 To 10If marks(i) < marks(j) Thentemp = marks(i)marks(i) = marks(j)marks(j) = tempEnd IfNextNextFor i = 0 To 10List2.AddItem marks(i)NextEnd SubPrivate Sub CmdExit_Click()EndEnd SubPrivate Sub CmdTranspose_Click()

End Sub

Page 37: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such

26. Dynamic Array In Visual Basic

Dim book() As StringDim bknum As Integer

Private Sub CmdBook_Click()bknum = InputBox("enter total no. of books to be entered")ReDim book(bknum) As StringEnd SubPrivate Sub CmdBookdetail_Click()List1.ClearFor i = 0 To bknumbook(i) = InputBox("Enter book Name:")List1.AddItem book(i)NextEnd Sub

Private Sub CmdAdd_Click()bknum = bknum + 1ReDim Preserve book(bknum) As Stringbook(bknum) = InputBox("Enter book Name to be added:")List1.ClearFor i = 0 To bknumList1.AddItem book(i)NextMsgBox "Book Added"End SubPrivate Sub CmdExit_Click()EndEnd Sub 

Page 38: Function  · Web view2018. 5. 5. · Label3.Caption = 2 * (Val(Text1.Text) + Val(Text2.Text)) End Sub Design a form with three command buttons “red ", “green " and " blue " such