VB IDE (integrated development environment)
o Title bar is the horizontal bar located at the top of the screen
o It gives the name of the application
o Interaction between the user and the title bar and handled by windows
o Everything below the title and menu bars in the windows application is called the “client area”
o Selecting items from the pull-down menus listed on a menu bar.
o The menu bar gives the tools needed to develop, test and save the application.
o Some menu items have short cut keys.
o A short cut key is usually a combination of keys
o The tool bars are customizable
o The four built-in tool bars are in VB. They are standard, Edit, Debug and form editor.
o The tool box is located at the left side of the screen.
o It contains the controls to build the interface for the VB application.
o We can add new components by choosing project -> components
o We can customize the form window by adding controls and changing its size
o Visual basic organizes its components into projects.
o Each project can have multiple forms; the code that activates the controls on a form is stored with the form in separated files.
o The general programming code shared by all the forms can be divided into different modules.
o The project explorer will display all the customizable forms and general code (module) that makeup the application.
o Three tools are available at the top of the project explorer window. They are
• View code
• View object
• Toggle folders
o By clicking the view code button, it will display the code associated with that form (or ) object
o Visual basic stores all the files in a project file, they have .vbp extension.
o VB allows to have multiple project at the same time. This is called project group. The extension of project group is .vbg
The properties window:
• The properties window located above the form layout window on the right hand side of the VB environment.
• By pressing F4, we can make properties window visible.
• The second column of the properties window always indicates the current setting of the property. Hence the right-hand column of the properties window is called the setting box.
• The default arrangement in the properties is alphabetical. Click the categorized tab in the properties window to list out the properties based on functionality.
COMMON FORM PROPERTIES:
• The caption property sets the title of the form.
• This property is used to identify the control in coding
• This property determines whether the form will have a three-dimensional look.
• The default value of this property is 1 for 3d look.
• If the value is 0, then the form will appear flat.
There are six values for this property.
2. Fixed size
4. Fixed double
5. Fixed tool window
6. Sizable tool window
• If the border style value is 0, then the application (form) will show no border and therefore no minimize, maximize or control buttons. Because of this, a form created without a border cannot be moved, resizes. This setting is useful for splash screen.
• If the setting is 1, the user will not be able to resize the window.
• If the value of the border style property is 2(sizable), then the user ca resize the form via the hot spot located on the boundary of the form.
• If the value is 3-fixe double, then it is used for design a dialog box.
• If the setting is 4- fixed tool window, then it will display the form with a close window, and the text on the title bar will be display in reduced size.
• If the setting is 5-sizable tool window, it works much like as fixed tool window.
• Control box are located in the far left corner of the title bar. The changes in the control box property go into effect only at runtime . we can assign the value either ‘true’ or ‘false’ to the control box.
o If the enabled property set to false, then the form cannot respond to any events.
o This property decides the initial position of the form at runtime. The default value is 0.
o Setting the value of this property to false, the form will not bew visible at runtime.
o This property determines how the form will work at runtime there are three possible settings.
0. Normal (default setting)
1. Minimized (reduce the form into icon)
PROPERTIES OF COMMAND BUTTON
This property is used to identify the control at coding time. This property determines the name visual basic uses for the event procedure. The name property for any control is more important. Microsoft suggests using a prefix to start the name of any control. For command button the prefix is “cmd”.
The limitations on assigning control name are:
• The name must begin with a letter
• After that we can use any combination of letters, digits and underscores.
• No spaces are allowed
• The name cannot be longer than 40 characters.
o The caption property determines what the user sees on the face of button.
o The caption property can use any symbols available in a single font.
o The caption on a command button is automatically centered within the button.
o This property determines whether the command button is visible or not at runtime. The command button is visible at design time even the visible property is set to false.
o This property determines whether the button can respond to any event. If this property set to false, VB will not respond to any event concerning that button.
o This property controls which font is used for the caption of the button.
o All the font characteristic – bold, italic, etc. can be set independently for each command button.
o These property define the height and width of the command button.
o We can change the setting for these properties directly from the properties window.
Disabled Pictures, Down Pictures, Picture, Style
o To display the picture in the command button, set the value of the style property to 1- graphical.
o The default value of the style property is 0-standard.
o In addition to setting a picture for a command button in tis normal state, we can set a special picture when the control is disabled (or ) when it is clicked.
o The command button allows all the standard picture type ( bitmaps, icons, jpegs, gif, metafile, etc. )
o The command button wont resize itself to fit the image.
o A user can activate an escape command button by pressing ‘esc’ key on the keyboard.
o By setting the cancel property to ‘true ‘, we can make the command button as escape command button.
o We can set the default command button by setting the value of default property of the command button to ‘true’.
o To set the access key for a command button place an ampersand (&) in front of the letter that we want to create the access key, in the caption.
o We can activate the access key by pressing key combination with ALT key.
o It is possible to have the same access key for more than one control.
TEXT BOX PROPERTIES
o The text boxes are the primary control for accept input and display output. The content of the boxes are treated as String. For numeric calculation, transforming a string into a number using built-in-function is required.
o Microsoft prefix for the name property of a text box is “txt”.
o Special properties of text boxes:
o Text property holds the information entered in the text bar.
o The default value for this property is set to text1, text2, and so on.
o This property controls how the text is displayed in a text box.
o The default value is 0 – left, which leaves the text left aligned.
o Use 1-right, 2-center are the value for other alignment.
o This property determines whether a text box can accept more than one line of text.
o The limit of the multiline text box is approximately 32000 characters.
o This property usually combined with resetting the value of the scroll bar property
o If the multiline property is set to “true”, a user can always use the standard methods in window to move through the text box.
o VB automatically word wraps when the user types more than one line of text.
o Use enter key to separate lines.
o This property determines whether a text box has horizontal (or) vertical scroll bar
o These are useful to accept long (or) multiple lines of character from a single text box box.
o The four possible setting for the scroll bar property are
0. None (this will display no scroll bar and this the default value)
1. Horizontal ( horizontal text limits inside the text box to a total of 255 characters )
2. Vertical ( text box has vertical scroll bars only)
3. Both ( text box has both vertical an d horizontal scroll bars)
o The default value of the border style property is 1-fixed single, which give the single width border to the text box.
o If the value of the border style property 0 – none, the border disappears.
o This determines the maximum number of character that the textbox will accept.
o Any setting other than 0 will limit the user’s ability to enter data into that textbox to that number of characters.
o This property limits the textbox display.
o If the value of this property is set to ‘*’, all the character entered in the box will display as row asterisks.
o This property is used to prevent users from changing the contents of the textbox.
o User can scroll and highlight but won’t be able to change it.
o Its advantage over setting the enabled property to false is that textbox is not grayed.
o Labels are used to display the information but the user cannot be able to change.
o The most common use for label is to identify a textbox or other controls by describing its contents.
o Microsoft suggested prefix for the name property of the label is ‘lbl’.
o The enabled property is not often used for labels.
o The alignment property for a label has three possible setting.
o The default value is 0 – left, which leaves the text left aligned.
o Use 1-right, 2-center are the value for other alignment.
Border Style, Back Style
o The border style property has the same two possible values as textbox.
o The difference is that the default value is 0
o Set the border style property to 1, the label resembles a textbox.
o This property is used for displaying outputs avoids the problem of textboxes being changed by the user.
o The back style property determines whether the label is transparent or opaque.
o By setting auto size property value to true, labels can b made to grow automatically in a horizontal direction.
o The default value of this property is set to false
o By setting word-wrap property to true, the label will grow in the vertical direction.
LIST AND COMBO BOX
o This property is available at design time.
o This gives another way to initiates the items in the List/Combo box instead of doing it at run time.
o To place each item on a separate line, use ctrl+enter between items.
o This property gives the numbers of items on the list.
o The value of the list index property gives the index number of the highlighted item.
o If no item was selected, the value of this property is 1.
o This is a property of both list and combo box and it gives the currently selected item stored as a string.
o To comment numerical equivalent of this string, apply the correct conversion function ( cInt, cDbl, … ) .
o For example, if the name of the list box is lstrollno then, the value of the lstrollno.text is the same as that of lstrollno.list(listindex) .
Columns And Multiselect
o The columns property controls the number of columns in a list box.
o The default value is 0, which has single columns in a list box with vertical scrolling.
o If the value is 1, the get single columns in a list box with vertical scrolling.
o Set the value is greater than 1 for multiple columns
o The multi-select property controls whether the user can select more than one item from the list.
o There are three possible values for this property.
VALUE TYPE OF SELECTION DESCRIPTION
0 No multi-selection allowed ---
multi-selection Use ordinary windows techniques and mouse dragging
( shift + arrow key, ctrl + right arrow, and so on)
multi-selection Shift + mouse click extends the selection to include all list item between the current selection and the location of the click.
CHANGE EVENT OF A COMBO BOX:
o The change event occurs only for pull down combo and simple combo (style 0 or 1).
o VB does not generate this event if you are using pull down list box (style 2)
o This event occurs whenever the user enters the text in the text area of the combo box. (or)
o Change the text property value of the combo box from code.
o Frames are usually used to group images or controls
o There are 31 properties for frames and all of them are common to the other controls.
o The most important thing in placing frames is, draw the frame before place the control.
o Option button always work together
o When the users choose one button, all the other buttons in the group are turned off.
o For using more than one group of option button, use the frame control to group the option button.
o The important property of option button is “value” property
o If the user selected the button, the value property is true; otherwise the value property is false,
o Microsoft suggested prefix for the name property of the option button id “opt”
o VB generates the click event when the user select the button
o By clicking with the mouse (or)
o Moving via the TAB key and pressing SPACEBAR
o We can temporarily disable the button by setting enabled property to false at design (or) runtime.
o Check boxes differ from option button.
o The used can be turned on (or) off independently.
o Whether a checkbox is on (or) off is determined by its value property.
o There are three values for the value property
o The scroll bars span a range of values
o Vertical scroll bar and horizontal scroll bars is works in the same way.
o The important event in the scroll bars is ‘change event’
o This event occurs when the user manipulates the scroll bar.
o An integer value that defines the smallest value for a scroll bar.
o The possible setting for a scroll bar is -32768 to 32767.
o An integer value that defines the largest value for a scroll bar.
o The possible setting for a scroll bar is -32768 to 32767.
o User can set max values to be less than the min value.
o Both max and min are usually set at design time but the user can change them with code at run time.
o This property tells where the scroll bar is.
o The range is determined by min and max property
o The value property can be as small as the min value (or) as large as the max value.
o The setting for small change determines how VB changes the value property of the scroll bar when the click on the scroll bar arrows.
o The value of the scroll bar increases by the amount of small change until the value property reaches the value of max property.
o Default value of small change is 1.
o It can be set to any integer between 1 and 32767.
o The setting for large change determines how VB changes the value property of the scroll bar in response be a users clicking between the scroll box and scroll arrow.
o We can set the integer value between 1 and 32767.
o As with min, max and small change, this property is usually set at design time but can changed at run time.
o Used to do something periodically
o There are two important properties for timer control is
o A Boolean property that determines whether the timer should start ticking or not.
o Timer control starts working only when this property is set to true.
o The user can disable the timer in code by setting its enabled property to false.
o Determines how much time VB waits before calling the timer event procedure.
o The interval is measured in millisecond
o The range is between 1 and 65535
COMMON DIALOG BOX
o This control is used to place the common dialog boxes, like open, save, print, font and colors, in project.
o To add common dialog in the tool box, Microsoft common dialog control be in project--> component menu.
o The following methods are available to view the corresponding dialog boxes.
Methods Dialog box
Show save Shows a file save dialog box
Show open Shows a file open dialog box
Show color Shows the color choice dialog box
Show print Shows the print dialog box
Show font Brings up the font choice dialog box
• The picture boxes are used to display icons, gif, jpeg, bitmap and windows metafiles.
• We can use the pictures box as control container like frame control.
• Picture boxes have currentX, currentY properties same like the scale properties in the form.
• The user can mix fonts and font size when the user prints to a picture to a picture box.
• The picture boxes are occupy less memory
• We can have more than one picture box on a single form
• If the Autosize property of a picture box is set to true, the picture will automatically resize itself to fit the image.
• The Textheight and Textwidth methods are used to accurately size text.
• The Autoredraw methods is used to refresh the picture box at the time of displaying graphics (circle, line, etc) on the picture box
• We can assign picture to the picture box using picture property at design time and by using loadpicture function at run time
• In loadpicture function the file name should include full path
• The loadpicture statement without a filename will clear the picture box
• Imagecontrol hold pictures
• Imagecontrol are user to display icons (or) picture
• The Loadpicture function will reset the value of the picture property
• The most important property of an image control is the stretch property
• This property determines whether the image control adjusts to fit the picture (or) the picture adjust to fit the control
• The message boxes are used to displays information in a dialog box super imposed on the form.
• The message box will for the user to choose a button before returning to application.
• Without responding to the message, the user cannot switch to any other forms.
• The simplest form of the message box is
• The complete syntax for the msgbox command is,
Msgbox message_dispolayed_in_msbox, type_of_box, title_of_box
• The user can combine three different groups of built-in integer contents to specify the kind of the message box.
• The three groups are,
o Type of button
o Type of icon
o Default button selected
• The first group of numbers controls what type of button will be displayed in the message box.
VALUE SYMBOLIC CONSTANT DESCRIPTION
0 VbOkOnly Display only the ok button
1 VbOkCancel Display ok and cancel button
2 VbAbortRetryTgnore Display abort, retry and ignore buttons
3 VbYesNoCancel Display yes, no and cancel buttons
4 VbYesNo Display yes, no buttons
5 VbRetryCancel Display retry and cancel buttons
• The second group of numbers control what type of icon will be displayed in the message box
VALUE SYMBOLIC CONSTANTS DESCRIPTION
16 VbCritical Display critical message icon
32 VbQuestion Display warning query icon
48 VbExclamation Display warning message icon
64 VbInformation Display information message icon
• The next group of numbers controls which button is the default button for the box.
VALUE SYMBOLIC CONSTANTS DESCRIPTION
0 VbDefaultButton1 First button is default
256 VbDefaultButton2 second button is default
512 VbDefaultButton3 third button is default
Op = Msgbox(“Do you want to delete?”,VbYesNo+VbCritical+VbDefaultButton2,”Delete?”)
If Op= VbYes Then
‘Write the code for Delete
• The input box function displays a model dialog box on the screen
• The dimensions of the input box are fixed
• There are two command buttons labelle ok and cancel
• There is a text area at the bottom
• The simplest sntax of inout box function is,
String_variable = inputbox(prompt string)
• The complete syntax for the inpoutbox function is,
Variable = InputBox(Prompt [,Title] [,Default][,XPos][,YPos][,HelpFile,Context])
The short descriptions of these parameters are,
• The prompt parameter is a string or string variable
• It ios a limited to 1024 character
• The prompt doesn’t wrap
• For multiline prompt, use VbcrLf characters line separator
• The parameter is optional
• There is no default value
• If this option is omitted, the application name is displayed in the title bar
• The default parameter is also optional
• This is a used to display default text in the edit box(text box)
• Both xpos and ypos arte integral numeric expression
• The xpos is the distance in twips between the left edge of the input box and the left edge of the screen
• If the user omits xpos, the box is horizontally centered.
Help File / Context
• The two parameter helpfile and context are used together when the user have a help message attached to the box
Op = InputBox (“Enter Roll No”, “Student Details”,”07UCP2651”,100,200)
• The grid is important foir accurately positioning controls
• To control the grid, choose
Toolsoption and then go to the general page
• The four properties that the user should control the grid are described below
• The user can turn the grid on or off by changing the show grid setting
• The default setting is on
Grid Width, Grid Height
• The height and width setting is used to set the distance ( in twips ) between grid marks
• The default is 120 twips
Align Controls To Grid
• This check box determines whether controls automatically move to the next grid mark (or) whether they can be placed etween grid marks.
• The alternate way for aligning controls to grid is, choose
VB EDITING TOOLS
THE EDITOR FORMAT PAGE
• Choose tools option and click on the editor format tab
• The code colors frame contains list of possible objects that the user can change
(ex: normal text, comment text, keyboard text and so on)
Font List Box
• This will display the complete list of fonts that is already installed in the system.
Size List Box
• The user can type a point size for the font directly in the size list box
• This option is used to change the font size of the VB environment
Foreground, Background And Indicator List Box
• The three code colors boxes determines the foreground and back ground colors used for each type of code
• The third list box used for indicators in the margin such as book marks.
• This box is used to see a sample text in the font, size and color setting that are currently set.
THE EDITOR PAGE:
Auto Syntax Check
• Visual basic automatically check the code when the programmer press ENTER and there by detect certain kinds of mistakes immediately
Require Variable Declaration
• Keep this option checked always
Tab Width Box
• Use the tab width box to set the number of spaces the user gets when the user press TAB key
• This can be anything from 1 to 32.
• The default is 4 spaces
• Tf the user have selected text,
o Pressing TAB shift all the text forward one tab stop
o Pressing SHIFT+ TAB all the text back one tab stop
Auto Indent Check Box
• If the auto indent box is checked, pressing ENTER after you use the TAB key to indent a line makes the subsequent line start at the same place as the line above it.
• It is useful to make programming structure cleaner
Default To Full Module View
• When this option is checked, the user will see all the code as one unit the code window
• The user will scroll through the code with arrow keys
• If this option is unchecked, each procedure of code pops up in a separate window
• Use CTRL+↑ and CTRL+↓ to cycle through the different pieces of code.
• Use this check box in conjunction with full module view
THE EDIT TOOL BAR
• Many useful editing features have button equivalent on the edit tool bar
• The user can add the eedit tool bar, in the VB environment bu selecting
VIEW tool bars
• The tools available in tool bar are discussed below
FUNCTION SHORT CUT DESCRIPTION
List properties methods [ CTRL + J ] Displays a pop-up list box with the properties and methods for the object preceding the period
[CTRL + SHIFT + J] Display a pop-up list box with the valid constants
Quick info [CTRL + I] Gives the syntax for the procedure (or) method
Parameter Info [CTRL + SHIFT + I] Provides the parameter list for the current function call
Complete word [CTRL+SPACEBAR] Complete the keyword or object when enough information is there
Intend [TAB] Indents the selected text one tab stop.
Use editor page to change the no. of spaces for the tab.
Out end [SHIFT+TAB] Moves the selected text back one tab stop
Toggle break point [F9] Used for debugging
Comment block Used to comment the block of statement
Uncomment block Used to uncomment the block of statement
Toggle bookmark The editor allows the user to put book mark at specific places in the code. The user can jump from one bookmark to another easily
Next bookmark Move to next bookmark
Previous bookmark Move to previous bookmark
Clear all book marks Used to clear all the bookmarks in the code
• Variables are used to store information(values)
• When the user use a variable , VB set up an area in the computer’s memory to store the information
• Variable name can be up to 255 characters
• The first letter of the variable should be an alphabet
• Any combination of letter, numbers and underscore can be given for a variable name
• The user can not use names reserved by VB
• Choose the meaning variable name
• The naming convention for styling variables name is, use capitals only at the beginning of the word.
• This convention is called mixed case variable name.
The data types available in VB are
4. Long integer
5. Single precision
6. Double precision
• Use the Boolean data type when you need to store either TRUE or FALSE
• This data type was added to VB 5
• It will hold integer values between 0 to 255
• Integer data type are used to store integer values between -32768 and 32767
• Integer arithmetic is very fast
• The integer variable are capable of holding integer within the range
• Use % sign at the end of integer variable name
• The long integer variable hold integer value between -2147483648 and 2147483647
• The identifier that the user can use for the variable is the ampersand(&)
• Long integer arithmetic is also fast
SINGLE PRECISION (!):
• This data type is used to store numbers with decimal points
• The range of the number is up to 38 digits
• The calculation will always be approximate for these types of variables
• This is used for numbers with only seven digit accuracy
• The double precision data type is used when the user need up to 16 places of accuracy
• The range is more than 300 digits
• The calculation are also approximately for these variables
• Calculation are relatively slow with double precision numbers
• The identifier used for double for double precision variable is a pound sign.
• The currency data type is designed to award certain problems in switching from binary fractions to decimal fraction.
• The currency data type can have 4 digits to the right of the decimal place and up to 15 to the left of the decimal point
• Arithmetic calculation will be exact with in this range
• This is the preferred data type to use for financial calculation
• The string data type holds characters
• A variable holding a string is called a string variable
• A string variable can hold about 2 billion character
• Due to memory constraint, the no. of characters may vary.
• The most common use of string variables is to store the information contained in a text box.
• This is a data type used to store both date and time
• We can store the data value between midnight on Jan 1, 100 and midnight on Dec 31, 9999.
• Use # symbol at the beginning and ending of the data values assignment
Ex: dob= #31-05-1980#
• If the time is not include in the date, VB assumes it is midnight
• We can use AM/PM for assigning time
Ex: dob= #31-05-1980 10:50AM#
CHAPTER – II
DISPLAYING INFORMATION ON A FORM
• VB displays text on a form using ‘print’ function
• The general syntax of print method is
o Where expression is any VB expression that VB can convert to a string
o Use Autodraw property of the form to refresh printed text on the form
o Cls is a command used to clear the form
CURRENTX AND CURRENTY
• Currentx refers to the horizontal position where VB will display the information
• Currenty refers to the vertical position
• The units used for these properties are determined by scale set via the various scale method
Where value may any numeric expression which can be converted in to single precision
FONT PROPERTIES IN CODE:
o The font and font size are depend on the h/w and s/w which is available in the system
o to assign a font name in code, place the name in quotation mark on the RHS of the assignment statement
o the user can change all the properties of the font object via code
o The propertied bold, italic, strikethrue, and underline are Boolean properties
o The user can change forms only in forms, richTextBox and picture box and also to mix these font properties
o Form and picture boxes have other font property is fonttransparent
o The value of FontTransparent property is Boolean.
THE TAB AND SPC COMMANDS
• The tab function is used to move to the specific location and start print and there
• The syntax is
• If the columnnumber is greater than the current column position , tab skips to the column on the next line
• If the value is less than 1, VB moves to the first column
• The maximum is 32767.
• The spc function hac the syntax similar to the tab function
• The syntax is
• This function insert the specific number of spaces into a line, starting at the current print position
This function works with a number and a template (format string)
The syntax is,
Format (numerical expression, format string)
FORMAT FUNCTION OUTPUT
• To display a symbol such as -,+,$,(,) (or) space use the symbol in the format string exactly in the place where it to occur
The output is, $123.45
PREDEFINED FORMAT STRING
• This is used to deal with the most common formatting situation by adding named formats to the format function
• The user can use the format function like
Me.print format(amount, “$###,###.##”)
• The advantage of using named format is that VB automatically adjust the thousand separator and current symbols
• The following table summarizes the predefined numeric formats
NAME OF FORMAT DESCRIPTION
General numbers Gives a string of digits with no thousand separator
Currency Use the appropriate thousand separator and display two digit to the right of the decimal point
Fixed Displays at least one digits to the least and two digits to the right of the decimal point
Standard Use the appropriate thousand separator; And Displays at least one digits to the least and two digits to the right of the decimal point
Percent Gives the numbers in percentage form. Always display two digit to the right of the decimal point
Scientific Use VB’s version of scientific notation
Yes/ no Display NO if the number is 0, otherwise displays YES
True/ false Display FALSE if the number is TRUE
On/ off Display OFF if the number is ON
3. The following table gives the various formats for date and time
NAME OF FORMAT DESCRIPTION
General date Displays a date and/ or time.
If there is no fractional part, the user will get a date
If there is integer fractional part, the user will get a time
If there are both, the user will get both date and time
Long date Display a date using the format that windows user for full dates
Medium date Display a date using the middle date format
Short date Display a date using the short date format
Long time Display a time with the hours, minutes and seconds
Medium time Display time 12-hour format using only hour and minutes and AM/pm
Short time Display time using 24-hour format
Me.print format(now, “general date”)
o/p: 26/9/07 10:15:45AM
Me.print format(now, “long date”)
o/p: Wednesday, September 26,2007
Me.print format(now, “medium date”)
Me.print format(now, “short date”)
Me.print format(now, “long time”)
RICH TEXT BOX
This control is used to display text with multiple fonts and sizes
The RichTextBox is not limited to 32000 character like and An ordinary text box
IMPORTANT PROPERTIES FOR RICH TEXT BOX - > Refer book
PROJECTS WITH MULTIPLE FORMS
o A project with multiple forms will add flexibility and power to the application program
o To add more forms to an application
1. Open projct menu and choose add form
HANDLING MULTIPLE FORMS AT RUN TIME:
o VB displays at most one form, which is called the startup form
o All other forms must be explicitly loaded and display via code
o To change the start up form, select project menu and choose project properties
METHODS FOR FORMS:
o There are four methods for working with forms they are
o The show method displays the form on the screen and moves the current form to the top of the desktop.
o When the user use show method, VB first checks that the form is loaded into memory
o If it is not loaded , then it loads the form first
3. The hide keyword removes the form from the screen. But it does not unload it from the memory
4. The control are not available to the user , but the user refer to them in code
5. The value of the form-level variables do not disappear
6. The syntax of hide method is,
o The load keyword places the form into memory but it does not display the form in the screen
o The main reason to load a form is to speed up the response time
o The syntax is
1. load formname
o The unload keyword removes the form from memory
o All information contained in its level variable is lost
o The syntax for this command is,
o unload formname
ACTIVATE/ DEACTIVATE EVENTS OF A FORM
o VB invokes the activate event for a form whenever a form becomes the active window within the current VB project
o In general, VB will call the activate event when
1. A for becomes actives with the current VB application
2. The user clicks on the form
3. The user use the show (or) setfocus methods in code
o The active event occurs before the gotfocus event
o The VB will execute the activate events only when a form is visible
o VB invokes the deactivate event when the form steps being the active window
o VB does not execute the deactivate events when the user unload the form
o VB calls the lostFocus event before the deactivate events
GLOBAL PROCEDURE AND GLOBAL VARIABLES
o A standard code include IO where the user put code that may be accessible to all code ina project
o Standard modules have no visual components
o Add new standard module by selecting project menu and choose add module option
o The standard module have .bar extension
o The sub and function procedure in code module are available to the whole project
o To make a variable attached to a form into a global variable, use the statement of the form
Public variablename as variabletype
o Code modules can also have module level variable that are visible only to the code attached to that module
o To make a variable global, a variable requires the public / global keywords
o These keywords are called access modifier
o If the user use private (dim) declaration syntax that have using for code attached to a form in the declaration section of a code module, then the variable is visible only to the procedure attached to that code module
o If the user use the private (dim) statement inside a procedure attached to a code module that variable is local to the procedure
o When the user use a sub or function procedure inside another procedure, VB follows these steps to determines where to look for it
• VB looks at procedure attached to the current form or modules
• If the procedure is not found in the current form (or) module s attached to the project
DO EVENTS FUNCTION AND SUBMAIN
7. Usually window monitor the environment constantly for events responds to
8. This will automatically done by the window’s operating system by giving each program a ‘slice’ of time to work before giving a chance to the next program
9. On the other hand, the user can foul up his own program by preventing windows from sending information about events that happened to the running program
Private sub form_load()
Do infinite loop
Private sub form_load()
o Do events is a command that tells VB to listen to any events
o Windows maintains a list of pending events is called an eventqueue
o The DoEvents statement passes control to windows and VB gets control back only after the operating system has finished process the events in its queues
o If the is not start up form, the user have to manage the code for loading all the form
o This is done inside a special sub procedure called main that be attached to any code module
o The user can have only one sub main procedure in any project
o To use a sub main, the user have to make the code module containing the sub main procedure be the startup module
o To do this, select project menu and choose project properties and then select general page
o On this page drop down the startup object list box and choose sub main instead of form
FUNCTION AND PROCEDURE
o To attach the function with the current form, open the code window, and then choose tools menu and select add procedure
o The first line of the function is called the header of the function
Public function random1to(x) as integr
Random1to – int (x * rnd)+1
Public function add2no (x as integer, y as integer ) as single
o The keyword public is called as access specifier
o Where x is a parameter in random to function and x, y are the parameter in add2no function
o In the body of the function, assign a value to the function using its name
o The value the function gets is depends on the parameter
USER DEFINED FUNCTION
The simplest form of a function definition is,
Public function functionName (para1, para2,…)
Function name= expression
Function name= expresio0n
Where parameter1, parameter2 ,… are variables
o These variables are referred to as the parameter (or) arguments of the function
o The types of the parameters can specified by type-declaration
o After process the statements, VB sends the information to the function definition
o The last value assigned to the functionname inside the body of the function is the result of the function
o Each variable to send to a parameter must be of the same type
SCOPE OF VARIABLES USED IN FUNCTION PROCEDURE
o As with events procedure, the user can setup own local variable inside function procedure
o Any variable declared within the body of the function using ‘dim’ keyword will be local to the procedure regardless of whether there is a form level variable with the same name
o The parameter of the function are automatically local to the procedure and no need to declare the parameter inside the procedure
o To add new sub procedure, select tools menu and choose add procedure
o The structure of the simplest sub procedure is,
Public sub procedurename()
o The first line of the sub procedure is called as header
o Public is the access identifier
o The next in the header is the keyword ‘sub’ followed by the procedure name
o The parameters list should be enclosed within the parenthesis
o The ‘end sub’ keyword are used to indicate the end of a general procedure
o The procedure list will be used to communicate between the program and the procedure
o To use the procedure in the main program, the ‘call’ keyword is used
o To use the call keyword, the user must give parenthesis around the argument list
USES OF PROCEDURE AND FUNCTION
PASSING BY REFERENCE, PASSING BY VALUE
o When the user call a function (or) procedure, there are two ways to pass in a variable as an argument
o They are
o Passing by reference
o Passing by value
o When the user pass an arguments variable by reference, any changes to the corresponding parameters inside the procedure will change the value of the original argument
o When the user pass an argument by value, then the original variable retains its original value.
Sub triple( num as integer)
Me.print ”inside the procedure the parameter value is ” & num
Dim amt as integer /* this is local variable to this procedure */
Me.print ”from form load procedure the parameter value is ” & Amt
Me.print ”After procedure call the parameter value is ” & Amt
From parameter pass by value
Change the statement
o Here the variable is passed by reference because it is surrounded by parenthesis
Call by reference Call by value
Form load 2 2
Inside procedure 6 6
After procedure call 6 2
VISUAL BASIC IMPORTANT QUESTIONS
1. Define GUI.
2. Define properties, events, methods
3. Integrated development environment ( IDE ) - explain
4. Data types in VB
6. Scope of the variables
7. Tool box
8. Text box, labels, command buttons, image control, picture control
9. Message box and input box
10. Control structure
i. Conditional statements (or) branching statements
ii. Looping statements
11. Conditional statements
i. All types of ‘if’ statements
ii. Select case statement
12. Looping statements
iii. Do until
iv. Do loop
1) String functions
2) Date and time functions
3) Data testing functions
4) Data conversion functions
14. Format functions
15. Sub routines and sub procedures
17. Control arrays
18. List box control
19. Combo box control
20. Do events and sub mains
21. Error trapping
22. Event handling
• Got focus
• Lost focus
• Query unload
23. Common dialog box
24. Common controls(pg: 512-541)
25. Menu editors
27. MDI form
28. Sorting and searching
• Ripple sort
• Insertion sort
• Shell sort
• Bubble sort
29. Records(pg: 374)
30. Grid control(pg: 410)
31. Manipulating objects(pg: 461)
32. Object variable
Ex: dim a as control
33. Testing(pg: 564)
34. Debugging(pg: 571)
35. Debugging tools
36. Working with graphics
37. File system controls(pg: 726)
38. Com / OLE(pg: 757)
39. OLE drag and drop(pg: 770)
40. DLL server(pg: 766)
41. Mouse Activity (pg: 648)
42. Mouse events
43. Keyboard events
44. Creating pop-up menu in VB
45. Basic file handling (pg: 675-700)
-Chief Administrative Officer.