You are on page 1of 13

1.

What is Visual Basic (VB)? Visual Basic (VB) y y A tool that allows you to develop Windows (Graphic User Interface -GUI) applications. is the third-generation event-driven programming language and integrated development environment (IDE) from Microsoft for its COM programming model.

2.

What are the parts of Windows Visual GUI?

Sidedocks Sidedocks are side windows which can be placed at any border of a KCachegrind window. They always contain a list of cost entities sorted in some way. y y y The Function Profile is a list of functions showing inclusive and exclusive cost, call count, name and position of functions. Parts Overview Call Stack

View Area The view area, typically the right part of a KCachegrind main window, is made up of one (default) or more tabs, lined up either horizontally or vertically. Each tab holds different views of only one cost entity at a time. The name of this entity is given at the top of the tab. If there are multiple tabs, only one is active. The entity name in the active tab is shown in bold, and determines the active cost entity of the KCachegrind window. Areas of a Tab Each tab can hold up to four view areas, namely Top, Right, Left, and Bottom. Each area can hold multiple stacked views. The visible part of an area is selected by a tab bar. The tab bars of the top and right area are at the top; the tab bars of the left and bottom area are at the bottom. You can specify which kind of view should go into which area by using the tabs' context menus. Synchronized View with Selected Entity in a Tab Besides an active entity, each tab has a selected entity. As most view types show multiple entities with the active one somehow centered, you can change the selected item by navigating inside a view (by clicking with the mouse or using the keyboard). Typically, selected items are shown in a highlighted state. By changing the selected entity in one of the views of a tab, all other views highlight the new selected entity accordingly.

Synchronization between Tabs If there are multiple tabs, a selection change in one tab leads to an activation change in the next tab, be it right of the former or under it. This kind of linkage should, for example, allow for fast browsing in call graphs. Layouts The layout of all the tabs of a window can be saved (View Layout). After duplicating the current layout (View Layout Duplicate (Ctrl++)) and changing some sizes or moving a view to another area of a tab, you can quickly switch between the old and the new layout via Ctrl+ and Ctrl+ . The set of layouts will be stored between KCachegrind sessions of the same profiled command. You can make the current set of layouts the default one for new KCachegrind sessions, or restore the default layout set. 3. What are the properties, methods and event of visual basic?  Properties y Properties define the characteristics of an object such as Size, Color etc. or sometimes the way in which it behaves y y behaves too All these characteristics of an object are called its properties. Docked under the Project Explorer window Exposes the various characteristics of selected objects Other characteristics affect not just the appearance of the object but the way it

 Method y Method is an action that can be performed on objects. y A method is a connected or built-in procedure, a block of code that can be invoked to impart some action on a particular object. A method requires an object to provide them with a context. Common Methods of Visual Basic Controls Method Use Move Drag Changes an object's position in response to a code request Handles the execution of a drag-and-drop operation by the user

SetFocus Gives focus to the object specified in the method call ZOrder Determines the order in which multiple objects appear onscreen

 Event

An event is what happens when you, for example, click on a button, drag the mouse, or double-click on an object. There are a large list of events that could happen within your application; you can choose the events that you want to respond to and then add programming code to tell VB what to do when that event occurs. Writing Event Procedures In order to perform an action when a button is clicked on (for example) you will need to write VB code. This code is entered through the Code Window.

You can see the Code Window by double-clicking on any control. You can then type the code associated with that object. On the left-hand side of the window you can see the name of the object you are currently

working on (in this case the Form) and you can see the event that you are writing code for on the right (in this case you are looking at the Load procedure). The code you will write is called an Event Procedure. The procedure's name consists of the name of the object (in the above example it is the Form) followed by an underscore and then the name of the event (in the above case it is the Load event). You write the code underneath the Private Sub statement and before the End Sub statement. So in the above example you would be writing code that will come into action when the form is loaded, for example, when it is first displayed on the screen. In the bottom left hand corner of the code window there are two buttons: Full Module View and Procedure View. y y 4. Full Module View will show all of the code associated with that form/module in one long list; there will be a horizontal line separating each procedure of code. Procedure View only shows the code that is relevant to the current event that is being viewed. Enumerate and define the data types modules and operators in visual basic  MODULES Three kinds of modules: Form Modules- a single or simple application Standard Modules- a separate module containing a procedure is created that implements the common code. Class Modules- (.CLS filename extension) are the foundation of the object oriented programming in Visual Basic. New objects can be created by writing code in class modules.  OPERATORS IN VISUAL BASIC ARITHMETICAL OPERATORS

Operators + / \ * ^ Mod &

Description Add Substract Divide Integer Division Multiply Exponent (power of) Remainder of division String concatenation

Example 5+5 10-5 25/5 20\3 5*4 3^3 20 Mod 6 "George"&" "&"Bush" 10 5 5 6 20 27 2 "George Bush"

Result

RELATIONAL OPERATORS Description Greater than Less than Greater than or equal to Example 10>8 10<8 20>=10 True False True Result

Operators > < >=

<= <> = y

Less than or equal to Not Equal to Equal to

10<=20 5<>4 5=7

True True False

LOGICAL OPERATORS Operators Description OR Operation will be true if either of the operands is true AND Operation will be true only if both the operands are true

5.

Identify the constants , data type conversion and built in functions

Constants are named storage locations in memory, the value of which does not change during program Execution. They remain the same throughout the program execution. When the user wants to use a value that never changes, a constant can be declared and created. The Const statement is used to create a constant. Constants can be declared in local, form, module or global scope and can be public or private as for variables. Constants can be declared as illustrated below. Public Const gravity constant As Single = 9.81 Data Type Conversion Visual Basic functions either to convert a string into an integer or vice versa and many more conversion functions. A complete listing of all the conversion functions offered by Visual Basic is elucidated below. Conversion To Boolean Byte Currency Date Decimals Double Integer Long Single String Variant Error Function Cbool Cbyte Ccur Cdate Cdec CDbl Cint CLng CSng CStr Cvar CVErr

A conversion function should always be placed at the right hand side of the calculation statement. Visual Basic Built-in Functions Many built-in functions are offered by Visual Basic fall under various categories. These functions are procedures that return a value. The functions fall into the following basic categories that will be discussed in the follwing sections at length.

y y y 6.

Date and Time Functions Format Function String Functions What are variables in visual basic? Variables are the memory locations which are used to store values temporarily. A defined naming strategy has to be followed while naming a variable. A variable name must begin with an alphabet letter and should not exceed 255 characters. It must be unique within the same scope

Explicit Declaration  Declaring a variable tells Visual Basic to reserve space in memory. It is not must that a variable should be declared before using it. Automatically whenever Visual Basic encounters a new variable, it assigns the default variable type and value. This is called implicit declaration. Though this type of declaration is easier for the user, to have more control over the variables, it is advisable to declare them explicitly. The variables are declared with a Dim statement to name the variable and its type. The As type clause in the Dim statement allows to define the data type or object type of the variable. This is called explicit declaration. Syntax Dim variable [As Type] For example, Dim strName As String Dim intCounter As Integer  Using Option Explicit statement  It may be convenient to declare variables implicitly, but it can lead to errors that may not be recognized at run time. Say, for example a variable by name intcount is used implicitly and is assigned to a value. In the next step, this field is incremented by 1 by the following statement Intcount = Intcount + 1  This calculation will result in intcount yielding a value of 1 as intcount would have been initialized to zero. This is because the intcount variable has been mityped as incont in the right hand side of the second variable. But Visual Basic does not see this as a mistake and considers it to be new variable and therefore gives a wrong result.  In Visual Basic, to prevent errors of this nature, we can declare a variable by adding the following statement to the general declaration section of the Form.

 Option Explicit

 This forces the user to declare all the variables. The Option Explicit statement checks in the module for usage of any undeclared variables and reports an error to the user. The user can thus rectify the error on seeing this error message. The Option Explicit statement can be explicitly placed in the general declaration section of each module using the following steps. y y y Click Options item in the Tools menu Click the Editor tab in the Options dialog box Check Require Variable Declaration option and then click the OK button

Local Variables  A local variable is one that is declared inside a procedure. This variable is only available to the code inside the procedure and can be declared using the Dim statements as given below.  Dim sum As Integer  The local variables exist as long as the procedure in which they are declared, is executing. Once a procedure is executed, the values of its local variables are lost and the memory used by these variables is freed and can be reclaimed. Variables that are declared with keyword Dim exist only as long as the procedure is being executed.

Static Variables  Static variables are not reinitialized each time Visual Invokes a procedure and therefore retains or preserves value even when a procedure ends. In case we need to keep track of the number of times a command button in an application is clicked, a static counter variable has to be declared. These static variables are also ideal for making controls alternately visible or invisible. A static variable is declared as given below.  Static in Permanent As Integer  Variables have a lifetime in addition to scope. The values in a module-level and public variables are preserved for the lifetime of an application whereas local variables declared with Dim exist only while the procedure in which they are declared is still being executed. The value of a local variable can be preserved using the Static keyword. The follwoing procedure calculates the running total by adding new values to the previous values stored in the static variable value. Function RunningTotal ( ) Static Accumulate Accumulate = Accumulate + num RunningTotal = Accumulate End Function

 If the variable Accumulate was declared with Dim instead of static, the previously accumulated values would not be preserved accross calls to the procedure, and the procedure would return the same value with which it was called. To make all variables in a procedure static, the Static keyword is placed at the beginning of the procedure heading as given in the below statement.

Static Function RunningTotal ( ) Example The following is an example of an event procedure for a CommandButton that counts and displays the number of clicks made. Private Sub Command1_Click ( ) Static Counter As Integer Counter = Counter + 1 Print Counter End Sub The first time we click the CommandButton, the Counter starts with its default value of zero. Visual Basic then adds 1 to it and prints the result. y Module Levele Variables

 A module level variable is available to all the procedures in the module. They are declared using the Public or the Private keyword. If you declare a variable using a Private or a Dim statement in the declaration section of a modulea standard BAS module, a form module, a class module, and so onyou're creating a private module-level variable. Such variables are visible only from within the module they belong to and can't be accessed from the outside. In general, these variables are useful for sharing data among procedures in the same module: ' In the declarative section of any module Private LoginTime As Date ' A private module-level variable Dim LoginPassword As String ' Another private module-level variable You can also use the Public attribute for module-level variables, for all module types except BAS modules. (Public variables in BAS modules are global variables.) In this case, you're creating a strange beast: a Public module-level variable that can be accessed by all procedures in the module to share data and that also can be accessed from outside the module. In this case, however, it's more appropriate to describe such a variable as a property: ' In the declarative section of Form1 module Public CustomerName As String ' A Public property You can access a module property as a regular variable from inside the module and as a custom property from the outside: ' From outside Form1 module... Form1.CustomerName = "John Smith" The lifetime of a module-level variable coincides with the lifetime of the module itself. Private variables in standard BAS modules live for the entire life of the application, even if they can be accessed only while Visual Basic is executing code in that module. Variables in form and class modules exist only when that module is loaded in memory. In other words, while a form is active (but not necessarily visible to the user) all its variables take some memory, and this memory is released only when the form is completely unloaded from memory. The next time the form is re-created, Visual Basic reallocates memory for all

variables and resets them to their default values (0 for numeric values, "" for strings, Nothing for object variables). y Public vs Local Variables

 A variable can have the same name and different scope. For example, we can have a public variable named R and within a procedure we can declare a local variable R. References to the name R within the procedure would access the local variable and references to R outside the procedure would access the public variable 7. What are the procedures in creating program in visual basic?

Step 1: Create a Project in Visual Basic. Your first step in creating a Visual Basic program is to open Visual Studio and create a project. You will do this when creating any Visual Basic program. 1. From the Windows Start menu, choose Microsoft Visual Basic 2005 Express Edition. The "Welcome to Visual Basic Express" screen appears. This is the interface for Visual Basic 2005 Express Edition, also known as the integrated development environment or IDE. 2. On the File menu, click New Project. The New Project dialog box opens. 3. Select Windows Application and click OK. A new form displays in the IDE, and the necessary files for your project are added to the Solution Explorer window. If this is the first Windows Application project that you have created, it is named "WindowsApplication1".

Step 2: Create a User Interface It is now time to start building your Web browser. You will use Microsoft Visual Basic 2005 Express Edition to build the user interface (the visible part that users interact with) by adding controls from the Toolbox to the form. The Toolbox is on the left side of Visual Studio and consists of several tabs such as Data, Components, and All Windows Forms. Inside each tab is a set of entries that represent controls or components that you can add to your application. For example, the All Windows Forms tab has entries named TextBox, Button, and CheckBox that represent controls that you can add to your application by dragging them onto the form.

To add controls to your application

1.

Click the Toolbox panel. The Toolbox opens. Tip The Toolbox is easier to use if you keep the window open. You can do this by clicking the Auto Hide icon, which looks like a push pin.

2.

Click the All Windows Forms tab of the Toolbox, select the Panel control, and then drag a panel onto the top-left corner of the form. Tip If you have difficulty finding the correct control, right-click on the Toolbox and then select Sort Items Alphabetically.

3.

From the same tab, drag a Button control and place it on top of the Panel. Tip You can reposition controls using a drag-and-drop operation. You can also resize controls by clicking and dragging the edge or corner of the control.

4. 5.

From the same tab, drag a TextBox control and place it on top of the Panel. Finally, from the All Windows Forms tab, select a WebBrowser control and place it below the Panel. Tip If you kept the Toolbox window open, you may want to close it now to give yourself more room to work. You can do so by clicking the Auto Hide icon again.

Step 3: Customize Looks and Behavior

In the previous lesson, you created a user interface by adding controls to your application. At this point, however, it neither looks like nor functions as a finished application. In this lesson, you will set properties to control the appearance of your controls, using the Properties window. . To set the properties of your controls 1. In the Form Designer, select the Panel control.

The Properties window in the lower-right corner of the IDE displays all properties for the Panel control named Panel1. 2. In the Properties window, select the Dock property, and then click the arrow to the right. A small property-selection window with several boxes is displayed. Tip The Dock property is found under the Layout category. You can sort the properties alphabetically by clicking the AZ button in the Properties window. 3. 4. Click the top box in the property-selection window to set the Dock property to Top. The Panel control expands to fill the top of the form. In the Form Designer, select the WebBrowser control. In the Properties window, set its Dock property to Fill by selecting the Dock property, clicking the arrow to the right, and selecting the center box in the property-selection window. In the Form Designer, select the Button control. In the Properties window, select the Text property of the Button control. In the right-hand column, delete Button1 and replace it with Go!. Resize or relocate any of the controls, and resize the form to suit your taste. Note The TextBox and Button controls must remain on top of the Panel, or you will not be able to see them when you run the application.

5. 6. 7.

Step 4: Add Visual Basic Code

In the previous lesson, you used the Properties window to configure the properties of the controls on your form. In this lesson, you will add the code that will control your program's functions.. To add code and functionality to your program 1. In the Form Designer, double-click the Button control. A new window called the Code Editor opens. This is where you add all the code for your program. 2. In the Code Editor, type the following. VB WebBrowser1.Navigate(Textbox1.Text)

This code will run when users click the button.

Tip When the Code Editor opens, the cursor is automatically located inside the Button's procedure - you can just start typing.

Step 5: Run and Test Your Program Now that your program is complete, it is time to run and test it. For complex programs, testing can be a long and difficult process, which will be discussed in detail in a later lesson. Happily, for this program, all you need to do is run it! To run your program 1. 2. Connect your computer to the Internet. On the Debug menu of the Visual Basic IDE, click Start Debugging. This command runs your program. Tip A shortcut to run your program is to press F5. 3. In the text box, type http://www.microsoft.com and click the Go! button. The WebBrowser control in your program navigates to the Microsoft home page. From there, you can navigate through any related links. To visit another Web page, type the address in the text box and click the Go! Button. 4. To close the program, on the Debug menu, click Stop Debugging. Tip You can also end the program by clicking the Close button on the top-right corner of the form.

References http://members.tripod.com/acha_ean/vb6_se/ch06.htm#Heading1 http://visualbasic.freetutes.com/learn-vb6/lesson1.1.html http://www.ehow.com/list_7593761_methods-visual-basic.html http://www.virtualsplat.com/tips/visual-basic-procedures-functions.asp http://visualbasic.freetutes.com/learn-vb6/lesson6.2.html http://visualbasic.freetutes.com/learn-vb6/lesson2.1.html http://msdn.microsoft.com/en-US/library/eyzd6e34%28v=VS.80%29.aspx http://msdn.microsoft.com/en-US/library/s3hwe76s%28v=VS.80%29.aspx http://msdn.microsoft.com/en-US/library/y7x894ky%28v=VS.80%29.aspx http://msdn.microsoft.com/en-US/library/bx0kecz4%28v=VS.80%29.aspx http://msdn.microsoft.com/en-US/library/s878kxw0%28v=VS.80%29.aspx Lectures from higher years :)

You might also like