0% found this document useful (0 votes)
129 views9 pages

Q1. Define Array With Syntax and Example

The document contains questions and answers related to various concepts in Visual Basic programming. It defines arrays and provides an example declaration. It explains the Select Case statement and its syntax. It describes the different data types in VB including numeric, string, date, boolean, and object types. It also discusses properties of scrollbars and methods to generate Fibonacci sequences and different looping statements in VB with examples. Finally, it defines concepts like properties, methods, events and discusses common properties for several VB controls.

Uploaded by

kanika_0711
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
129 views9 pages

Q1. Define Array With Syntax and Example

The document contains questions and answers related to various concepts in Visual Basic programming. It defines arrays and provides an example declaration. It explains the Select Case statement and its syntax. It describes the different data types in VB including numeric, string, date, boolean, and object types. It also discusses properties of scrollbars and methods to generate Fibonacci sequences and different looping statements in VB with examples. Finally, it defines concepts like properties, methods, events and discusses common properties for several VB controls.

Uploaded by

kanika_0711
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Q1. Define array with syntax and example.

An array is a collection of values of the same data type. The values in an array are called array elements. Array elements are accessed using a single name and an index number representing the position of the element within the array. Arrays are used in a database application to handle data for processing. Declaring Arrays Unlike simple variables, arrays must be declared with the Dim (or Public, or Private) statement followed by the name of the array and the index of the last element in the array in parentheses for example: Dim Ages(19) As Integer Dim Names(19) As String

Q2. What is Select Case? Write its syntax.


Select Case is preferred when there exist many different conditions because using If...Then..ElseIf statements might become too messy. The format of the Select Case control structure is show below: Select Case expression Case value1 Block of one or more VB statements Case value2 Block of one or more VB Statements Case value3 . . Case Else Block of one or more VB Statements End Select

Q3. Explain all data types in VB.


Visual Basic classifies the data types in two major categories:1) Numeric Data Types 2) Non-Numeric data types

1. Numeric Data Types Numeric data types are types of data that consist of numbers, which can be computed mathematically with various standard operators such as add, minus, multiply, divide and more. Examples of numeric data types are examination marks, height, weight, the number of students in a class, share values, price of goods, monthly bills, fees and others. In Visual Basic, numeric data are divided into 7 types, depending on the range of values they can store.

Type Byte Integer Long Single

Storage 1 byte 2 bytes 4 bytes 4 bytes

Double

8 bytes

Currency Decimal

8 bytes 12 bytes

Range of Values 0 to 255 -32,768 to 32,767 -2,147,483,648 to 2,147,483,648 -3.402823E+38 to -1.401298E-45 for negative values 1.401298E-45 to 3.402823E+38 for positive values. -1.79769313486232e+308 to 4.94065645841247E-324 for negative values 4.94065645841247E-324 to 1.79769313486232e+308 for positive values. -922,337,203,685,477.5808 to 922,337,203,685,477.5807 +/79,228,162,514,264,337,593,543,950,335 if no decimal is use +/- 7.9228162514264337593543950335 (28 decimal places).

2. Non-numeric Data Types Nonnumeric data types are data that cannot be manipulated mathematically using standard arithmetic operators. The non-numeric data comprises text or string data types, the Date data types, the Boolean data types that store only two values (true or false), Object data type and Variant data type .

Data Type String(fixed length) String(variable length) Date Boolean Object Variant(numeric) Variant(text)

Storage Length of string Length + 10 bytes 8 bytes 2 bytes 4 bytes 16 bytes Length+22 bytes

Range 1 to 65,400 characters 0 to 2 billion characters January 1, 100 to December 31, 9999 True or False Any embedded object Any value as large as Double Same as variable-length string

Q4. What is Scrollbar? Explain the properties and methods


The scroll bar control is a long stripe with an indicator that lets the user select a value between the two ends of the control. The ScrollBar control comes in two versions: horizontal and vertical. Other than their orientation, there are no difference between the two versions. The basic properties of the scrollbar control, therefore, are properly named Min, Max, and Value. Min : The controls minimum value Max: The controls maximum value Value: The controls current value, specified by the indicators position

Q5. Implement the program to generate the Fibonacci series


Private Sub Command1_Click() Dim a, b, c, i, sum As Integer c = 20 a=0 y=1 Print a

Print y For i = 3 To c sum = a + y Print sum a=y y = sum Next i End Sub

Q6. Explain all looping statements in VB with simple example.


Do Loop The formats are a) Do While condition Block of one or more VB statements Loop b) Do Block of one or more VB statements Loop While condition c) Do Until condition Block of one or more VB statements Loop d) Do Block of one or more VB statements Loop Until condition Example: Do while counter <=1000 num.Text=counter counter =counter+1 Loop * The above example will keep on adding until counter >1000. The above example can be rewritten as Do num.Text=counter counter=counter+1

Loop until counter>1000

For....Next Loop The format is: For counter=startNumber to endNumber (Step increment) One or more VB statements Next Example: For counter=1 to 10 display.Text=counter Next

Q7. What do you mean by Event driven programming? Discuss the advantages and disadvantages of Visual Programming.
In an event driven application , the code doesnt follow a predetermined path rather it executes different code sections in response to events . Events can be triggered by the users actions ,by messages from the system or other applications, or even from the application itself. The sequence of these events determines the sequence in which the code executes , thus the path through the applications code or the sequence of execution differs each time the program runs. Advantages 1) It is not just a language to program in but a whole graphicaldevelopment environment. This aids your programming skills allowingyou to concentrate on developing novel ideas instead of going over oldground. 2) It is quick to develop new programs. A newcomer will have a windowproudly opening and greeting you with "Hello World!" - always theprogrammers first program - in less than 5 minutes. 3) OLE programming is simple. This allows you to embed objects suchas Word documents and Excel spreadsheets with a minimum of fuss.

4) It can be used as a front end to SQL (or other databases) allowingthe user to enhance the way they access their data. 5) It is widely used for in-house application program development andfor prototyping. 6) It can also be used to create ActiveX and COM components for useonline or in desktop applications. 7) It is very simple to learn. As the name Basic suggests it useseasy to understand and remember terminology. 8) Because of its popularity there are many resources available to theuser - websites are numerous and books are plentiful for theprogrammer needing help. 9) Strict programming structures can be "turned off" to allow you toquickly develop a program - this could also be seen as a disadvantagewhen a bug arises! 10) Perhaps its strongest advantage is its simplicity. There is hardlyany learning curve for programmers to begin learning the language orcoming from another language. 11) VB is a "component integration language" which utilises Microsoft'sComponent Object Model ("COM") that allows parts to be bolted ontoprograms easily. These COM programs can be written in any language. Disadvantages 1) It is not suited to complex modern programming techniques. Becauseof its age little is being down to further the VB environment and ithas been largely superceded by VB.net and other languages (even byMicrosoft!). 2) Programs that are written in it tend not to be the quickest, thisis largely due to the additional code that is often included that isnot really necessary for your program to run. 3) VB is an interpreted language which again slows the execution ofyour program down.d) VB programs require large libraries to be present on your PC toenable them to work. If you do not have them the programmer eitherhas to supply them or you have to download them.e) Because of its over-simplified approach VB can produce programmersthat are sloppy in their work leading to workarounds having to beemployed. 4) Because of its age VB does not allow many modern techniques such asObject Orientated Programming. 5) As you can control the checking and warning systems in VB it oftenenables the programmer to write code that is very difficult to troubleshoot when a bug arises. 6) VB consists of features and syntax borrowed from other languages(often ones that are now no longer used). Watch a programmers facewhen you talk to them about "GoSub" and "On Error" commands! 7) OOP - Object Orientated Programming - is missing from VB, this isone of the most common techniques in all new languages allowing codeto be easily reused (although this is available in VB.net) 8) There is no threading support (although this is also available inVB.net). 9) The programs a programmer produces in VB are not portable andcannot be used on non-Windows systems. 10) Mathematical performance is poor which slows down the speed of yourprogram.m) Service Packs! Everyone knows about Microsoft's love of servicepacks to fix the many bugs that have accumulated over time.

Q8. Explain the term Property, Method and Event. Discuss some common properties for several Visual Basic controls (i.e. Alignment, Caption, Enabled, Name, ToolTipText and Visible ).
Property All objects have attributes that are used to specify and return the state of the object. These attributes are properties, and youve already used some of them in previous hours in the Properties window. Indeed, every object exposes a specific set of properties, but not every object exposes the same set of properties. To illustrate this point, Ill continue with the hypothetical pet object. Suppose that you have an object, and the object is a dog. This Dog object has certain properties common to all dogs. These properties include attributes such as the dogs name, the color of its hair, and even the number of legs it has. All dogs have these same properties; however, different dogs have different values for these properties. Figure 3.1 illustrates such a Dog object and its properties. Method In addition to properties, most objects have methods. Methods are actions the object can perform, in contrast to attributes, which describe the object. To understand this distinction, think about the pet object example one more time. A Dog object has a certain set of actions it can perform. These actions, called methods in Visual Basic, include barking, tail wagging, and chewing carpet (dont ask). Event An event, in a sense, is really a special kind of method used by an object to signal state changes that might be useful to clients (code using the object). In fact, the Visual Basic 2010 documentation often calls events methods (something that no doubt confuses new programmers). Events are methods that can be called in special waysusually by the user interacting with something on a form or by Windows itselfrather than being called from a statement in your code.

Visual Basic Controls Alignment : The commands on this menu align the edges or middles of selected controls: Lefts,Centers,Rights align the left, center, and right sides of thr selected controls; these commands are meaningful only if controls are stacked in a column

Tops,Middles,Bottoms aligns the top, middle, and bottom sides of the controls; these commands are meaningful only if controls are placed to each other To grid aligns the controls to the nearest grid point Caption: This property sets the text that is displayed on many controls that dont accept input , for example, the text on a label control, the caption of a Command button control, and the strigs displayed next to the checkbox and option button controls Enabled: By default, this propertys value is True, which means that the control can get the focus. Set it to false to disable the control. A disabled control appears gray and cant ac cept user input. Visible: Set this property to False to make a control invisible. Sometimes, you use invisible controls to store information that is used internally by the application and should not be seen or manipulated by the user Name: This property sets the name of the control, through which you can access the controls properties and methods.

Q9. Discuss the following elements of user interface i.e. Textbox, Label, Checkbox and Option button. Explain the following properties of Textbox control Locked b)MaxLength b) MultiLine c) PasswordChar d) ScrollBars e) Text.
Textbox: This control displays text that the user can edit. The Textbox control is a mini text editor, and its most important property is the text property, which can set the text on the control or read the text that the user enters. Label: This control displays text on a Form that the user cant edit. Labels commonly identify other controls and can be transparent, so the text appears to be placed directly on the Form. You set the labels text with the caption property. CheckBox: The checkbox control presents one or more choices that the user can select. The CheckBox controls main property is Value, and it is 0 if the CheckBox is cleared, and 1 if the CheckBox is checked. The CheckBox is a toggle. Every time its clicked, it changes status. Option Button : Option button appears in groups and the user can choose only one of them. The Option buttons main property is Checked, and it is True if the control is checked, and False otherwise. The Option button is a toggle. Every time its clicked, it changes status . TEXTBOX CONTROL

MaxLength property determines the number of characters that can be entered into a TextBox control If you attempt to insert text programmatically, the text will be truncated at the length specified by the MaxLength property. PasswordChar property is of type String Multiline : This property determines whether the TextBox control will hold a single line or multiple lines of text. By default, the control holds a single line of text. To change this behavior, set the Multiline property to True. ScrollBars: This property controls the attachment of scroll bars to the TextBox control if the text exceeds the controls dimensions. Single line textboxes can have a horizontal scroll bar so that the user can view any part of a long line of text. Multi-line textboxes can have a horizontal or a vertical scroll bar or both. Scroll bars will appear in multi-line textboxes even if they arent needed or the text doesnt exceed the dimensions of the control. Q10. WAP that will perform the following operations by using Form, Label, Textbox, and Command Controls.

You might also like