You are on page 1of 11

1. What is VB?

Visual Basic (VB) is an ideal programming language for developing sophisticated professional applications for Microsoft Windows. It makes use of Graphical User Interface for creating robust and powerful applications. The Graphical User Interface as the name suggests, uses illustrations for text, which enable users to interact with an application. Visual Basic (VB) was developed from the BASIC programming language and is an event-driven programming language. Visual Basic enables the user to design the user interface quickly by drawing and arranging the user elements. Due to this spent time is saved for the repetitive task. 2. What are the important features of VB? Full set of objects - you 'draw' the application Lots of icons and pictures for your use Response to mouse and keyboard actions Clipboard and printer access Full array of mathematical, string handling, and graphics functions Can handle fixed and dynamic variable and control arrays Sequential and random access file support Useful debugger and error-handling facilities Powerful database access tools ActiveX support Package & Deployment Wizard makes distributing your applications simple.

3. What are the previous versions of VB? The original Visual Basic for DOS and Visual Basic For Windows were introduced in 1991. Visual Basic 3.0 (a vast improvement over previous versions) was released in 1993. Visual Basic 4.0 released in late 1995 (added 32 bit application support). Visual Basic 5.0 released in late 1996. New environment, supported creation of ActiveX controls, deleted 16 bit application support. Visual Basic 6.0 - released in mid 1998s - some identified new features of Visual Basic 6.0: Faster compiler New ActiveX data control object Allows database integration with wide variety of applications New data report designer New Package & Deployment Wizard Additional internet capabilities.

4. What are the main components of Visual Basic IDE? Menu Bar Tool Bar Project Explorer Properties window

Form Layout Window Toolbox Form Designer Object Browser

5. What is mean by module? What are the kinds of modules? Code in Visual Basic is stored in the form of modules. The three kind of modules are Form Modules, Standard Modules and Class Modules. A simple application may contain a single Form, and the code resides in that Form module itself. As the application grows, additional Forms are added and there may be a common code to be executed in several Forms. To avoid the duplication of code, a separate module containing a procedure is created that implements the common code. This is a standard Module. Class module (.CLS filename extension) are the foundation of the object oriented programming in Visual Basic. New objects can be created by writing code in class modules. Each module can contain: Declarations : May include constant, type, variable and DLL procedure declarations. Procedures : A sub function, or property procedure that contain pieces of code that can be executed as a unit. 6. What are the rules to follow when naming elements in VB? A name must begin with a letter. May be as much as 255 characters long (but don't forget that somebody has to type the stuff!). Must not contain a space or an embedded period or type-declaration characters used to specify a data type; these are ! # % $ & @ Must not be a reserved word (that is part of the code, like Option, for example) The dash, although legal, should be avoided because it may be confused with the minus sign. Instead of First-name use First_name or FirstName. 7. What are the data types used in VB? By default Visual Basic variables are of variant data types. The variant data type can 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. In addition, some types can interchange with some other types. A list of Visual Basic's simple data types are given below. 1. Numeric Byte Integer Long Store integer values in the range of 0 - 255 Store integer values in the range of (-32,768) - (+ 32,767) Store integer values in the range of (- 2,147,483,468) - (+ 2,147,483,468)

Single Double Currency 2. String

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 to the left

Use to store alphanumeric values. A variable length string can store approximately 4 billion characters 3. 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 4. 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. 5. 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. 8. What are the operators used in VB? Arithmetical Operators Operators + / \ * ^ Mod & Add Substract Divide Integer Division Multiply Exponent (power of) Remainder of division String concatenation Description 5+5 10-5 25/5 20\3 5*4 3^3 20 Mod 6 Example 10 5 5 6 20 27 2 Result

"George"&" "&"Bush" "George Bush"

Relational Operators

Operators > < >= <= <> =

Description Greater than Less than 10>8 10<8

Example True False True True True False

Result

Greater than or equal to 20>=10 Less than or equal to Not Equal to Equal to 10<=20 5<>4 5=7

Logical Operators Operators OR AND Description Operation will be true if either of the operands is true Operation will be true only if both the operands are true

9. What is mean by explicit 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 10. What is the use of Option Explicit statement in VB? t may be convenient to declare variables implicitly, but it can lead to errors that may not be recognized at run time. Say, for example a variable by name intcount is used implicitly and is assigned to a value. In the next step, this field is incremented by 1 by the following statement Intcount = Intcount + 1 This calculation will result in intcount yielding a value of 1 as intcount would have been initialized to zero. This is because the intcount variable has been mityped as incont in the right hand side of

the second variable. But Visual Basic does not see this as a mistake and considers it to be new variable and therefore gives a wrong result. In Visual Basic, to prevent errors of this nature, we can declare a variable by adding the following statement to the general declaration section of the Form. Option Explicit This forces the user to declare all the variables. The Option Explicit statement checks in the module for usage of any undeclared variables and reports an error to the user. The user can thus rectify the error on seeing this error message. The Option Explicit statement can be explicitly placed in the general declaration section of each module using the following steps. Click Options item in the Tools menu Click the Editor tab in the Options dialog box Check Require Variable Declaration option and then click the OK button

11. What are the scope of variables in VB? A variable is scoped to a procedure-level (local) or module-level variable depending on how it is declared. The scope of a variable, procedure or object determines which part of the code in our application are aware of the variable's existence. A variable is declared in general declaration section of e Form, and hence is available to all the procedures. Local variables are recognized only in the procedure in which they are declared. They can be declared with Dim and Static keywords Local Variables A local variable is one that is declared inside a procedure. This variable is only available to the code inside the procedure and can be declared using the Dim statements as given below. Dim sum As Integer Static Variables Static variables are not reinitialized each time Visual Invokes a procedure and therefore retains or preserves value even when a procedure ends. In case we need to keep track of the number of times a command button in an application is clicked, a static counter variable has to be declared. These static variables are also ideal for making controls alternately visible or invisible. A static variable is declared as given below. Static intPermanent As Integer Module Levele Variables A module level variable is available to all the procedures in the module. They are declared using the Public or the Privatekeyword. If you declare a variable using a Private or a Dim statement in the declaration section of a modulea standard BAS module, a form module, a class module,

and so onyou're creating a private module-level variable. Such variables are visible only from within the module they belong to and can't be accessed from the outside. 12. Can a variable have same name and different scope? A variable can have the same name and different scope. For example, we can have a public variable named R and within a procedure we can declare a local variable R. References to the name R within the procedure would access the local variable and references to R outside the procedure would access the public variable. 13. What is the use of Exit For statement in VB? A For...Next loop condition can be terminated by an Exit For statement. Dim x As Integer For x = 1 To 10 Print x If x = 5 Then Print "The program exited at x=5" Exit For End If Next The preceding code increments the value of x by 1 until it reaches the condition x = 5. The Exit For statement is executed and it terminates the For...Next loop. 14. What is the use for Exit Do statement in VB? A Do...While loop condition can be terminated by an Exit Do statement. Dim x As Integer Do While x < 10 Print x x=x+1 If x = 5 Then Print "The program is exited at x=5" Exit Do End If Loop 15. What is the use of With.End With statement in VB? When properties are set for objects or methods are called, a lot of coding is included that acts on the same object. It is easier to read the code by implementing the With...End With statement. Multiple properties can be set and multiple methods can be called by using the With...End With statement. The code is executed more quickly and efficiently as the object is evaluated only once. With Text1 .Font.Size = 14 .Font.Bold = True .ForeColor = vbRed .Height = 230

.Text = "Hello World" End With In the above coding, the object Text1, which is a text box is evaluated only once instead of every associated property or method. This makes the coding simpler and efficient. 16. What are the types of arrays in VB? There are two types of arrays in Visual Basic namely: Fixed-size array : The size of array always remains the same-size doesn't change during the program execution. Dynamic array : The size of the array can be changed at the run time- size changes during the program execution. 17. What is the TabIndex property of controls in VB? Visual Basic uses the TabIndex property to determine the control that would receive the focus next when a tab key is pressed. Every time a tab key is pressed, Visual Basic looks at the value of the TabIndex for the control that has focus and then it scans through the controls searching for the next highest TabIndex number. When there are no more controls with higher TabIndex value, Visual Basic starts all over again with 0 and looks for the first control with TabIndex of 0 or higher that can accept keyboard input.

18. How do I validate the date entered in textbox?


Private Sub Command1_Click() If IsDate(Text1.Text) Then MsgBox CDate(Text1.Text) Else MsgBox "Invalid date entered" End If End Sub

19. How to start remote programs (i.e.: notepad, calculator) using version 5.0 learning
or 6.0 enterprise editions of VB? Use Shell function. It is available in all editions and versions of VB. For example: Shell c:\winnt\notepad.exe, vbNormalFocus

20. Is there an easy way to resize all the objects when resizing the form?
There is no easy way. You have to catch new form' size and recalculate all the components' sizes. For example, following code keeps textbox as big as possible and command button in the middle of the form: Private Sub Form_Resize() On Error Resume Next Text1.Width = Me.Width - 60 Text1.Height = Me.Height - 960 Command1.Top = Me.Height - Command1.Height - 430

Command1.Left = (Me.Width - Command1.Width) / 2 End Sub

21. How do I make a self extractor that automatically gets all the dll's it need and puts
them all into one file? It takes two steps to create self-extracting setup executable. 1)Use VB Setup wizard (or Package and Deployment wizard) to create setup package - bunch of files including your application executable with dependencies (dlls, ocxs, etc). If you are familiar with Installshield, you can use it for that purpose as well. 2)Compile all the files in one executable. The best tool for it is Installshiled PackageForTheWeb. But there is a lot of utilities you can choose from: ZIP-selfextractor, GSX-selfextractor, Instyler, etc.

22. How can I find if table exists in a database?


1.set On Error Resume Next 2.try to open the table you're looking for 3.catch the error (if table exists - err.Number=0) Here is the code for Access database: On Error Resume Next Set dbs = CreateObject("ADODB.Connection") dbs.open "provider=Microsoft.Jet.OLEDB.4.0;data source=c:\yourpath\youfile.mdb" Set rst = dbs.execute("yourtable") If Err.Number <> 0 Then MsgBox "Table not found" Else MsgBox "OK"

23. I could not create a flexgrid. Where is the control button?


Flexgrid is nod intrinsic (standard) Visual Basic control. In order to use it in your project you need to click on "Project" menu and select "Components" submenu. Dialog box with list of available controls will appear. Find "Microsoft Flexgrid Control" and check its checkbox. Click on "OK" button to close "Components" dialog box. Flexgrid icon should appear on "Toolbox" window.

24. How do I make an RTF box un-editable?


Set its property "Locked" to "True". 25. What is the Dll required for running the VB? Vbrun300.dll 26. Which property of menu cannot be set at run time? Name property 27. How to get Cursor position using API?

GetCursorPos() is the API that is used to get the cursor position. 28. What is the difference between Property Get, Set and Let? Set ? Value is assigned to ActiveX Object from the form. Let ? Value is retried to ActiveX Object from the form. Get- Assigns the value of an expression to a variable or property. 29. Does VB Supports OOPS Concepts? Visual Basic is not supprt Inheritance and Data binding OOPS Concept 30. Types of cursors in DAO? * Dynamic cursor - Allows you to see additions changes and deletions by other users. * Keyset cursor - Like a dynamic cursor except that you cannot see additions by other users and it prevents access to records that other users have deleted. Data changes by other users will still be visible. * Static cursor - Provides a static copy of a recordset for you to use to find data or generate reports. Additions changes or deletions by other users will not be visible. This is the only type of cursor allowed when you open a client-side Recordset object. * Forward-only cursor - Allows you to only scroll forward through the Recordset. Additions changes or deletions by other users will not be visible. 31. Difference between Recordset and Resultsets. recordset-is used in DAO control to access the data resultset-is used in RDO control to access the data 32. What is frx? frx can be said as the resource binder of forms in a vb. For eg: a picture that we set as a background of form or a image box. These resources are binded in the frx file that attach with frm form file. 33. Which property of textbox cannot be changed at runtime. What is the max size of textbox? You can't change Name, Multiline, TabIndex properties of this control. 34. What is the max size of textbox? Max Size of TextBox is 65535 characters. 35. What is the size of the variant data type? The Variant data type has a numeric storage size of 16 bytes and can contain data up to the range of a Decimal, or a character storage size of 22 bytes (plus string length),and can store any character text. 36. What is MDI form?

MDI is Multi Document Interface. It means through a MDI form we can open multiple forms at the same time, without closing any one of them. You cannot place any control in a MDI form. 37. How to check the condition in Msgbox? If(Msgbox("Do you want to delete this Record",VbYesNo)=VbYes)Then End if 38. What is Mask Edit and why it is used? Mask Edit is a control and is used to restrict data input as well as formatting data output. 39. How many images can be placed in the image list? 64 40. What is Collection Objects and why it is preferred over an array? Collection objects are similar to arrays but are preferred over an array because of the following reasons. 1. A collection objects uses less Memory than an array. 2. It provides methods to add and delete members. 3. It does not required reason statement when objects are added or deleted. 4. It does not have boundary limitations. 41. What do ByVal and ByRef mean and which is the default? There are two ways to pass arguments to a procedure in Visual Basic: ByVal and ByRef. This refers to whether a copy of the argument is passed to the procedure (ByVal - the value is passed) or whether the actual argument itself is passed (ByRef - a reference to the argument is passed). The default for VB 6 is to call ByRef. 42. How can visual basic be used for server side scripting? Visual basic can be used for server side scripting. A component designed with Visual basic will not have any user interface instead provides the functionality of Active X to other programs via COM. This form of technique allows server side functionality and add in module. 43. 44. 45. 46. 47. 48. 49. 50. sd df f fd fd f df df

You might also like