Q111. Describe Scroll Bar Control
Q111. Describe Scroll Bar Control
The ScrollBar is a commonly used control, which enables the user to select a value by positioning it at the desired location. It represents a set of values. The Min and Max property represents the minimum and maximum value. The value property of the ScrollBar represents its current value, that may be any integer between minimum and maximum values assigned. The HScrollBar and the VScrollBar controls are perfectly identical, apart from their different orientation. After you place an instance of such a control on a form, you have to worry about only a few properties: Min and Max represent the valid range of values, SmallChange is the variation in value you get when clicking on the scroll bar's arrows, and LargeChange is the variation you get when you click on either side of the scroll bar indicator. Move the indicator near the top (or left) arrow. VScroll1.Value = VScroll1.Min Move the indicator near the bottom (or right) arrow. VScroll1.Value = VScroll1.Max Q112. How to create an ADO Data Control that exposes a Recordset in application, 1. Add the Microsoft ADO Data Control 6.0 (OLEDB) from the Project, Components menu dialog box. The ADO Data Control icon should now appear in the VB toolbox. 2. Place an instance of the ADO Data Control on the form. 3. Change the control's Name and Caption from their default values. (The Caption is for information only, so you can set it to whatever you think will be most informative for the user.) 4. Set the ConnectionString property using steps 59. 5. Click the ellipsis next to the ConnectionString property in the ADO Data Control's Properties window to bring up the Property Page dialog box for this property. 6. As Source of Connection, choose one of the following three options: Use Data Link File. If you choose this option, you will be able to click the Browse button to specify an existing *.UDL file). Use ODBC Data Source Name. If you choose this option, you will be able to choose an existing ODBC DSN from the drop-down list, or you can create a new DSN by clicking the New button.
Use Connection String. If you choose this option, you will be able to click the Build button to bring up the Data Link Properties tabbed dialog box. The following steps assume that you have chosen this option. On the Provider tab of the Data Link Properties tabbed dialog box, choose an OLE DB data provider, such as Microsoft Jet 3.51 OLE DB. 7. The Connection tab of the Data Link Properties tabbed dialog box will vary in appearance, depending on the provider specified in the preceding step. In the case of the Microsoft Jet 3.51 OLE DB, you are prompted to choose an Access data file and set some security options. 8. Click OK to accept the ConnectionString options you have built. 9. Still in the ADO Data Control's Properties window, navigate to the RecordSource property and click the ellipsis button. 10.On the RecordSource tab of the resulting Property Page dialog box, choose the CommandType (adCmdUnknown, adCmdText, adCmdTable, adCmdStoredProc). 11.Complete the dialog box appropriately for the CommandType that you chose: If you chose adCmdText, fill in the text of a valid Select statement in the Command Text field . If you chose adCmdTable or adCmdStoredProc, fill in the appropriate table or stored procedure name in the Table or Stored Procedure Name drop-down list. 12.Click OK to end the RecordSource dialog box. Q113. Different types errors in VB code. No matter how hard we try, errors do creep into our programs. These errors can be grouped into three categories:
Syntax errors: Syntax errors occur when you mistype a command or leave out an expected phrase or argument. Visual Basic detects these errors as they occur and even provides help in correcting them. You cannot run a Visual Basic program until all syntax errors have been corrected. Run-time errors: Run-time errors are usually beyond your program's control. Examples include: when a variable takes on an unexpected value (divide by zero), when a drive door is left open, or when a file is not found. Visual Basic allows you to trap such errors and make attempts to correct them.
Logic errors: Logic errors are the most difficult to find. With logic errors, the program will usually run, but will produce incorrect or unexpected results. The Visual Basic debugger is an aid in detecting logic errors.
Q114. Describe label control and frame control in VB. Label control is used to provide a descriptive caption and possibly an associated hot key for other controls, such as TextBox, ListBox, and ComboBox, that don't expose the Caption property. In most cases, we just place a Label control where we need it, set its Caption property to a suitable string and we're done. Caption is the default property for Label controls. Be careful to set the Label's TabIndex property so that it's 1 minus the TabIndex property of the companion control. Frame controls are similar to Label controls in that they can serve as captions for those controls that don't have their own. Moreover, Frame controls can also (and often do) behave as containers and host other controls. In most cases, you only need to drop a Frame control on a form and set its Caption property. If you want to create a borderless frame, you can set its BorderStyle property to 0-None. Q115. What do you mean by data source name (DSN)? A data source name (DSN) is a data structure that contains the information about a specific database that an Open Database Connectivity ( ODBC ) driver needs in order to connect to it. Included in the DSN, which resides either in the registry or as a separate text file, is information such as the name, directory and driver of the database, and, depending on the type of DSN, the ID and password of the user. The developer creates a separate DSN for each database. To connect to a particular database, the developer specifies its DSN within a program. In contrast, DSN-less connections require that all the necessary information be specified within the program. There are three kinds of DSN: user DSNs (sometimes called machine DSN s); system DSN s; file DSN s.
User and system DSNs are specific to a particular computer, and store DSN information in the registry. A user DSN allows database access for a single user on a single computer, and a system DSN for any user of a particular computer. A file DSN contains the relevant information within a text file with a .DSN file extension, and can be shared by users of different computers who have the same drivers installed. Q116. Date and time functions. Function Year ( ) Extracted Portion Year (Now)
Month (Now) Day (Now) WeekDay (Now) Hour (Now) Minute (Now)
Second ( ) Second (Now) The calculation and conversion functions related to date and time functions are listed below. Function DateAdd ( ) DateDiff ( ) DatePart ( ) DateValue ( ) TimeValue ( ) Description Returns a date to which a specific interval has been added Returns a Long data type value specifying the interval between the two values Returns an Integer containing the specified part of a given date Converts a string to a Date Converts a string to a time
DateSerial ( ) Returns a date for specified year, month and day Q117. Define user defined data type in VB. Variables of different data types when combined as a single variable to hold several related informations is called a User-Defined data type. A Type statement is used to define a user-defined type in the General declaration section of a form or module. User-defined data types can only be private in form while in standard modules can be public or private. An example for a user defined data type to hold the product details is as given below. Private Type ProductDetails ProdID as String ProdName as String Price as Currency End Typ The user defined data type can be declared with a variable using the Dim statement as in any other variable declaration statement. An array of these userdefined data types can also be declared. An example to consolidate these two features is given below. Dim ElectronicGoods as ProductDetails ' One Record Dim ElectronicGoods(10) as ProductDetails ' An array of 11 records A User-Defined data type can be referenced in an application by using the variable name in the procedure along with the item name in the Type block. Say,
for example if the text property of a TextBox namely text1 is to be assigned the name of the electronic good, the statement can be written as given below. Text1.Text = ElectronicGoods.ProdName If the same is implemented as an array, then the statement becomes Text1.Text = ElectronicGoods(i).ProdName User-defined data types can also be passed to procedures to allow many related items as one argument. Sub ProdData( ElectronicGoods as ProductDetails) Text1.Text = ElectronicGoods.ProdName Text1.Text = ElectronicGoods.Price End Sub