VB 51-60

Embed Size (px)

Citation preview

  • 7/28/2019 VB 51-60

    1/4

    Q51. How does the load statement differ from the show statement.

    Both are form methods. To open a form and make it visible, show method is used . When we want to assignproperties to a form and not shown on screen load method is used. In load method, the form is loaded inmemory but not shown on the screen.

    Syntax of Show method is:

    Formname.Show style, ownerform

    Syntax of Load method is:

    Load

    Q52. What is control array? What are its utilities?

    A control array is a group of controls that share the same name type and the same event procedures. Addingcontrols with control arrays uses fewer resources than adding multiple control of same type at design time.

    Control array can be created at the following time

    Design time

    Run time

    Control arrays are one of the most interesting features of the Visual Basic environment, and they add a lot offlexibility to the programs:

    Controls that belong to the same control array share the same set of event procedures; this oftendramatically reduces the amount of code to be written to respond to a user's actions.

    We can dynamically add new elements to a control array at run time; in other words, we caneffectively create new controls that didn't exist at design time.

    Elements of control arrays consume fewer resources than regular controls and tend to producesmaller executables. Besides, Visual Basic forms can host up to 256 different control names, but a

    control array counts as one against this number. In other words, control arrays let you effectivelyovercome this limit.

    Q53. What do you mean by arrays of array?

    An array of which each element is itself an array is called an array of arrays, or a jagged array. Havingarrays as elements is not the same thing as a multidimensional array, which has more than one indexon a single array.

    Declaration of a jagged array:- Dim jaggedArray(D1)() As datatype

    For example, you might have an array of months, each element of which is an array of days. Sincedifferent months have different numbers of days, the elements do not form a rectangular two-dimensional array. In such a case, you can use a jagged array instead of a multidimensional array.

    Q54. What is a multi-dimesional array ?

    Ans.

    You may need to use two subscripts to identify tabular data, where data are arranged in rows and columns. Todefine a two-dimentional array or table, the Dim statement specfies the number of rows and columns in thearray. The row is horizontal and the column is vertical.

    Syntax:

    Dim ArrayName ( [ LowerLimit To ] UpperLimit, [ LowerLimit To ] UpperLimit ) As Datatype

    Example:

    Dim strName ( 2, 3 ) As String

  • 7/28/2019 VB 51-60

    2/4

    Dim strName ( 0 To 2 , 0 To 3 ) As string

    Q55. What is dynamic array? How to allocate space for dynamic array? How to preserveinformation in a dynamic array?

    An array which can be resized or re-dimensioned at runtime is known as dynamic array. It can be declared bythe dim keyword with empty parenthesis & re-dimensioned by the redim statement.

    Redim statement can only appears within a procedure because it is an executable statement which makesthe application carries out an action only at runtime. E.g

    Dim x () as integer

    Redim x (5) as integer

    For example the dynamic array matrix one is created by first declaring it at the module level: Dim Matrix 1 () AsInteger

    A procedure then allocates space for the array:

    Sub CalcValuesNow ()

    ReDim Matrix (19,29)

    End Sub

    The ReDim statement shown here allocates a matrix of 20 by 30 integers (at a total size of 600 elements).Alternatively, the bounds of a dynamic array can be set using variables: ReDim Matrix1(X,Y)

    Preserving the content of dynamic array:-

    Each time executing the ReDim statement al values currently stored in the array are lost. VB reset the valuesto empty for variant type, to zero for numeric type , 0 length for string type and nothing for object type.

    In order to preserve the data in an existing array the preserve keyword is used when there is a need tochange the last dimension.

    Eg: ReDim preserve x(10) as Integer.

    ReDim preserve x ( + 1) as integer by this declaration the array size is increased by one but all the currentinformation remains intact.

    List index property:=

    This is the index of the selected item in the list. If multiple items are selected list index is the index of the mostrecently selected items. We use this property to access specific almosts in the list or delete specific items. Thefollowing statement removes the selected item from the list control but only if an item is selected.

    List1.remove item.list1. listindex after the removal of the item, the indices of the following item are adjustedaccordingly.

    List box & combo box controls supports this property.

    For list box control(to remove a selected item)

    If list1.listindx>=0 then

    List1.removeitem list1.listindex

    End if

    Q56. What is a purpose of splash screen?

    Ans:

    Perhaps you have noticed the logo or window that often appears while program is loading. This initial form iscalled splash screen. Professional applications use splash screens to tell the user that the program is loadingand starting. It can make a large application appear to load and run faster, since something appears on the

  • 7/28/2019 VB 51-60

    3/4

    screen while the rest of the application loads. You can create your own splash screen or use the splash screentemplate included woth Visual Basic. In the add form dialog box, choose the Splash screen to add a new form;then modify the form as you need.

    Q57. How can we create a pop-up menu?

    In visual basic we can display a context menu by calling the pop-up menu method and passing it any top levelmenu object.For Ex: if we have an edit menu named mnuedit with cut, copy and paste submenus, we can display a contentmenu with the cut, copy, and paste commands by calling pop-up Menu mnuedit.codeprivate Sub mnuCut_click()MsgBox you selected cutEnd Subprivate Sub mnuCopy_click()MsgBox you selected copyEnd Subprivate Sub mnuPaste_click()MsgBox you selected pasteEnd SubPrivate Sub Form_MouseDown( Button as Integer, Shift as Integer, X as single, Y as Single)

    If button = Vb Right button thenPop-up Menu mnuEditEnd ifEnd sub

    Q58. Distinguish between procedure and function?

    Procedure:a. A procedure is a set of one or more program statements that can be executed by referring to theprocedure name. We can reuse the code written in a procedure as it can be executed any number of times bymaking a call to the procedure.b. Subroutines (a type of procedure) perform a task and dont report anything to the calling program.c. The state means that make up a procedure and placed within sub /End sub.d. Sub Show Date()

    Msg Box Date()

    End Sube. To call a procedure:Show Date()

    Function:a. A function is similar to a subroutine, but a function returns a result.

    b. Functions commonly carried out calculation and report the result.c. The statements that make up a function are placed within function/ End function.d. Function Next Day() As DateNext Day = Date() + 1End Function.e. To call a function:

    Dim d as Dated= Next Day()

    Q59. What is procedure?

    A procedure is a set of one or more program statements that can be executed by referring to the procedurename. We can reuse the code written in a procedure, as it can be executed any number of times by making acall to the procedure.

    Advantage:-

    1) Allow us to break an application into discrete logical units, thus making the application more readable.

    2) Procedures help in debugging an application because debugging separate units of an application is easierthem debugging the application as a whole.

    3) Procedures are reusable across programs with little or no modification.

    Q60. How many types of procedures are there in Visual Basic?

  • 7/28/2019 VB 51-60

    4/4

    a) Sub procedure:

    Sub procedure has two types:--

    (i) General procedure: A general procedure is a block of code that performs a specific task. If we needto perform as specific task posted of writing the code multiples times in different parts of theapplication, we can write the code in a procedure and call the procedure from anywhere within theapplication. It is a declared as public then other application can use it.

    (ii) Event handling procedure: An Event handling procedure is a block of code that is executed whena specific event occurs, such as the click of button the loading of a form in the memory or fulfillmentof a user defined condition. Example: If a user click a command button object with the namecommand1, the procedure named command1_click() is called and the code within the procedure isexecute.

    b) Function procedure: A function procedure is a block of code enclosed within the function. End functionstatements a function procedure unlike a sub procedure, returns a value to the calling code. If we need aprocedure to returns a value so that the return value can be further procedure in the calling code, we shouldcreate a function procedure instead a sub procedure.

    c) Property procedure: A property procedure is a set of code statements that are used to assign or creative

    the value of the properties declared with in a module, a class or a structure. Properties are type of variables

    that store the values for an object of a class or a structure.