Page 4 :
P, , i.he, , Deda, wahap, , extbx, , sy*, , e, , act, , y7a, , An, , ya, , Buttan, , CA, , ender, , s, , sywten.ctjact., , A, , ny7a, , An, , AGDgKText, , E, , iytem EoantArgn andim, , ystee EventArga) andins But. T.onz, , CE, , yaten. Even cArga Bandi as Buttond.C, , al, , Adding Codes, Execute the program and click on Red, Yellow and Green buttons one by one to notice the, effect., Forml, , Form, Tralfic Lights, , Red, , Yellow, , Forml, Traffic Lights, , Red, , Green, , Yellow, , Traffic Lights, , Red, , Green, , Yellow Light Says: WAIT, , Red Light Says: STOP, , Yellow, , Green, , Green Light Says: GO, , Variables in Visual Basic, Variable refers to a memory location used to store data temporarily. It has a unique name,, which is used to identify it in the program. Every variable has an associated data type such, as string, integer, etc. to specify the type of data to be stored., Dim statement is used to declare a variable in VB., , Syntax Dim Variable Name as Data Type, , EXample: Dim Radius, , as, , Data Typee, nteger, Inte, , String, , Integer will, , create, , a, , variable named Radius to store, , Example, , Description, It is used to store integer values, ranging from -, , 327668, , to+327668, , dring, , It is used to store a set of characters., , Date, , t is, , integer values., , used to store Date & Time based data, , Dim Marks as Integer, , Dim Name as String, Dim DOB as Date, , Let's Teate an application to calculate area and circumference of a circle, using variables., Create, Cre an interface as shown below and name the 2 buttons as CmdCalc and CmdClea., ype the code shown below for the command buttons CmdCalc and CmdClea., , Computer Plus-8, , 99
Page 5 :
Declerstions), , agrermi.vformibDesgn, , @enerel, , statements, , will, , These, , l a s s Forml, , Pubi, , PriVate, , Dim, , variables,, , ae, , Button1_Click (ByVa l, , Sub, , rad As, , Int eger 1, , values, , to s t o r e, , Rad will, , get, , Dim area As Integer, , rad, Cir, , 3.14, , rad, , Circumference,, , rad, , the results,, , rad, , 3.14, , 2, , A E X E B O Z .T e x t, , area, , e x L B o x 3 .T e x t, , These, , cir, , Sub, , Button2_Click (Byval, , TexLROK1., , Text, , -, , in, , using, , Rad, , variables, , As, , sender, , Arg) Handie hutton, , Area, , variable, , Area and, , and, , and s t o r e, , Cir resp., stored, , the values, will Display, TextBox2 and, o, n, Cir, Area and, , wn, , ReXLBeX2.Text, , Areaa, , statements, , System. Object,, , These, , type, , Area and, , TextBox1, , calculate, , in variables, TextBox3 resp., , End Sub, Lvate, , will, , statements, , *, , of Radius,, , value from, , These, , Val (TextBOK2.Text, , area, , t h r e e integer, , Circumference, Variable, , Dim c i r As Integer, , create, , statements, , TextBox1, , and, , ByVal, , e, , will clear the, , TextBox2, , and, , As, , System., , &ven LArgs) Handle, , But, , .click, , in, text written, , TextBox3, , resp., , TextBOx2. Text, , End Sub, End Class, , Writing Codes, , Note, Declaring, , a, , variable, , reserving, , for them. It is not required to declare l, it assigns the default variabie, new variable,, , memory space, , it. Whenever VB encounters a, and value. This is called implicit declaration., , variable before, , type, , means, , using, , over the variables. But, it il, user as it gives control, Although this type of declaration is easier for the, declaration. For explicit declaration, use the, advised to declare them explicity. This is called explicit, , statement Option Explicit before variable declaration., , Operators in Visual Basic, Operators, , are, , special symbols, , used to, , perform calculations,, , make, , comparisons, , and check, , logical conditions in a program., , For example, + operator is used to add two data items and> operator is used to compare two, values., , Arithmetic Operators, These operators are used for arithmetic operations., Example, , Description, , Operator, , Add: Add two values., , 12+4, , 16, , Subtract: Subtract one number from another., Divide: Divide one number by another., , 12-4, , 8, , Multiply: Multiply two numbers., Integer Division: Displays only the, , 12/4, , AS, , 12*4, , integer, , (without decimal places) after division., Modulus: Return the reminder after division., , Mod, , Result, , 12/5, 18 Mode 4, , Relational (Conditional) Operators, These, , operators, , return True, , or, , are used to, , False, , as a, , 100, , compare, , result., , two, , values. These operators compare the, , Computer Plus-8, , va
Page 6 :
Operator, , Than: ChecksDescription, whether a number, other or not., Example Result, is, greater, than, Less Than: Checks, whether a number is, or not., 86, True, less than other, Equal, Tor Checks, Fqual To:, whether a, Creater than or equal to: number is equal to other or not. 5<9 True, 4-5, False, whether, a, greater than or equal to otherChecks, number, is, or not., 8>-4, True, Less than or, equal to: Checks whether, GreaterT, , than or equal to other, Not equal to: This, , 7, , are not equal., , or, , a, , not., , number is less, , operator returns true if the, , Operator, OR, AND, , NOT, , True, , 46, , True, , numbers, , Logical Operators, , onerators are used to combine two or more, , 7=7, , conditions and display result, accordingly., , Description, , To check whether, any of the, statement is true or not. Will, result if any of the conditions given, give true as, is true., To check if both the, statements are true or not. Will, give true as result only if, both the conditions are true., To check if none of the, condition is true., , Control Statements, ne, , statements in, , a, , program are executed in a sequence. But, sometimes,, Control statements are useful in these situations., , we wish to, change, ue, are, used, to, They, control, r xecution of a program, either by repeating or by skipping the execution, 0r a set, of a statement, of, , Llow of control., , statements., , If..Then..Else Statement, s user, , han the, , or, making, statements, , decisions based, , the result of, , comparisons. If the condition is true,, written after "Then" are executed. But if the condition is false, then the, atementsStatements, written after ""Else" are ecuted., , Syntax:, , If Condition Then, , VB Statement(s), , Else, , on, , Example, Ifage>= 18 Then, MsgBox ("Hi, you are Adult"), Else, , VB Statement(s), , End if, , MsgBox (*Hi, you are not Adult"), End if, , H, , Comnputer Plus-8101
Page 7 :
Write, , a, , whether, program to check, , a, , person, , and, shown here, , is, , Adult or, , assign, , the, , not,, , names, , Create an interface a s, respectiveiy., to lextBox1, TextBox2 and Label3, code shown, pen, , based on, , T xtNamc,, , hi, his age., , TxtA ve, , xtAge and LAky, , below., , write the, the Command window and, , Stan Pagr Form.ve formlan (Designit, , (Dedarations), , Li (General)9, , Publ1C Class Forml, , (ByVal, Butt on1_Click, , Dim name As, Dim age As, , name, , sender, , As, , System. Object,, , ByVal, , Integer_, , >, , Handles, , Bue ., , Button.Clica, , of person, , to, , These statements will assign values entere, , in TxtName and TxtAge TextBoxes to Name nd, , 18 Then, , l2A3.Text, , "Hi" 6, , name, , &",, , you, , are, , =, , adult., , "Hi", , nane, , &",, , you, , are, , not, , =, , Els, R, , Age, , and, store Name, , Integer, , Val (txtage.Text, , If age, , system.EventAI gs), , These statements will create two variable, , tKLDAmE. Text, , age, , ehs, , .Text, , Age variables resp., , aduit. J \, , These statements will check whether Apei, , End If, End Sub, End Class, , greater than or equal to 18, or not. Depending, , upon the result of this condition, messages will, , Writing Codes, , be displayed accordingly., , Execute the program and check the output., , Forml, , 2, , Form1, Enter Your Name, , Nikhil, , Enter Your Neme, , Nikhil, , Enter Your Age, , 16, , Enter Your Age, , 26, , Check, , Check, , Hi Nikhil, you are not Adult., , Hi, , Nikhid, you, , are, , Adut, , Executing the Program, , Radio, , Button, , The radio button is, , a very useful control, in Visual Basic 2008., Radio buttons are multl, which, means the user can choose, exclusive,, one item out of a, only, also known as Option Button. The default, number of choices, , names are, , properties of Radio Button Control are RadioButton1, RadioButtonz, e, Name, The Name, property identifies a label while, Checked, This property indicates, writing the program., whether, the Radio Button is, not., Font, This property sets the, checked, or, font, font size, font, Fore Color, This property, style, etc., for the Raai, the, changes, foreground colour in Radio Button, used to display text., , The common, , Button, , Enabled, , Text, Visible, , This property sets, True or False at, run time, This property, display., contains the, text, which, is, This property, on the, Radio, the Rau, determines whether the displayedd on, 102, Computer Plus-8, control is, hidden., , utton, , visible or n
Page 10 :
F a m p l e, , ans Forms, , rubi, , Vate, , DLm n, , Case, e, , AS, , Btt.on 1 click, (Byval, , i er, , Case, , sender, , Integer, , ls 1, , As, , Text), , ase, , n, , System. Object,, , ByVal, , e, , As, , ls, , syst em., , Sunday"), 3, , CASe, ases, , Case, , Monday, , 13, , ls, , 4, , ls, , Case, , Tue sday )_, , b, , Wednes day, , Ase Is - 5, Case, , ls, , ), , These, , statements will, value stored, compare the |, in n, variable with, cases. After finding the, given, right case, it will, execute the, statements, , Thur sday"), , 6, , SASES 1s=6, , Case Is, , andins Butt, , "), , =, , Cases Is -, , EventArgs), , 7 C'Eriday"), , and, , MsgBex ("Saturday"), Case Else, , MsgBox("Enter, , End Select, End Sub, , Valid, , display, , name of, , written tor that, , a, , message box,, corresponding day ofcontaining, week., , Numbe r"), , End Class, , Do While Statement, It is, , used, , condition, , Using Select Case Statement, , repeatedly, , to, , execute a set of, statement(s), till the, remains true. It stops, the, , executing, , condition becomes false., , specified, , statements,, , as, , the, , Formb, Pin, , Syntax, Do While Condition, , VB Statements, , Loop, rite a, , Form6, , display even numbers between 2 to 20., Createan interface as shown here., program to, , Pran, , Write code (as shown below) for click event of the Command, , Button., xecute the program and click on Print button., Pubic Class Fomn, trivate Sub Button., n A T, DmnAs, Integer, , CHck, , 1ck (ByVal, , sender As System., , Object,, , 2, , while, , n, , <, , 21, , n1stBox1.Items.Add, 2, 1oOp, , (n), , As, , Systen, EventArgs), , Handles, , a, , Displaying Output, , But ton1 .Click, , variable, , less than, whether variable n is, It checks, the, statements, executes, 21. If true, it, written before loop., , class, , First tatement, will print, , e, , create, These statements will, 2., value, it, num and assign, , Eod Sub, , in n variable, , ByVal, , the value stored, , second, ncreasevalueand, of n by2., , statement will, , Using, , Do While, , Statement, , Computer Plus-8, , 105
Page 11 :
For.. Next Statement, , number of, a fixed, statement(s), , It is used to repeat a set of, the number of executions., , =, , uses, , a, , raunter to COu, , co, , Example, , Syntax :, For Counter, , It, , times., , For Count, , Initial Value To Final Value, , =, , I to 10, , Print Counter, , VB Statement(s), , Next, , Next, WndoApan-Moseh Vin k 2008Cprenstonon, , Write, , a, , program to, accept a number from, the user and display its, , Bon, , Table., , 2 OckedUrbo«, mbodax, , 92axàn, m r FormL e, , A Won Ferms, Cem, , arels, , hck, , Dotemecker, , Create an interface, as shown here., , '-40, , MathadTerßou, MonthCaendar, , Write code as showwn, in the given figure, for the click event of, Command Button 1, and, Button 2., , Nottykon, umencupDown, Pctuedox, , Radolon, , aRichTextBax, Textax, Tool fp, , w, , enus&Toeets, , Command, , Form7, , Creating an Interface, , Enter a Number to get Teble, , 51 5, , SHOW, , Dedarations), , Form, , 53 15, , B Public Class Forml, Private, Din nSub, AsButton1_click (ByVal sender As System.Object,, , 5 7-35, 5'8 40, , n, , va, , For counter, , 5*9 45, , l, , To, , As System. EventArgs), , Handles Buttonl.Click, , 10, , ListBoxl.Items.Add (n * * & counter, , 510- 50, , ByVal e, , (T9XTBOx1.Text), , *** & n*counter, , zndSub, , Class, , Displaying the Output, , Using For...Next Statement, , Exercises, A., , Tick, 1., , (), , the correct, , option. (Multiple Choice Questions), , Dim statement is used t o . ., , .. in Visual Basic., , (a) declare a variable, , (b) define the size, (d) define a constant, , (c) define comments, , 2., , Which statement of Visual Basic is used, , choices/conditions?, , to execute, , (a) Select Case Statement, , b), , (c) Case Statement, , 3Which property of PictureBox, (a) Image, , 106, , the statements based, , If Else, , on, , Statement, , (d) None of these, is, , used, , to, , (b) Picture, , display picture on it?, C)Visible, , Computer Plus-8, , d)View, , dffei, , en
Page 12 :
lrol, , Name thec Cont, , which, , n, , the user can, , choose, , only, , item, , one, , (a) Comnand Button, , ill, ill, , given, , usca to, , opcrators, , coInpare, , twO, , values in Visual Basic., , (a) Arithmctical Operator, , (b) Logical Operator, , (c)Relational Operator, , (d) None of these, word., , wIlh correct, , blanks, in the, , items., , (b) Radio Button, (d) Drop-down Box, , (c)heckBox, the, Name, , out of, , For...Next, , Control, , Relational, , Date, , variable, , ....data type is uscd to store date and time values., , statements are used to control the execution of a program., , 2, , refers to a memory location where data is stored temporarily., , 3., , A, * * * * * * * *, , 4, ., , State, , ., , are, , statenment, , is, , Relational Operators, , 2., , For, , 4., , 5., , Next, , loop, , are, , uscd to compare two values., , used to, , repeat, , statemenis are, , whether the following, , ., , 3., , D., , ., , Operators, , Truc, , repeat, , task for, , a, , or, , times., , False., , operations., , used for arithmetic, , is used to, , fixed number of, , of statement a, , set, , a, , a, , finite number of times., , to store data pernmanently., A variable is used, control the execution ofa program., statements are used to, condition remains, Looping, task, till the specified, For..Next, , true., , specified, loop keep repeating, , the following questions., Visual Basic 2008?, declare variable in, will, you, How, What is a Variable?, Operators., Relational and Logical, , Answer, , ., 2., , Differentiate between, , 3., , What do you, , 4.Write a, , short, , mean, , by, , a, , program, , culate, , to, , Enabled, , is, , LABAtiuity, , . Create a GU, aGUI, , 40,, , Name, , Student's, , percentage, , greater than, , variable, , declaration?, , all the, , decision Control, , CheckBox, and Visible property of, , the, , enter, , the total and, , Percentage, , Statements?, , Control, note on, , S.Differentiate between, , ite, , Implicit and Explicit, , of, , name,, , marks and, , o t h e r w i s e print, , "You, , Statements., , control, , and marks in, Roll No., , print, are, , a, , message, , *You, , application, , input, , based, , display, oft, then, aa Loss"., , Basic to, , failed"., , an, , item in, , input an, , otherwise,, , integerand, numbers, , display, , a n d find, , next, , the, , greater, , Visual, , jComputer, , 10 integers., , the, , Program, , in, , of, , product, Cost Price andincurred Loss. If thesuffered, have, made Profit or display "You, , Write a Program in, in Visual Basic to input two, 4rrogram, , passed" if, , the, , Seller has, Profit", whether the, Check, made a, two, have, inXTBoxes., You, , rite a, , are, , Selling Price, , to, , 3 subjects., , Plus-8107, , number.