Professional Documents
Culture Documents
What is an Array? How do we create an Array in VB Program? Also write the syntax for creating a Multidimensional Array & Dynamic Array with suitable example .
Array is a linear collection of same type variable which allocates contiguous memory in the primary memory RAM. Alternately, we can say that Array is a common name shared by various variable of same type which allocates linear contiguous memory in the primary memory RAM. The main importance of array is to handle huge number of variables of same type very easily & efficiently by using index or, subscript of array blocks. It is also possible to declare huge number of same type variable using a single statement. Since, array allocates contiguous memory in the primary memory RAM. So, the access time of array variable is minimum. Consequently, the processing speed of program will be very fast. In Visual Basic, array is declared using the Dim keyword and the Redim keyword according with the name of the array & appropriate size. The general syntax of array declaration in visual basic is :
1. Title Bar 1. Standard Menu Bar * 2. Standard Toolbar * 3. Form Design Window * 4. Project Explorer Window * 5. Properties Window * 6. Toolbox * 7. Code Window 8. Object Browser Window 9. Form Layout Window 10. Immediate Window
Title Bar
The Title Bar is the top most horizontal line present in the VB IDE. The Title Bar contains the project name which is under development and the form name which is currently active in the under development application. In VB whole program is present under a project which contains all the forms as well as the internal coding system of application. A single project can contain more than one forms as the requirement of the application.
5
Standard Toolbar
Standard Toolbar is the third horizontal line from the top of VB IDE. Standard Toolbar contains symbolic representation which are popularly used in VB application development and present under different menus. Standard Toolbar is the easy way to perform appropriate action on the application without searching the menu item present under menu, only by clicking on appropriate symbol. Generally, Standard toolbar contains symbolic representation of new project, add form, menu editor, open project, save project, cut, copy, paste, undo, redo, start execution, stop etc. This toolbar also contains other components of the IDE. Such as- project explorer, properties, form-layout, object browser window, toolbox, visual component manager etc. The toolbar also contains the co-ordinates of the form starting from (0,0) up to the size which are currently selected on the current application.
Form-Design Window
The Form Designer Window is used to design appropriate interface required for the application. Generally, Visual Basic is used as a front end application tools for real life application. That means the only use of visual basic is to provide appropriate interface to the user to interact with the application. The formdesigner window is the place where the application interface is created by the user with the help of toolbox. The form is the main container to contain the controls supplied from the toolbox to interface the application data stored in the back-end DBMS. In real application the inputted data of Visual Basic program is generally stored in the back-end database present in MS-access. Oracle, SQL server or, any other DBMS present in the system. The formdesigner window can be designed externally at the time of development of the application using the toolbox. User can also add components by clicking on component menu bar present under project menu or, right clicking on toolbox
9
10
Properties Window
The Properties Window displays the field name and their current value of the selected object on the form-design window in two-column format. The properties windows is used to navigate all the properties (identifying properties) present in the selected object or, control in the application. Generally, the properties window displays properties alphabetically. It is also possible to display categorisely. User can change the properties values of the properties by selecting the property and supplying new value using keyboard or, mouse. The properties window also displays the name of the control thats properties are currently displayed in the properties window.
ToolBox
The toolbox is the most important component of Visual Basic IDE. The toolbar is present in the left side of the form-design window and contains popular
10
11
Code Window
The Code Window is used to write codes which are internally executed to perfectly execute the program and displays required information. The code window can be opened by double-clicking on any component of the form or,
11
12
Form-Layout Window
The Form-Layout Window is the preview of the forms of the current application. This window provides an idea to the user about the viewing size, colors of the forms of the application which is under development. This window is noninteractive. User can set the position of forms on the screen by dragging the forms in the form-layout window.
Immediate Window
The Immediate window is generally used to debug logical errors related to variables. This window displays the immediate values of variables which are under debug. Visual Basic automatically recognize syntax errors at the time of editing logical errors can be removed by checking the value of variables using the immediate window.
Qn.
12
13
Qn. What is Event Driven Programing? What are its properties? How does it take place in Visual Basic? Explain with example.
Ans. Event Driven Programing is those type of programming in which a particular event is fired automatically when that type of event is occurred. In Event Driven Programing various event actions are present. Such as- Click, DblClick, mousemove, mousedrag, gotfocus, lostfocus, keypress, keyrealised, keyup etc. & appropriate action is automatically performed by the Visual Basic. In Event Driven Programing a particular action event is performed by the user and internally appropriate code block written under that event is automatically fired & executed & required task is performed.
13
14
14
15
For exampleWrite a Visual Basic Application to change the Background color of a form when a MouseMove action event is arise on the form. Step 1: Design a form such as form1 and set the Caption COLOR EXAMPLE in the properties windowStep 2 : Open code window and select the MouseMove event & set the BackColor property of form1 randomly asPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Form1.BackColor = RGB(CInt(255 * Rnd), CInt(255 * Rnd), CInt(255 * Rnd)) End Sub The background color of form1 will automatically changed when the mousemove action event is arise on the form.
Qn. Explain the difference between Combo Box & List Box. Write down the method showing that a particular list box item is selected.
Ans. The List Box control is very popular control present in the toolbox to display list of elements. The list box displays one element in a row and can display more than one element at a time. Alternately, we can say that list box is a matrix of single column & multiple rows. When the display area is filled then a vertical scrollbar will automatically arise. By default, single element can be selected from a list box but it is possible to select more than one element from a listbox by changing the properties multiselect of the list box. The Combo Box is same as list box but only one element is displayed at a time in the combo box. In combo box multiple selection of element is not allowed. So, multiselect properties is not present. Combo box is useful to store huge number of elements.
15
16
Combo Box
1. Combo Box is arised using the Combo box control. 2. Combo Box displays only one element at a time. 3. In combo box, multiple elements cannot be selected. 4. Combo Box is useful for huge number of elements.
Qn. Write methods to connect any type of database using Add-In manager.
Ans. Methods to connect any type of database using Add-In manager are as followsStep 1: Click on Add-Ins on standard menu bar & go to Add-In manager and click. Step 2: Select VB6 Data Form Wizard and click on the check box loaded/unloaded under load behavior & click on Ok. Step 3: Click on Data-Form Wizard under Add-Ins menu & click on Next. Step 4: Select Remote(ODBC) and click on Next. Step 5: For Oracle DatabaseSupply DSN name created using Control Panel for Oracle Database. We must supply UserId as SCOTT, SYSTEM, INTERNAL etc. It is also possible to supply username created by the user itself. We must supply corresponding password according to the username-
17
Qn. What is Common Dialog Box? Explain Message & Input Box with a suitable example. Is form may be created as a dialog box, if yes how? Ans. Dialog Boxes are generally pre-defined interface which are
used to take input values or, display messages in Visual Basic Application. Alternately, we can say that the Common Dialog Boxes are a custom control that displays the commonly used dialog boxes such as- Open, Save As, Color, Font, Print, Help etc. When a Common Dialog Box is created on a form it automatically resizes itself & it is invisible at run-time. Common Dialog Boxes are generally present in the Microsoft Common Dialog Control 6.0 under the components. By supplying the action property appropriate dialog box can be displayed as the requirement of the user. If the action value is 1 then Open dialog box will be arise, if the action value is 2 then Save As dialog box will be open, if it is 3 then the Color dialog box will be open, if it is 4 then the Font dialog box will be opened and so on. In Visual Basic two types of dialog boxes are present according to the interaction with the user and the display behavior of the dialog boxes. Generally, The Dialog boxes are divided in two categories1. Model Dialog Box 2. Modeless Dialog Box A Model Dialog Box does not allow the user to continue with other application unless it is close. The Modeless Dialog Box allow shifting of focus between the Dialog Box & another form without closing the dialog box. Message Box
17
18
18
19
Qn. What do you mean by Control? Explain 5 important controls with their properties and event. How can you set in the control properties with the help of code? Ans. Controls are system-defined object present in the toolbox to handle
Visual Basic program. Generally, popularly used controls are present in the toolbox. Every control present in the toolbox is pre-defined object and so, it has three types of componentsIdentifying properties or, Data member which are displayed in the properties window after selecting the object. The next components are the events associated with the control. The events are automatically fired when appropriate action event is arised. User can define any events as the requirement of the user. The last property of control are the methods present in the object which can be called by supplying appropriate arguments associated with the object.
In Visual Basic the most popular controls are present1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. Command Button Text Box Picture Box Label Frame Check Box Option Button Combo Box list Box Horizontal Scrollbar Vertical Scrollbar
19
20
Command Button
Command Button is the most important control present in the toolbox to handle visual basic application. Using command button user can invoke any event associated with the command button and can perform any task.
The Command Button has the following popular properties: Name Appearance Backcolor Caption Enabled Font Picture Style Tool Tip Text Visible etc.
The name of command button which is generally command1,command2, Command3.. etc. is the internal identifier which can be used in coding to perform appropriate task associated with the command button. The Appearance property is used to set the appearance of the command button. Its value is 0 & 1. The 0 indicates flately appearance and 1 indicate 3D
20
21
The Command Button has the following popular Events: Click GotFocus LostLocus KeyDown KeyPress KeyUp MouseDown MouseMove MouseUp etc.
The Click event will automatically invoked when user click on the command button. The GotFocus event will automatically activate when the cursor or, control activate the button. Similarly, the LostFocus event will automatically activate when the control goes from the button. The KeyDown event will automatically invoked when any key present in the keyboard pressed by the user. Similarly, the KeyUp event will automatically activate when any key is
21
22
Text Box
The Text Box control is also a very important common control present in the toolbox. The textbox control is generally used to take input values from keyboard. It is also possible to supply values from other controls such aslistbox, combobox, checkbox or, other common dialog boxes. User can also display calculated results in textbox.
The general properties of TextBox are Name Alignment Appearance Backcolor Forecolor BorderStyle Datafield Dataformat Datasource Enabled Font Locked Multiline PasswordChar Scrollbars Tabindex Text
22
23
The name property is the internal name of textbox object which is generally text1, text2, Text3. etc. The Alignment property is used to set the display alignment of the box which is by default left alignment(0). 1 indicates Right alignment and 2 indicates Center alignment. The Appearance property is used to set the looking of textbox which is by default 3D(1). The 0 value indicates Flat looking. The BackColor property is used to set the background color. Similarly, the ForeColor property is used to set the foreground color. The BorderStyle property is used to set the borders or, unset borders around the textbox which is by default fixed single (1). The 0 value provide no border. The DataField property is used to set the field name of a database which is displayed during execution. The DataField can work if the DataSource is set. The DataFormat is used to set the format property of the textfield. Using this property user can specify the type of the textfield which is by default string. The DataSource property is used to link a textfield to a DataBase field. The Enabled property is used to activate or, deactivate the textbox. The default value is True. The Locked property is used to set the editable true or, false which is by default false. If the value is true then it is not possible to write anything in the textbox. The Font property is used to set the fonts of the textbox with style and size. The MultiLine property is by default false that means only one line can be inputted. It is also possible to set scrollbars around the textbox. This property can be activated automatically when the multiline is true. The PasswordChar property is used to set the password character during inputting into the textbox. This character is displayed during typing. This property can be set if multiline is false. The scrollbar property is used to set scrollbars around textbox. This property can be activate if the multiline property is True. The text property is used to set text into the textbox as well as get the text present in the textbox. The visible property is by default True. If the property is false then the textbox will be disappear.
24
The change event will be automatically called when any changing is performed on the textbox. The click event will automatically invoked when user click on the command button. The gotfocus event will automatically activate when the cursor or, control activate the button. Similarly, the lostfocus event will automatically activate when the control goes from the button. The keydown event will automatically invoked when any key present in the keyboard pressed by the user. Similarly, the keyup event will automatically activate when any key is released by the user. The keypress event will automatically called when any key printable or, non-printable is pressed by the user from the keyboard. The mousedown event is automatically called when any button of the mouse is pressed by the user. Similarly, the mouseup event will automatically called when the mouse buttons are released by the user. The mousemove event will be automatically called when the mouse is moving on the button.
The following popular methods are present with textbox Setfocus Move Refresh etc. The setfocus method is used to move the cursor to the textbox. The refresh method is used to refresh the textbox by deleting unwanted values. The move method is used to move the textbox from one location to another.
LABEL
24
25
List Box
List Box is one of the most important controls present in tool Box which contains a list of data in the form of string. User can browse the data in the list Box and select one or more items as the requirement of the user. The user can not edit the data in the list box directly. When the list box of data is to long then Visual Basic adds a vertical scroll bar. List box always displays some list of elements as the size of the list box. So, it occupies maximum space on the
25
26
26
27
Combo Box
The Combo Box control is as same as ListBox, the only difference is that it displays a single element which is currently selected but can contain any number of elements. The Combo Box comes from combination box which is the combination of Text Box and List Box. A Combo Box controls allows the user to select a predefine item from a list and enter new value not in the list. The Combo Box is also known as Dropped Down Box. The Combo Box
27
28
28
29
30
31
The Path property is a run time property. That sets or returns the path to the Directory in the Directory List Box. It is usually accessed in the change event for the Drive List Box. the path property is also used in the Directory List Box. Directory List Box change event to update the list of files in the File List Box. The popular events present in the Directory List Box :-
Change Click KeyPress KeyUp GotFocus LostFocus MouseDown MouseUp Scroll etc.
The change event will automatically triggered or called when any changing is performed in the Directory List Box to select other Directories. The popular methods present in the Directory List Box:-
32
*.* indicates all file *.cpp Displayed all cpp files *.java Displayed all java files
The file list box has the following popular events : Click DblClick KeyPress
32
33
FRAME
Frame control is a sub container as form which can contain any other control present in the ToolBox to form a new group. Generally in a particular form only one radio button can be selected at a time. It is not possible to select more then one radio button at a time in a particular form. But in some situation more then one Radio Button should be selected of different groups at a time. To implement the concept of grouping of radio button as well as check boxthe frame control is used to form different groups. User can drop any number of frames on a particular form and can design more then one groups of radio button as well as check box. It is possible to select a single radio button from each group. Ultimately more then one Radio Button can be selected at a time by grouping then using the frame control. The popular properties of Frame are: Appearance BackColor BorderStyle Caption
33
34
Radio Button
Radio Button is a Boolean type control thats value can be true or false. Radio Button is also called option Button. If the Button is selected then the value is true other wise it is false. The default value is false. It is not possible to select more then one Radio Button in a particular group. If user wants to select more then one Radio Button then the concept of grouping should be used using the frame control. The Radio Button control has the following popular properties: Alignment Caption Enabled Font Appearance BackColor Name Picture Style
34
35
Check Box
The Check Box control is as same as Radio Button but more then one check box can be selected at a time of a particular group. The other difference is the check box has three value ON, Off and Grayed (neither ON nor Off). If the check box is selected then the value is 1, if it is not selected then the value is 0 (zero), if it is grayed then the value is 2. Check Box has the following popular properties:Alignment Appearance BackColor Style Caption TabIndex DataSource DataField
35
36
Timer
The Timer is one of the most important and popular control present in the Tool Box. Those type of task which can be automatically executed should be present under the Timer event. The Timer control has only one event- that is Timer. User should writes the codes which will be executed automatically until the Timer enabled property False. Timer control is not displayed at the time of execution on the container. Timer has the properties Enabled, Interval etc. the enabled property is by Default True. If it is False then the
36
Fundamental Of Visual Basics Theory only Timer will not work. The interval is by default 0(zero). That means the cycle
will appear after 0 mili second. User can set the Interval as the requirement of the user. The Timer control has no methods.
37
SHAPE
The Shape control is used to draw different Shapes like square, rectangle, circle, oval etc. using this control user can display different predefine shapes by supplying value of the Shape property of the Shape Control. The Shape control can draw six types of predefine Shapes as:-
0 - Rectangle (By Default) 1 - Square 2 - Oval 3 Circle 4 - Rounded Rectangle 5 Rounded Square The Shape control has the following popular properties: Name BackColor BorderStyle BorderWidth FillColor FillStyle Shape Visible etc The Shape control has no events and no Methods.
Ques :- Discus the various type of application that can be created in visual basic ?
Ans :- Visual Basic is a front end programming language to design appropriate interface to interact with the data base present in other programming language
37
38
1. 2. 3.
Common ActiveX Control User Created ActiveX Control Extra ActiveX Controls or Component
Common ActiveX controls are those controls which are commonly used in visual basic application and present in the tool box automatically. Common ActiveX Controls are generally pointer Picture Box, Frame, Command Button, Label etc. User can create ActiveX controls as the choice of the user by clicking on add user control menu item present under the project menu using this option user can create any type of control for their later application. An application can also be treated as a control for the later application. Besides the above two controls huge no of extra control are present in visual basic which are commonly known as components. Components can be added by clicking on components present under project menu. It is also possible to add component by right clicking on tool box and click on components. Generally extra components are Status Bar, Tool Bar, Image List Box, Flex Grid Control and all the components present in the list.
38
39
Ques :- What do you understand by a tool bar. List down the various step to create a new Tool Bar? Ans :- Tool Bar is a horizontal single line container which contain different
buttons (Command Button) with images (Optional) to perform different task assigned with the corresponding buttons. Fore example in visual basic IDE the second horizontal line contains different symbols for the popular operations as well as controls necessary visual basic application. This line is called standard tool bar which is given in the VB IDE. User can create this type of tool bar as the requirement of the user to perform different task assigned in the tool bar components. User can create own tool bar which is present under the component Microsoft windows common control 6.0
40
Ques :- What do you mean by user interface. Discus the various uses of user interface and their use?
Ans :- User interface is the interaction point on which user can interact with the application and can perform various operations associated with the interaction point user generally interact with the controls present in the main container form and active other interfaces. In visual Basic two types of interfaces are present. 1. 2. Modal Modeless
Modal interfaces are those interfaces before closing it other interfaces cannot be work. Modeless interfaces are those interfaces in which user can work concurrently. Generally MDI applications are modeless and SDI applications can be modal as well as modeless as the choice of the user. A modal dialog box does not allow the user to continue with other application unless it is closed. The modeless dialog box allows shifting of focus between the dialog box and another for without closing the dialog box. Message box and input boxes is modal dialog box. It is also possible to display a form as a dialog box in modal or modeless form. In Visual basic three types of dialog boxes are present according to the creation of the dialog boxes. 1. Predefined dialog box 2. Standard dialog box
40
41
41
42
1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
Integer Long Byte Boolean Single Double Currency Date Variant String
Besides the above type user can create any type of variable as the requirement of the user by using the type and end type keyword. Suppose user wants to create a new type student in which name, roll, class, year fields are present to it can be possible as:42
43
Ques. What is a form? Why do we use it? Explain the procedure for loading and unloading forms, showing and hiding forms. How can one form be controlled from within another? Explain.
Ans. A form is the main container to contain different types of controls present in the Tool Box or in the component dialog box or created by the user. Form is a main class in which other classes can be inherit and corresponding action can be taken by the component according to the requirement of the user. In Visual Basic automatically one form is arise in any application which is form 1. All the other components can be present on the form. Without form components
43
44
44