You are on page 1of 5

Basic VB interview questions

A reader sent these in noting that these questions were used in his company for interviewing prospective VB
programmers.

1. How do you center a form?

2. Can I send keystrokes to a DOS application?


3. Convert an RGB value to a long, or a long to RGB.
4. Implement smooth scrolling for either text, graphics or controls across a form.
5. Implement some quick and easy encryption (can be something primitive).
6. 4 different types of sorts: advantages and disadvantages.
7. Compute CRC32 checksum, write a quick piece of code that accepts the packet of data and returns
the CRC.  
8. How do you use the Mouse OFF event?
9. How do I call Windows Help files from a VB program?
10. How do I create a textbox that lets you insert tabs?
11. How do I make text box that displays asterisks when the user types in data such as password?
12. How do I create multi-column combo box?
13. How do I make a menu popup from a CommandButton?
14. How to create menus at run time in VB?
15. Write a generic error handling routine.
16. How to copy text to the Windows clipboard and from it.
17. How can I call a Command button without clicking it?

18. Write a simple app with Encrypt and Decrypt buttons and Textbox where the user can enter text for
encryption and decryption.

ASP, ADO and IIS interview questions

This came in the mail from the reader who recently went through a job interview process. He didn’t mention the
company name.

1. Why do you use Option Explicit?

2. What are the commonly used data types in VBScript?


3. What is a session object?
4. What are the three objects of ADO?
5. What are the lock-types available in ADO? Explain.
6. What are the cursor types available in ADO? Explain.
7. What is a COM component?
8. How do you register a COM component?
  9. What is a virtual root and how do you create one?  
10. What is a database index, how do you create one, discuss its pros and cons?
11. How do you use multiple record sets (rs.NextRecordSet)?
12. As soon as you fetch a record set, what operations would you perform?
13. Define a transaction. What are ACID properties of a transaction?
14. How would you remotely administer IIS?
15. What is RAID? What is it used for?
16. What is normalization? Explain normalization types.
17. What is the disadvantage of creating an index in every column of a database table?
18. What are the uses of source control software?
19. You have a query that runs slowly, how would you make it better? How would you make it better in .NET
environment?
20. What is a bit datatype? What is it used for?
21. How would you go about securing IIS and MS-SQL Server?
22. What is the difference between Request("field") and Request.Form("field")?

 
 
  COM interview questions

1. What is IUnknown? What methods are provided by IUnknown? It is a generally good idea to have
an answer for this question if you claim you know COM in your resume. Otherwise, you may consider
your interview failed at this point. IUnknown is the base interface of COM. All other interfaces must
derive directly or indirectly from IUnknown. There are three methods in that interface: AddRef, Release
and QueryInterface.
2. What are the purposes of AddRef, Release and QueryInterface functions? AddRef increments
reference count of the object, Release decrements reference counter of the object and QueryInterface
obtains a pointer to the requested interface.
3. What should QueryInterface functions do if requested object was not found? Return
E_NOINTERFACE and nullify its out parameter.
4. How can would you create an instance of the object in COM? Well, it all depends on your project.
Start your answer from CoCreateInstance or CoCreateInstanceEx, explain the difference between them.
If interviewer is still not satisfied, you’ll have to explain the whole kitchen behind the scenes, including a
difference between local server and inproc server, meaning and mechanism of class factory, etc. You
may also mention other methods of object creation like CoGetInstanceFromFile, but discussion will likely
turn to discussion of monikers then.
5. What happens when client calls CoCreateInstance? Again, all depends on the level of detail and
expertise of interviewer. Start with simple explanation of class object and class factory mechanism.
Further details would depend on a specific situation.
6. What the limitations of CoCreateInstance? Well, the major problems with CoCreateInstance is that it
is only able to create one object and only on local system. To create a remote object or to get several
objects, based on single CLSID, at the same time, one should use CoCreateInstanceEx.
7. What is aggregation? How can we get an interface of the aggregated object? Aggregation is the
reuse mechanism, in which the outer object exposes interfaces from the inner object as if they were
implemented on the outer object itself. This is useful when the outer object would always delegate every
call to one of its interfaces to the same interface in the inner object. Aggregation is actually a specialized
case of containment/delegation, and is available as a convenience to avoid extra implementation
overhead in the outer object in these cases. We can get a pointer to the inner interface, calling
QueryInterface of the outer object with IID of the inner interface.
8. C is aggregated by B, which in turn aggregated by A. Our client requested C. What will
happen? QueryInterface to A will delegate request to B which, in turn, will delegate request for the
interface to C. This pointer will be returned to the client.
9. What is a moniker ? An object that implements the IMoniker interface. A moniker acts as a name that
uniquely identifies a COM object. In the same way that a path identifies a file in the file system, a
moniker identifies a COM object in the directory namespace.
10. What’s the difference, if any, between OLE and COM? OLE is build on top of COM. The question is
not strict, because OLE was built over COM for years, while COM as a technology was presented by
Microsoft a few years ago. You may mention also that COM is a specification, while OLE is a particular
implementation of this specification, which in today’s world is not exactly true as well, because what
people call COM today is likely implementation of COM spec by Microsoft.
11. What’s the difference between COM and DCOM? Again, the question does not require strict answer.
Any DCOM object is yet a COM object (DCOM extends COM) and any COM object may participate in
DCOM transactions. DCOM introduced several improvements/optimizations for distributed environment,
such as MULTI_QI (multiple QueryInterface()), security contexts etc. DCOM demonstrated importance of
surrogate process (you cannot run in-proc server on a remote machine. You need a surrogate process to
do that.) DCOM introduced a load balancing.
12. What is a dual interface? Dual interface is one that supports both - IDispatch interface and vtbl-based
interface. Therefore, it might be used in scripting environment like VBScript and yet to use power and
speed of vtbl-based interface for non-scripting environment. Discussion then may easily transform into
analyzing of dual interface problems - be prepared to this twist.
13. Can you have two dual interfaces in one class? Yes. You may have two dual interfaces in one class,
but only one of them may be default. The bottom line is that you cannot work with two dual interfaces at
the same time due to nature of dual interface! To support two dual interfaces in VB you would write
something like:
14. dim d1 as IDualInterface1
15. dim d2 as IDualInterface2
16. set d1 = new MyClassWithTwoDuals
17. set d2 = d1

In ATL’s class you would have to use macro COM_INTERFACE_ENTRY2(IDispatch,


IDualInterface1), to distinguish between different dual interfaces.

18. What is marshalling by value? Some objects can essentially be considered static: regardless of which
methods are called, the state of the object does not change. Instead of accessing such an object
remotely, it is possible to copy the static state of the object and create a new object with the same state
information on the caller side. The caller won’t be able to notice the difference, but calls will be more
efficient because they do not involve network round trips. This is called “marshaling by value".

19. What is a multi-threaded apartment (MTA)? Single-threaded apartment (STA)? This is pretty
difficult question to describe shortly. Anyway, apartments were introduced by Microsoft in NT 3.51 and
late Windows 95 to isolate the problem of running legacy non-thread safe code into multithreaded
environment. Each thread was “encapsulated” into so called single-threaded apartment. The reason to
create an object in apartment is thread-safety. COM is responsible synchronize access to the object even
if the object inside of the apartment is not thread-safe. Multithreaded apartments (MTA, or free
threading apartment) were introduced in NT 4.0. Idea behind MTA is that COM is not responsible to
synchronize object calls between threads. In MTA the developer is responsible for that. See “Professional
DCOM Programming” of Dr. Grimes et al. or “Essential COM” of Don Box for the further discussion on this
topic.
20. Let’s assume we have object B and aggregated object C (in-proc server), created by B. Can
you access any interface of B from C? What’s the difference between aggregated and
contained objects? Yes, you can. This is fundamental postulate of COM: “If you can get there from
here, you can get there from anywhere", i.e. QI’ing for IUnknown you may proceed and to get a pointer
to any other interface, supported by the object. Aggregated object exposes its interface directly, without
visible intervention of the object container. Contained object is created within the object container and its
interfaces might be altered or filtered by the object container.
21. What is ROT ? GIT ? Count pros and cons of both. By definition, running object table (ROT) is a
globally accessible table on each computer that keeps track of all COM objects in the running state that
can be identified by a moniker. Moniker providers register an object in the table, which increments the
object’s reference count. Before the object can be destroyed, its moniker must be released from the
table. Global Interface Table (GIT) allows any apartment (either single- or multi-threaded) in a process
to get access to an interface implemented on an object in any other apartment in the process.
22. If you have an object with two interfaces, can you custom marshal one of them? No! The
decision to use custom marshaling is an all-or-nothing decision; an object has to custom marshal all its
interfaces or none of them.
23. Is there a way to register in-proc server without regsvr32.exe? Yes. Call DllRegisterServer() from
the client. Do not forget to call DLLUnregisterServer() from the same client. You may also use Registrar
object for the same purpose or use direct manipulation of the windows registry.
24. What is VARIANT? Why and where would you use it? VARIANT is a huge union containing
automation type. This allows easy conversion of one automation type to another. The biggest
disadvantage of VARIANT is size of the union.
25. How can you guarantee that only remote server is ever created by a client? Create an object
(call CoCreateObjectEx()) with CLSCTX_REMOTE_SERVER flag.
26. What is __declspec(novtable)? Why would you need this? __declspec(novtable) is a Microsoft’s
compiler optimization. The main idea of this optimization is to strip the vtable initialization code from
abstract class (for abstract class the vtable is empty, while it is initialized in contructor) MSDN has an
article on this topic.
27. What is an IDL? IDL stands for Interface Definition Language. IDL is the language to describe COM
interfaces.
28. What is In-proc? In-proc is in-process COM object, i.e. COM object that implemented as DLL and
supposed to be hosted by a container. When you have to instantiate the in-proc object remotely, you
may use DLLHost.exe application that was design specially for this purpose.
29. What is OLE? OLE is an object and embedding first implementation of COM spec available from MS
before COM was officially named COM.
30. Give examples of OLE usage. The most famous examples are probably drag and drop and structured
storage implementations.
31. What are 2 storage types for composite document? Storage and Stream.

32. Is .doc document a compound document? Is it a structured storage? Compound document is a


document that contains information about other documents hosted in this document. All office
documents _may_ be compound documents, but may be not. Word documents from version 6.0 and up
are stored as structured storage.

VB 6, COM, DCOM, Microsoft platform interview questions

1. 3 main differences between flexgrid control and dbgrid control

2. ActiveX and Types of ActiveX Components in VB


3. Advantage of ActiveX Dll over ActiveX Exe
4. Advantages of disconnected recordsets
5. Benefit of wrapping database calls into MTS transactions
6. Benefits of using MTS
7. Can database schema be changed with DAO, RDO or ADO?
8. Can you create a tabletype of recordset in Jet-connected ODBC database engine?
9. Constructors and destructors
  10.
11.
Controls which do not have events
Default property of datacontrol
 

12. Define the scope of Public, Private, Friend procedures?


13. Describe Database Connection pooling relative to MTS
14. Describe: In of Process vs. Out of Process component. Which is faster?
15. Difference between a function and a subroutine, Dynaset and Snapshot, early and late binding, image
and picture controls, linked object and embedded Object,listbox and combo box,Listindex and Tab
index,modal and moduless window, Object and Class, query unload and unload in form, declaration and
instantiation of an object?
16. Draw and explain Sequence Model of DAO
17. How can objects on different threads communicate with one another?
18. How can you force new objects to be created on new threads?
19. How does a DCOM component know where to instantiate itself?
20. How do I register a component?
21. How do I set a shortcut key for label?
22. What kind of components can be used as DCOM servers?
23. Name of the control used to call a Windows application
24. Name the four different cursor and locking types in ADO and describe them briefly
25. Need of zorder method, no of controls in form, Property used to add a menus at runtime, Property used
to count number of items in a combobox,resize a label control according to your caption.
26. Return value of callback function, The need of tabindex property
27. Thread pool and management of threads within a thread pool
28. To set the command button for ESC, Which property needs to be changed?
29. Type Library and what is it’s purpose?
30. Types of system controls, container objects, combo box
31. Under the ADO Command Object, what collection is responsible for input to stored procedures?
32. What are the ADO objects? Explain them.
33. What are the different compatibility types when we create a COM component?
34. What do ByVal and ByRef mean and which is the default?
35. What does Option Explicit refer to?
36. What does the Implements statement do?
37. What is OLE and DDE? Explain.
38. What is the difference between Msgbox Statement and MsgboxQ function?
39. What keyword is associated with raising system level events in VB?
40. What methods are called from the ObjectContext object to inform MTS that the transaction was
successful or unsuccessful?
41. What types of data access have you used.
42. What was introduced to Visual Basic to allow the use of Callback Functions?
43. Which controls can not be placed in MDI?
44. Which controls have refresh method, clear method
45. Which Property is used to compress a image in image control?
46. Which property of menu cannot be set at run time?
47. Which property of textbox cannot be changed at runtime?
48. What is the maximum size of a textbox?

49. Which tool is used to configure the port range and protocols for DCOM communications?

Note: This set of questions was sent in by a recruiter with no answers provided. Usually that means that
the interview is conducted by developers themselves who do not need a cheat sheet for the upcoming
interview, and they prefer to ask the questions that they are intimately familiar with. Please consider
looking into several in-depth titles on Visual Basic to find out the answers. I don’t have them. If you’re
willing to send them or post them here, I would gladly publish them.

  Visual Basic

1. How do you register a component? Expected answer: Compiling the component, running REGSVR32
MyDLL.dll

2. Name and explain the different compatibility types when creating a COM component. Expected
answer: No Compatibility ? New GUID created, references from other components will not workProject
Compatibility ? Default for a new component <Not as critical to mention this one>Binary Compatibility ?
GUID does not change, references from other components will work
3. Why iss it important to use source control software for source code? Expected answer: Modification
history.Code ownership: Multiple people can not modify the same code at the same time.
4. What two methods are called from the ObjectContext object to inform MTS that the transaction
was successful or unsuccessful? Expected answer: SetComplete and SetAbort.
5. What is the tool used to configure the port range and protocols for DCOM communications?
Expected answer: DCOMCONFIG.EXE
6. What does Option Explicit refer to? Expected answer: All variables must be declared before use. Their
type is not required.
7. What are the different ways to Declare and Instantiate an object in Visual Basic 6? Expected
answer: Dim obj as OBJ.CLASS with eitherSet obj = New OBJ.CLASS orSet obj = CreateObject(?
OBJ.CLASS?) orSet obj = GetObject( ,? OBJ.CLASS?)orDim obj as New OBJ.CLASS
8. Name the four different cursor types in ADO and describe them briefly. Expected answer: The cursor
types are listed from least to most resource intensive.Forward Only ? Fastest, can only move forward in
recordset Static ? Can move to any record in the recordset. Data is static and never changes.KeySet ?
Changes are detectable, records that are deleted by other users are unavailable, and records created by
other users are not detectedDynamic ? All changes are visible.
9. Name the four different locking type in ADO and describe them briefly. Expected answer:
LockPessimistic ? Locks the row once after any edits occur.LockOptimistic ? Locks the row only when Update
is called.LockBatchOptimistic ? Allows Batch Updates.LockReadOnly ? Read only. Can not alter the data.
10. Describe Database Connection pooling (relative to MTS ) Expected answer: This allows MTS to reuse
database connections. Database connections are put to ?sleep? as opposed to being created and destroyed
and are activated upon request.
11. What are the ADO objects? Explain them. Provide a scenario using three of them to return data
from a database. Expected answer: Connection ? Connects to a data source; contains the Errors
collectionCommand ? Executes commands to the data source. Is the only object that can accept parameters
for a stored procedure.Recordset ? The set of data returned from the database.Scenario: There are many
possibilities. The most likely is as follows:Dim conn As ADODB.ConnectionDim rs As ADODB.RecordsetDim
Cmd As ADODB.Commandconn.ConnectionString = ?CONNECTION STRING?conn.OpenSet
Cmd.ActiveConnection = connCmd.CommandText = ?SQL STATEMENT?Set rs = Cmd.ExecuteSet
rs.ActiveConnection = Nothingconn.Close
12. Under the ADO Command Object, what collection is responsible for input to stored procedures?
Expected answer: The Parameters collection.
13. What are some benefits of using MTS? Expected answer: Database Pooling, Transactional operations,
Deployment, Security, Remote Execution.
14. What is the benefit of wrapping database calls into MTS transactions? Expected answer: If database
calls are made within the context of a transaction, aborting the transaction will undo and changes that occur
within that transaction. This removes the possibility of stranded, or partial data.
15. Describe and In Process vs. Out of Process component. Which is faster? Expected answer:An in-
process component is implemented as a DLL, and runs in the same process space as its client app, enabling
the most efficient communication between client and component.Each client app that uses the component
starts a new instance of it.An out of process component is implemented as an EXE, and unlike a dll, runs in
its own process space. As a result, exe’s are slower then dll’s because communications between client and
component must be marshalled across process boundaries. A single instance of an out of process
component can service many clients.

16. What are the main components of the ADO object model? How are they used? Expected
answer:Connection: Used to make a connection between your app and an external data source, ie, sql
server.Command: Used to build queries, including user-specific parameters, to access records from a data
source (which are returned in a Recordset)Recordset:Used to access records returned from an SQL query.
With a recordset, you can navigate returned records. You can also add, modify or delete records.

You might also like