It stands for integrated development environment. This word describes the interface and environment used to create applications. It is called integrated because you can access all the development tools needed for one screen. Visual basic is not just a language but also provides an IDE in which you can develop run, test and debug your applications. Once you start VB you will see, a window which will ask you to select type of project.
Project: A project is an application which you develop using IDE. The different types of projects you can develop are: 1 Standard EXE: A standard exe project is a typical application. Most of the projects developed in VB are standard exe projects.
This two types of projects are identical in functionality but are packed differently. Use this type of projects to develop your own active x controls. Menu bar: Menu bar contains the command use full to work with VB. The basic a menus available in the menu bar are a. File menu: It contains commands for opening and saving projects. It also contains commands for listing recent projects and for creating executable files.
Edit menu: It contains commands like undo, copy, cut, paste, redo….. View menu: Contains commands for showing or hiding components of IDE. Project menu: Contains commands that add components to the current project. Format menu: Contains commands for aligning the controls on the form.
Run menu: Contains the start, break, end, application commands. Debug menu: Contains debugging commands. Tools: Contains tools which are helped in building active x components.
Help: Contains information which will help you to work with VB. Tool bar types: Tool bar gives quick access to menu commands. To open and close toolbars. Choose view tool bars. Project Explorer: The window titled as project is the project explorer, which displays the components of the project. Tool bar: Toolbar contains icons of the control. The can be placed on a form to create an application. To place a control first selects it with the mouse over the Form.
Instead of crowding a tool box with all the controls you need for a project you can create several tabs with icons o tool box and organize the controls according to them. To add a new tab to the tool box follow the steps. Right click on the tool box to open the pop up menu 2. VB displays a new tab button on the tool box. Selected the components option and VB displays a list of all active x controls installed on your system.
To add the required active x controls to the tab check big in front of the names f the control. Form designer: The form designer is the main window which appears in the middle of the screen and in it you can design and edit the application. The same window displays a text editor in which you can enter the application code so the form designer tool displays two windows.
The Form Window 2. The Code Window To switch between the two windows choose an icon in the project explorer namely view code to open the code window or choose view Object to open the specified form. Properties window: Properties window to contain a set of properties for the selected Object or controls properties are the character sticks of an Object such as its size, caption, color and soon you can open the properties window for a particular Object by selecting it and choosing view properties from the menu bar.
You can also change the appearance of the Object on the form through properties window. Properties can be Object characteristics or attributes every Object in the tool box has their own properties. A property for an Object can be set either at design time or at run time.
To set the properties at run time we generally use dot notations. The general form of dot notation Object name property name value.
If it is string enclose it with in quotation. For example: Form 1. It cannot be set at run time some properties are available only at run time. To set property at design time press F4 keys after selecting the Object. Some of the common properties in every Object available are: 1 Name: - It set the Object name through which the Object can be manipulated.
These values determine whether user can manipulate the Object or not. This value determines whether user can see the Object or not. Object browser window: Object browser allows the user to browse through various methods, events, properties, that are available for a particular Object. You can access Object browser from view menu or by pressing F2 key Object browser provides the following information on both in Objects and custom Objects 1.
Classes 2. Methods 3. Events 4. Properties 5. Constant values Components of Object browser: 1. EX: you must choose word project from the project library drop don list which immediately displays all the Objects of that project. Class list: It shows the available classes for the project selected in project library drop down list.
Members of list: Displays the available numbers for the class list that is method, constants, events, properties are the members of the class list. Search text box: In this text box enter the string you want to search for. Show definition button: Click this button to display code window for the Object selected in the class list. Navigating with Object browser: a.
First activate the Object browser by selecting view Object browser from the menu bar or press F2 key. In the project library drop down list select the name of the project that you want to view.
In the class list select the class you to work with. If you want to work with a particular member of the class select in the members of the list. You can view the information about the member selected at the button of the browser window.
Its purpose is to simply give the user model i. This window is also useful for knowing how the form looks when your application is running. To open the form layout window choose, view form layout window from the menu bar. Once the form layout window is opened click the form in the form layout window and move it to the center. You can examine or change the values of the application variables. It is one of the reasons for the popularity of VB.
It let you to step into the application code change the value of the variables and even insert statements in the code and then continue the execution application. Customizing the tool bar: One of the main features in the IDE is the availability of the tool bars.
If you are really confused with all tool bars you can customize these tool bars as follows. Moving a toolbox button: If you want to move some buttons on the toolbar. Follow these steps: 1 Right click the menu bar or tool bar at the top of the screen. Removing and Adding a menu item: If the tool bar does not contain short cuts you want, then you customize them further to get what you want, 1 Right click the menu bar or tool bar at the top of the screen.
In this tab you have two flames. Code setting frame: it contains the options that will effect your code window editor. This option is: a Auto list members: Check this check box to display a list of members methods, properties belonging to an Object. This if you prefer to see one procedure in the editor at a time.
You can set grid lines using form grid setting frame. You this line to align the control on the form. Error trapping selection allows to set error trapping i. Compile sections contains the following options. Set compile on demand. Enable back ground compile allow you to continue working in VB while it compile your applications, this setting is enabled by fault.
Checking show tool tips allow VB to show you tool tips that describe the control. Docking tab: By selecting the clocking tab you can determine which windows with in IDE are docks able. The environment tab: The environment tab is the most important place to customize settings with in IDE. When you are involved in serious project developments you want to save your work often.
To do this to check the promote to save changes option. The advanced tab: 1. Selecting the back ground project load options will force VB to load projects while you continue working. This is useful because it allows you to continue working while a project loads. Leave the notify when changing shared project items option checked. A variable has a name and a value when a variable has a text value it should be enclosed with in quotations.
Example: - Dim name as string. Dim meters as integer. In VB having two type of declarations. They are Explicit and Implicit Declarations. You can declare multiple variable of same type i. Dim a, b, c as integer. So, what data type is declared we have to enter the same type of data. That means variable type is variant.
In such case VB can assigns run type of data can be assigned at runtime. They are: 1 Integer and long 2 Single and double 3 Integer and long Any variables declared as integer or long stores whole numbers. Example: Dim a as integer Dim b as long Single and double: variables declared as single or double stores fractional numbers.
Double gives the accurate results compared to single. Example: Dim x as single Dim y as double 2 String variables: String data type stores only text and its value is enclosed with in quotations.
Example: Dim var name as string. Example: Dim var name as byte This data type is generally used to store images or sounds etc.
It is declared using the word Boolean. Example: Dim var name as Boolean. Any variable Declare as variant is handle by VB according to the variables constants. If you assign a string value, VB treats it as an integer. If you assign a string value, VB treats it as a string. Its type depends on the contents you can also specify variant type to make the code clear. Example: Dim a as variant. Example: A form has two command buttons command1and command2 you can declare two object variables as Dim a as command1 Dim b as command2 Each of these two object variable can be set to one of the command buttons present on the form with the following statements.
Example: To change the caption properties of the command button use the statement as follows. Scope of a variable: The scope of a variable is the limit of a variable with in different sections of applications. If a variable is declared with in a procedure then only the code present in that procedures can access that variables.
This variable does not exits for the rest of the application so this variables scope is limited to a procedure and such variable ate called local or private variables. Example: You are writing the click event procedure of a command button.
These variables are called form wide variables. Such variable can be accessed by all procedure with in the some form. All such variables must be declared in the forms declaration section using Dim statement. Such variables are called as public variables. Public variables must be declared in module section.
Public variables may not appear with in procedures. These must be declared in the declaration section of a module. Life time of a variable: The word life time means the period during which all variable retain their values.
Variables declared as public exists for a life time of the application. Life time declared with in procedures with Dim statement exists for life time procedures in which there are declared.
When the procedure finishes local variables allocated variables return to the system. Variables declared in a form outside any procedure exists for the life time of the form i.
If the form is loaded again the variables value is uninitalised. Constant Variable: Variables that do not change value during the execution of the program are called constants variables. Constant variables many times in your code. Declaring constants: The manner in which you declare constants is similar to the manner in which you declare variables. The syntax for declaring constant variables is as follows.
The data type of constant variables is determined by the value you assign to it. Constant can also have spoken.
A constant variables declared with in a procedure can be access only by that procedure. Constant declared as public can be accessed by the entire application to declare public constants mention public infornt of constant word. Constants declared in a module as public can be accessed by every procedure. Variable type conversations: In some situations you will need to convert variables from one type to another for this VB provides different data type conversation functions.
Dim a as Integer. Individual variables can hold single value such as a number data or string. Arrays hold sets of data in array has a name as variable has and the value stored in array can be accessed by its index.
Suppose if you want to store sixteen salaries one for employee. You can declare 16 variables or you can declare an array with 16 elements. An array generally contains series of values which are distinguished by means of index. Declaring Arrays: Arrays must be declared with Dim statement followed by the name of array and the maximum number of values it can hold. A 0 is the salary of first person; a 1 is the salary of second person and so on.
Explicitly you can specify the type of the arrays elements using as key word. Example: Dim a 10 as integer Dim name 10 as string. All the elements now in an array have the same data type. When the data type is variant for array then elements of an array can contain different types of data. The number that appears in the parenthesis after the array name is called index or upper bound of an array. For example: Dim salary 16 as integer In these 16 is the upper bound the lower bound starts from 0.
The upper bound in 1 less than that mentioned in parenthesis in you can explicitly specify the lower limit of the array. Example: Dim salary 1 to 16 as integer. Multi Dimensions array:- Single dimensional array stores single dimensional data. Multi dimensional arrays stores data with more than two dimensional arrays has two indices.
In such case you can declare dynamic array. To create a dynamic array declare it as usual with dim statement but do not specify its dimensions. Re dimension dynamic user account user is the user enter value which specifies the dimension. The re dimension statement can appear only in a procedure re dimensions statement can change the bounds of the arrays. But not the no.
Forcing variable declaration:- VB does not enforce variable declaration. But for clean coding it is always better to declare variables. This statement tells the compiler to check each variables whether it is declared or not before using it and issue an error message if you attempt to use a variable with out declaring it. If you omit the option explicit. Statement VB creator variables as needed by itself. Let us consider an example following statement converts Germany dollars to US dollars.
Another reason of declaring variable in advances is to simplify debugging in large application. To avoid this application must enforce variables declaration then the compiler complain the DM2 USD variable has not been declared. Procedures: Procedures are useful for implementing repeated tasks such as frequently used calculation. Suppose you are writing an application that at some point it converts centimeters to inches or calculates the smaller of two numbers.
This task in repeated in several places. To repeat in several places a procedure can be writing the same code in several places. The benefits if writing a procedure is it is easy to understand and easy to maintain and the code in clear procedures are of two types.
A commands click event procedure is a sub routine which is called each time the button in clicked. The statements in the sub routine are executed and when the end sub in reached, the control returns to the calling functions. It is possible to exit from a sub routine in between using exit statements. Sub routine does not report anything to the calling program. The statements making up a function are placed in a pour of functions and end functions. Because functions report a result to the calling program it must have a type.
Sum in a function that returns tomorrow date by adding one day to the current date. Because functions report the result to the calling program, the sum function has a type a date. Arguments: Argument is a value you pass to the procedure and the procedure acts on it. This is how the sub routine and functions communicate with the application. Key ASCII is an argument which conveys the information about the key pressed functions also accepts arguments and in many cases more than 1.
Ex: The function sum accepts two numbers and returns the total of that two numbers. When you call procedure, you must supply values for all the arguments specified in the procedures definition and in the same order. Call him 10, 15 You can also omit the call statement and call to the sub routine by its name and arguments with in parentheses. Calling functions: Functions are called by name a list of arguments follows the name in parentheses.
Argument passing mechanism: There are two mechanism used to pass arguments. When passing arguments by value. The procedure sends only the copy of the argument. Even if the procedure changes the argument value. They are not permanently changed.
The advantages of passing argument by value are only the program in which they are declared can change their value. Now the value n1 and n2 are printed as 10 and This is because the arguments are passed by value.
When the argument are passed by value the changes mode to the function argument a, b take effect only with in the function. The value n1 and n2 are not changed permanently. Also returns some value. Function statement. End if. End if 3 Select case. End if: This structure tests the conditions specified and if it is true, executed the statements, specified after the condition.
This is used mainly to test a single condition. End if: This statement executes one block of statement if the condition is true and another if the condition is false. The general syntax is as follows. Another variation of If …. The conditions are evaluated from top to button if any one of them in true. The corresponding block statements are executed and if name of the conditions are satisfied the else block will be executed. In the above example the expression is day date.
The value of that expression is compared with each case value. Some case statements can be followed by multiple value which are separated by , commas. Looping statement is an important plant of any program. VB supports the following loop statements. Do end 3 For Loop: The Do Once the condition becomes false the loop in terminated.
There are two variations of do The general syntax is Do Once the condition becomes false the statements after the loop will be executed.
If the condition is initially false. The statements will never execute. Example: The below Do Do end: The while Once if the condition is false the statements after while Do end will be execute.
Control is written to the while statement again which evaluates the condition again this process is repeated until the condition becomes false. The for……next loop uses counter variables that increases or decreases in value during each repition of the loop. The loop in executed until the counter variable reaches the end value. The counter variable increased by one changing the old value in the loops body will not have any effect to the end value.
Once the condition is false the statements after while end will be executed. It has the following syntax. The general syntax of input box function is: Inputbox is prompt , default , response , y pos , title The above arguments are described as follows: Prompt: If required a string expression this displays the massage us the dialogue box. Title: It is optional it also requires string expression this displays the title of the dialogue box.
If committee the application name is displayed. Defaults: It is optional. This is displayed in the text box as the default value. If no input is provided, it committed the text box is displayed as empty. Response: It is optional it requires numerical expression this specifies the width of the input box. Y pos: It is also optional and requires numerical expression this specifies the light of the input box. Msgbox function : This displays a message in a dialogue box waits for the user to click a button and return an integer indicating which button the user has clicked.
Msgbox prompt button title Prompt: It requires a string expression. This displays a message in a dialogue box. Button: Button argument is a numeric expression which is optional. Can you donate it to the Lending Library? Learn More. This edition doesn't have a description yet. Can you add one? Add another edition? Includes index. Visual Basic 6 secrets Harold Davis.
Donate this book to the Internet Archive library. If you own this book, you can mail it to our address below. Want to Read. Delete Note Save Note. Check nearby libraries Library. An object has a set of properties. Each property of the object has a value. Event handlers transfer data to procedures that complete the task. The results of these procedures are returned back to other screen objects, e. A procedure attached to an object, such as a button, is a command used to make something happen, e.
Show where FormXX is the new form name. Activity 2 1. Open a new form and change its name to ColourChanger. Place the following objects on this form. Use cut and paste to make the task easier. Value, HScroll2. Value, HScroll3. Value Label5. Value Label1. Value, - HScroll2. Value, - HScroll3. Value, 0, 0 Label3. Value, 0 Label4. Value 3. Use the Project Explorer window to return to your main form and double click example 2 in your menu to add the appropriate code.
Save and backup. Naming conventions Up till now, we have often accepted default names, Text1, Label1, etc. In a big project, this is not good practice as it makes the code harder to read or maintain. Naming conventions use a prefix of three lowerCase letters to identify the type of control, followed by a meaningful name. A variable can only hold one datatype.
A program can have as many variables as you need but before you can use a variable it must be declared. True or False e. Often called double-precision. Often called single-precision.
Visual Basic includes many built-in functions intrinsic functions. Some perform basic mathematical tasks.
Others manipulate string data such as converting text to upperCase or lowerCase letters. An argument is a value you pass to a function so the function has data to work with. Function names have parentheses at the end to hold the function arguments. Even if a function has no arguments, the parenthesis are required. Two intrinsic functions include message boxes and input boxes.
Activity 3: Message and input boxes Message and input boxes are intrinsic functions in Visual Basic 6. Follow the instructions Add new form to menu at the end of Activity 1 to create a new form with a menu heading on the main form.
The user must acknowledge this box before doing anything else. Remarks are added in code to explain the purpose of a section of code or to add information for code maintenance. Activity 4 Create a calculator that can add, subtract, multiply and divide two numbers given by the user.
0コメント