Vous êtes sur la page 1sur 11

Visual Basic 6.

0 Short Notes
Customizing a Form
Starting Visual Basic

Unit 1

The first step in using Visual Basic is launching it and opening existing files or creating new ones. To start Visual Basic 6.0 1. In Windows, click Start, point to Programs, and point to the Microsoft Visual Basic 6.0 folder. The icons in the folder appear in a list. 2. Click the Microsoft Visual Basic 6.0 program icon. The New Project dialog box appears. This dialog box prompts you for the type of programming project you want to create. See the p icture of window below.

3. To accept the default new project, click OK. In the Visual Basic development environment, a new project (a standard, 32-bit Visual Basic application) and the related windows and tools open. See the picture below.

For more notes and information, kindly visit: http://sunnmoonsolution.blogspot.com

Visual Basic 6.0 Short Notes

Unit 1

The Visual Basic development environment contains these programming tools and windows, with which you construct your Visual Basic programs: Menu bar Toolbars Form window Properties window Project Explorer Immediate window Form Layout window

Loading and Running a Program: Before you can work with a Visual Basic program, you need to load the program into memory, just as you would load a word processing document in a word processor for editing. To load a Visual Basic program into memory and run it. 1. On the File menu, click Open Project. The Open Project dialog box appears. With this dialog box, you can open any existing Visual Basic program on your hard disk, attached network drive, CD-ROM, or floppy disk. 2. On the Visual Basic Standard toolbar, click Start to run the program. The toolbox and several of the other windows disappear, and the Visual Basic program starts to run. 3. On the toolbar, click End when you want to exit the program.

Visual Basic Resources


Programming Tools: The location and purpose of the Visual Basic 6.0 programming tools are described in the following. Menu bar: Located at the top of the screen, the menu bar provides access to the commands that control the Visual Basic programming environment. Menus and commands work according to standard conventions used in all Windows-based programs. You can use these menus and commands by using keyboard commands or the mouse.

Toolbars: Located below the menu bar, toolbars are collections of buttons that serve as s hortcuts for executing commands and controlling the Visual Basic development environment. You can open specialpurpose toolbars by using the View menu Toolbars command.

For more notes and information, kindly visit: http://sunnmoonsolution.blogspot.com

Visual Basic 6.0 Short Notes

Unit 1

Windows taskbar: This taskbar is located along the bottom of the screen. You can use the taskbar to switch between Visual Basic forms as your program runs and to activate other Windows -based programs. Toolbox Controls: You use special tools, called controls, to add elements of a program user interface to a form. You can find these re sources in the toolbox, which is typically located along the left side of the screen. (If the toolbox is not open, display it by using the Toolbox command on the View menu.) By using toolbox controls, you can add these elements to the user interface: Artwork Labels and text boxes Buttons List boxes Scroll bars File system controls Timers Geometric shapes Data and OLE controls.

For more notes and information, kindly visit: http://sunnmoonsolution.blogspot.com

Visual Basic 6.0 Short Notes

Unit 1

For more notes and information, kindly visit: http://sunnmoonsolution.blogspot.com

Visual Basic 6.0 Short Notes


Form Window

Unit 1

When you start Visual Basic, a default form (Form1) with a standard grid (a window consisting of regularly spaced dots) appears in a pane called the Form window. You can use the Form window grid to create the user interface and to line up interface elements. Adjusting Form Size: You can adjust the size of the form by using the mouse the form can take up part or the entire screen. Controlling Form Placement: To control the placement of the form when you run the program, adjust the placement of the form in the Form Layout window.

Properties Window
With the Properties window, you change the characteristics (property settings) of the user interface elements on a form. A property setting is a characteristic of a user interface object. For example, you can change the text displayed by a text box control to a different font, point size, or alignment. (With Visual Basic, you can display text in any font installed on your system, just as you can in Microsoft Excel or Microsoft Word.) Displaying the Properties Window: To display the Properties window, click the Properties Window button on the toolbar. Changing Property Settings: You can change property settings by using the Properties window while you design the user interface or by using program code to make changes while the program runs.

Project Explorer
A Visual Basic program consists of several files that are linked together to make the program run. The Visual Basic 6.0 includes a Project window to help you switch back and forth between these components as you work on a project. Project Window Components: The Project window lists all the files used in the programming process and provides access to them with two special buttons: View Code and View Object. Displaying the Project Window: To display the Project window, click the Project Explorer button on the Visual Basic toolbar.

For more notes and information, kindly visit: http://sunnmoonsolution.blogspot.com

Visual Basic 6.0 Short Notes


Form Layout Window The Form Layout window is a visual design tool. With it, you can control the placement of the forms in the Windows environment when they are executed. When you have more than one form in your program, the Form Layout window is especially useful you can arrange the forms onscreen exactly the way you want. To position a form in the Form Layout window, simply drag the miniature form to the desired location in the window.

Unit 1

Writing a Simple Program


A Visual Basic program is a Windows-based application that you create in the Visual Basic. Planning the Program : The first step in programming is determining exactly what you want your program to accomplish. One part of the planning process might be creating an ordered list o f programming steps, called an algorithm. Building the Program Building a Windows-based application with Visual Basic involves three programming steps: creating the user interface, setting the properties, and writing the code. And, of course, your proje ct must be saved. Testing, Compiling and Distributing the Program After you create a working version of your program, you need to test it carefully to verify that it works correctly. If you wish to distribute your program, you also need to compile it into an executable program (a stand-alone Windows-based program) and give it to your users. To draw a control using the Toolbox 1. 2. 3. 4. 5. 3. 2. 1.

Creating Controls

Click the tool for the control you choose to draw in this case, the text box. Move the pointer onto your form. The pointer becomes a cross hair. Place the cross hair where you want the upper-left corner of the control. Drag the cross hair until the control is the size you want. Release the mouse button. The control appears on the fo rm.

For more notes and information, kindly visit: http://sunnmoonsolution.blogspot.com

Visual Basic 6.0 Short Notes

Unit 1

Another simple way to add a control to a form is to double -click the button for that control in the Toolbox. This creates a default-size control located in the center of the form; then you can move the control to another location on the form.

Resizing, Moving, and Locking Controls:


Notice that small rectangular boxes called sizing handles appear at the corners of the control; you'll use these sizing handles in the next step as you resize the control. You can also use the mouse, keyboard, and menu commands to move controls, lock and unlock control positions, and adjust their positions. To resize a control: 1. Select the control you intend to resize by clicking it with the mouse. Sizing handles appear on the control. 2. Position the mouse pointer on a sizing handle, and drag it until the control is the size you choose. The corner handles resize controls horizontally and vertically, while the side handles resize in only one direction. 3. Release the mouse button or Use SHIFT with the arrow keys to resize the selected control. To move a control: Use the mouse to drag the control to a new location on the form or use the Properties window to change the Top and Left properties. When a control is selected, you can use the CTRL key with t he arrow keys to move the control one grid unit at a time. If the grid is turned off, the control moves one pixel at a time.
,,

To lock all control positions: From the Format menu, choose Lock Controls or click the Lock Controls Toggle button on the Form Editor Toolbar. This will lock all controls on the form in their current positions so that you don't inadvertently move them once you have them in the desired location. This will lock controls only on the selected form; controls on other forms are untouched. This is a toggle command, so you can also use it to unlock control positions.

The Name Property


The Name property determines the name Visual Basic uses for the event procedures you write to make the control respond to the user. Picking meaningful names for the controls makes easier to debug the program. If we have five command buttons in our program, it is hard to find the exact command button while debugging. It would be easier to write like this, Private Sub cmdLeft_Click() ********* End Sub Instead of, Private Sub Command3_Click() ********** End Sub Naming Rules: The name must begin with a letter. After that, we can use any combination of letters, digits and underscores. No spaces are allowed in a controls name. The name cannot be longer than 40 characters.

For more notes and information, kindly visit: http://sunnmoonsolution.blogspot.com

Visual Basic 6.0 Short Notes


Command Button: The

Unit 1

Command Button control to create buttons with a variety of uses on a form. A command button is the most basic way to get user input while a program is running. By clicking a command button, the user requests that a specific action be taken in the program. Here are some command buttons that youd typically find in a program: OK:- Accepts a list of options and indicates that the user is ready to proceed. Cancel:- Discards a list of options. Quit:- Exits an open dialog box or program. Command Button Properties: Appearance:- Selects 3-D or flat appearance. Caption:- String to be displayed on button. Font: Sets font type, style, size. Changing Command Button Properties: You can change command button properties (like those of all objects) in two ways: By adjusting property settings in the Properties window. By changing properties with program code.

Access key
In addition to clicking on a button to invoke its event, you can also press its access key (no need for a mouse). The access key is pressed in conjunction with the Alt key. The ampersand (&) precedes a button's access key. event. Example: Caption: E&xit In this example, x is the access key. By pressing ALT + x, we invoke the

The Image Control:

An image box is very similar to a picture box in that it allows you to place graphics information on a form. Image boxes are more suited for static situations - that is, cases where no modifications will be done to the displayed graphics. Image box graphics can be resized by using the Stretch property. Image Box Properties: Picture:- Establishes the graphics file to display in the image box. Stretch:- If False, the image box resizes itself to fit the graphic. If True, the graphic resizes to fit the control area. The image box does not support any methods, however it does use the LoadPicture function. It is used in exactly the same manner as the picture box uses it. And image boxes can load the same file types: bitmap (.bmp), icon (.ico), metafiles (.wmf), GIF files (.gif), and JPEG files (.jpg). With Stretch = True, all three graphic types will expand to fit the image box area.

Textbox :

A Textbox is used to display information entered at design time, by a user at run-time, or assigned within code. The displayed text may be edited. This control performs two functions: Displaying output (such as operating instructions or the contents of a file) on a form. Receiving text (such as names and phone numbers) as user input.

For more notes and information, kindly visit: http://sunnmoonsolution.blogspot.com

Visual Basic 6.0 Short Notes

Unit 1

Text Box Properties: Appearance:- Selects 3-D or flat appearance. BorderStyle:- Determines type of border. Font:- Sets font type, style, size. MaxLength:- Limits the length of displayed text (0 value indicates unlimited length). MultiLine:- Specifies whether text box displays single line or multiple lines. PasswordChar:- Hides text with a single character. ScrollBars:- Specifies type of displayed scroll bar(s). SelLength:- Length of selected text (run-time only). SelStart:- Starting position of selected text (run-time only). SelText:- Selected text (run-time only). Tag:- Stores a string expression. Text:- Displayed text. Setting properties to a TextBox: 1. Text can be entered into the text box by assigning the necessary string to the text property of the control. 2. If the user needs to display multiple lines of text in a TextBox, set the MultiLine property to True 3. To customize the scroll bar combination on a TextBox, set the ScrollBars property. 4. Scroll bars will always appear on the TextBox when it's MultiLine property is set to True and its ScrollBars property is set to anything except None(0) If you set the MultilIne property to True, you can set the alignment using the Alignment property. The test is left-justified by default. If the MultiLine property is set to False, then setting the Alignment property has no effect.

Label Button:

Label, the simplest control in the Visual Basic toolbox, displays formatted text on a user interaction. Typical uses for the Label control include:

Help text Formatted output, such as names, times, and dates Descriptive labels for other objects, including text boxes and list boxes. Label Properties: Alignment:- Aligns caption within border. Appearance:- Selects 3-D or flat appearance. AutoSize:- If True, the label is resized to fit the text specifed by the caption property. If False, the label will remain the size defined at design time and the text may be clipped. BorderStyle:- Determines type of border. Caption:- String to be displayed in box. Font:- Sets font type, style, size. WordWrap:- Works in conjunction with AutoSize property. If AutoSize = True, WordWrap = True, then the text will wrap and label will expand vertically to fit the Caption. If AutoSize = True, WordWrap = False, then the text will not wrap and the label expands horizontally to fit the Caption. If AutoSize = False, the text will not wrap regardless of WordWrap value. Creating Labels in Program: The program codes below, when command1 button is clicked, will set the caption of label1 as Welcome and label2 as Please enter your name below: Private Sub Command1_Click () Label1.Caption = "Welcome" Label2.Caption = "Please enter your name below:" End Sub

For more notes and information, kindly visit: http://sunnmoonsolution.blogspot.com

Visual Basic 6.0 Short Notes


The Message Box

Unit 1

One of the best functions in Visual Basic is the message box. The message box displays a message, optional icon, and selected set of command buttons. The user responds by clicking a button. The statement form of the message box returns no value (it simply displays the box): MsgBox Message, Type, Title Message Box Example:

MsgBox This is an example of a message box,

Variables
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. It should not contain any special character like %, &, !, #, @ or $. There are many ways of declaring variables in Visual Basic. Depending on where the variables are declared and how they are declared, we can determine how they can be used by our application. Ex plicit 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

Data Types
By default Visual Basic variables are of variant data types. The variant data type ca n store numeric, date/time or string data. When a variable is declared, a data type is supplied for it that determines the kind of data they can store. The fundamental data types in Visual Basic including variant are integer, long, single, double, string, currency, byte and boolean. Visual Basic supports a vast array of data types. Each data type has limits to the kind of information and the minimum and maximum values it can hold. A list of Visual Basic's simple data types are given below.

For more notes and information, kindly visit: http://sunnmoonsolution.blogspot.com

10

Visual Basic 6.0 Short Notes


1. Numeric Byte Integer Long Single Double Currency 2. Store integer values in the range of 0 - 255 Store integer values in the range of (-32,768) - (+ 32,767)

Unit 1

Store integer values in the range of (- 2,147,483,468) - (+ 2,147,483,468) Store floating point value in the range of (-3.4x10-38) - (+ 3.4x1038) Store large floating value which exceeding the single data type value Store monetary values. It supports 4 digits to the right of decimal point and 15 digits

String Use to store alphanumeric values. A variable length string can store approximately 4 billion characters Date Use to store date and time values. A variable declared as date type can store both date and time values and it can store date values 01/01/0100 up to 12/31/9999. Boolean Boolean data types hold either a true or false value. These are not stored as numeric values and cannot be used as such. Values are internally stored as -1 (True) and 0 (False) and any non-zero value is considered as true. Variant Stores any type of data and is the default Visual Basic data type. In Visual Basic if we declare a variable without any data type by default the data type is assigned as default. 5. 4. 3.

Proverb: He who has learned how to obey will know how to command

For more notes and information, kindly visit: http://sunnmoonsolution.blogspot.com

11

Vous aimerez peut-être aussi