Difference between standard and class modules
Classes differ from standard modules in the way their data is stored. There's never more than one copy of a standard module’s data. This means that when one part of your program changes a public variable in a standard module, and another part of your program subsequently reads that variable, it will get the same value. Class module data, on the other hand, exists separately for each instance of the class (that is, for each object created from the class).Data in a standard module has program scope — that is, it exists for the life of your program — while class module data for each instance of a class exists only for the lifetime of the object; it’s created when the object is created, and destroyed when the object is destroyed.
Finally, variables declared Public in a standard module are visible from anywhere in your project, whereas Public variables in a class module can only be accessed if you have an object variable containing a reference to a particular instance of a class.
3. Passing parameter byVal , by reference
If pass by reference value of variable can be changed . By Val the value of variable cannot be changed, procedure access a copy of the variablesADO Sample
OLEDB for SQL SERVERMyConn.ConnectionString= "Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;"
Or dsn-less connection
Connection_string=”uid=myid;pwd=mypwd;database=pubs;driver={SQl Server};dsn=’’”
ACCESS
MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Donations1.mdb;"
Dim MyConn As ADODB.Connection
Dim MyRecSet As ADODB.Recordset
Dim i As Integer
Set MyConn = New ADODB.Connection
MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Donations1.mdb;"
MyConn.Open
Set MyRecSet = MyConn.Execute("SELECT * from [SwitchBoard Items]")
Text1 = MyRecSet.Fields(0)
'Do Until MyRecSet.EOF
List1.Clear
For i = 1 To 5
List1.AddItem MyRecSet(4) & vbKeyTab & " :::::" & MyRecSet(2)
'MsgBox MyRecSet.Fields(0)
MyRecSet.MoveNext
Next
'Loop
MyConn.Close
Different way to attach recordset to connection
Dim objRs
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRs = Server.CreateObject("ADODB.Recordset")
objConn.Open Application("Connection_String")
objRs.Open "exec sp_ListArticles '1/15/2001'", objConn
Working example
Dim adoconn As ADODB.Connection
Set adoconn = New ADODB.Connection
Dim conn_string As String
Dim res As ADODB.Recordset
conn_string = "Driver={SQL Server};Server=METARAMP;database=pubs;UID=sa;PWD=sa;"
adoconn.Open conn_string
If Err.Number Then
MsgBox Err.Number
Else
MsgBox "connected"
End If
Dim stored_proc_string as string
‘’all parameters should be string type and I did not find how to specify output parameters
stored_proc_string = “execute select_from_authors " & par1 , par2
Set res = adoconn.Execute(stored_proc_string)
If Err.Number Then
MsgBox Err.Number
Else
MsgBox "res set "
End If
Do While Not res.EOF
list1.AddItem res(0) & " " & res(1) & " " & res(2)
res.MoveNext
Loop
Advantages of disconnected recordsets
Disconnected recordset - a recordset in a client cache that no longer has a live connection to the server. If something must be done with the original data source, such as updating data, the connection will need to be re-established.
Fill the recordset than set RS.ActiveConnection = nothing
Function GetRS(strSQL)
'this function returns a disconnected RS
'Set some constants
Const adOpenStatic = 3
Const adUseClient = 3
Const adLockBatchOptimistic = 4
'Declare our variables
Dim oConn
Dim strSQL
Dim oRS
'Open a connection
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open mydsn,Sean,Grimaldi
'Create the Recordset object
Set oRS = Server.CreateObject("ADODB.Recordset")
oRS.CursorLocation = adUseClient
'Populate the Recordset object with a SQL query
oRS.Open strSQL, oConn, adOpenStatic, adLockBatchOptimistic
'Disconnect the Recordset
Set oRS.ActiveConnection = Nothing
'Return the Recordset
Set GetRS = oRS
'Clean up...
oConn.Close
oRS.Close
Set oConn = Nothing
Set oRS = Nothing
End Function
'call the function
strSQL = "SELECT * FROM Authors"
set RS = GetRS(strSQL)
Using command object to execute stored procedure with parameters
Private Sub cmd_update_Click()
Dim res As Integer
Set cmd = New ADODB.Command
cmd.ActiveConnection = con
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "update_empdetails"
cmd.Parameters.Append cmd.CreateParameter("empid", adVarChar, adParamInput, 6, txt_empid.Text)
cmd.Parameters.Append cmd.CreateParameter("firstname", adVarChar, adParamInput, 30, txt_firstname.Text)
cmd.Parameters.Append cmd.CreateParameter("title", adVarChar, adParamInput, 30, txt_title.Text)
cmd.Parameters.Append cmd.CreateParameter("address", adVarChar, adParamInput, 100, txt_address.Text)
cmd.Parameters.Append cmd.CreateParameter("result", adInteger, adParamOutput)
cmd.Execute
res = cmd("result")
If (res = 1) Then
MsgBox "Updated Successfully"
End If
Set cmd.ActiveConnection = Nothing
End Sub
Define the scope of Public
Public procedure is accessed from a module or form other than the module or form containing the module definition
Private procedure
Private procedure will be recognized only within the module or form within which it is defined.
Friend procedures
Friend procedures are sensibly faster than Public ones. Friend members is suitable in the ActiveX components. Friend functions are not part of an object's interface. They can't be accessed by programs that use the component's objects. They're only visible to all the other objects within the component to allow safe internal communication within the component. The Friend keyword can only be used in class modules.
In of Process vs. Out of Process component
Which is faster? In-process is faster . it does not need to cross application boundaries to access properties and methods
Objects
Objects in Visual Basic are created from classes; thus an object is said to be an instance of a class. The class defines an object's interfaces, whether the object is public, and under what circumstances it can be created. Descriptions of classes are stored in type libraries. The slowest – late binding, because the objcet is not known. But has more flexibility. By setting Foo as an Object in the Dim statement, you are telling the compiler to hold a reference to an unknown object, so the compiler has absolutely no idea as to what that will be.
Dim Foo as Object
Set Foo = CreateObject(“MyObject.MyClass”)
Early Binding . Compiler knows what to expect before compiling. cutting down on the number of calls, thereby speeding code execution
Dim Foo as objectmy
Set Foo= new ObjectMy
Early binding like
Dim Foo as New MyObject.MyClass
Is the slowest in code execution. By creating this type of Early Binding, the compiler will add verification code before every call to your Foo Object, to verify that the pointer to the interface is valid.
FAQ
Draw and explain Sequence Modal of DAO
How can objects on different threads communicate with one another?
How can you force new objects to be created on new threads?
How does a DCOM component know where to instantiate itself?
How to register a component?
How to set a shortcut key for label?
Kind of components can be used as DCOM servers
Name of the control used to call a windows application
Name the four different cursor and locking types in ADO and describe them briefly
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.
Return value of callback function, The need of tabindex property
Thread pool and management of threads within a thread pool
To set the command button for ESC, Which property needs to be changed?
Cancel property has to be changes.
Type Library and what is it's purpose?
A type library is a binary file containing all the type information you need to use procedures or classes in DLLs. You can examine the standard ones by clicking the Object Browser
Types of system controls, container objects, combo box
Under the ADO Command Object, what collection is responsible for input to stored procedures?
VB and Object Oriented Programming
What are the ADO objects? Explain them.
What are the different compatibility types when we create a COM component?
What does Option Explicit refer to?
Required explicit declaration of all variables
What does the Implements statement do?
Specifies an interface or class that will be implemented in the class module in which it appears
What is OLE and DDE? Explain.
What is the difference between Msgbox Statement and Msgbox function?. A. Function displays a message in a dialog box, waits for the user to click a button, and returns an Integer indicating which button the user clicked. Statement
What keyword is associated with raising system level events in VB?
RaiseEvent
What methods are called from the ObjectContext object to inform MTS that the transaction was successful or unsuccessful?
What types of data access have you used.
What was introduced to Visual Basic to allow the use of Callback Functions?
Which controls can not be placed in MDI?
Only Picture Control can be placed on MDI Parent Form.
Which controls have refresh method, clear method
Most controls have refresh method. Timer control cannot be refreshed. MDI Parent Form cannot be refreshed.
Which Property is used to compress a image in image control?
Which property of menu cannot be set at run time? A. WIndowlist
Which property of textbox cannot be changed at runtime and What's the maximum size of a textbox?
Text property cannot be changed ; The Text setting for a TextBox control is limited to 2048 characters unless the MultiLine property is True, in which case the limit is about 32K
Which tool is used to configure the port range and protocols for DCOM communications?
Multithreading
In Visual Basic, apartment-model threading is used to provide thread safety. In apartment-model threading, each thread is like an apartment — all objects created on the thread live in this apartment, and are unaware of objects in other apartments.
Multiple threads are supported only for components that can be marked for unattended execution — that is, they require absolutely no user interaction. Applications and components authored with Visual Basic are restricted to a single apartment (thread) if they include forms, controls, ActiveX documents, or classes created with ActiveX designers.
To mark your ActiveX DLL or EXE project for unattended execution
Remove all forms, controls, and UserDocuments, along with any classes created using ActiveX designers.
2 On the Project menu, click <project> Properties to open the Project Properties dialog box.
3 On the General tab, check Unattended Execution, then click OK.
How do you register a component? Expected answer: Compiling the component, running REGSVR32 MyDLL.dll To unregister a component you call Regsvr32 with the "/u" switch.
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
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.
What two methods are called from the ObjectContext object to inform MTS that the transaction was successful or unsuccessful? Expected answer: SetComplete and SetAbort.
What is the tool used to configure the port range and protocols for DCOM communications? Expected answer: DCOMCONFIG.EXE
What does Option Explicit refer to? Expected answer: All variables must be declared before use. Their type is not required.
What are the different ways to Declare and Instantiate an object in Visual Basic 6? Expected answer: Dim obj as OBJ.CLASS with either Set obj = New OBJ.CLASS or Set obj = CreateObject(?OBJ.CLASS?) Set obj = GetObject( ,? OBJ.CLASS?) or Dim obj as New OBJ.CLASS
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.
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.
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.
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 collection. Command ? 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.Connection
Dim rs As ADODB.Recordset
Dim Cmd As ADODB.Command
conn.ConnectionString = ?
CONNECTION STRING?
conn.Open
Set Cmd.ActiveConnection = conn
Cmd.CommandText = ?
SQL STATEMENT?
Set rs = Cmd.Execute
Set rs.ActiveConnection = Nothing
conn.Close
Under the ADO Command Object, what collection is responsible for input to stored procedures? Expected answer: The Parameters collection.
What are some benefits of using MTS? Expected answer: Database Pooling, Transactional operations, Deployment, Security, Remote Execution.
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.
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.
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.
In VB6, using ADO (Again, a fairly simple example -- and there are a few other ways to do it):
sample 1 using stored procedure.
Public Function DeleteBufferADO()
Dim msConnectStr As String
Dim sSQL As String
Dim oADOConnObj As New ADODB.Connection
Dim oRecSetas As Variant
msConnectStr = "DSN=QRRTest;UID=batman;PWD=batman;"
Set oADOConnObj = CreateObject("ADODB.Connection")
oADOConnObj.ConnectionString= msConnectStr
With oADOConnObj
.ConnectionTimeout = 3000
.CommandTimeout = 3000
.CursorLocation = adUseClient
.Open msConnectStr
End With
sSQL = "pr_ag_qrr_buffer_delete " & par3 & “,” & par4
Set oRecSet = oADOConnObj.Execute(sSQL)
Set oADOConnObj = Nothing
End Function
Sample 2.
Public Function GetPatInfoRS(cn As ADODB.Connection) as ADODB.Recordset ' Pass in an open connection object
Dim cmd As ADODB.Command
Dim rs As ADODB.Recordset
Set cmd = New ADODB.Command
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "usp_GetPatientInfo"
cmd.Parameters.Append cmd.CreateParameter("@PatientDetail", adBoolean, adParamInput, , UserInterface.PatientDetail.Value)
cmd.Parameters.Append cmd.CreateParameter("@AdjDischg", adBoolean, adParamInput, , UserInterface.AdjDischg.Value)
...
Set cmd.ActiveConnection = cn
Set rs = New ADODB.Recordset
rs.ActiveConnection = cn
rs.Source = cmd.CommandText
rs.CursorLocation = adUseClient
rs.CursorType = adOpenStatic
rs.LockType = adReadOnly
rs.Open cmd
Set rs.AcitveConnection = nothing
Set rs = cmd.Execute
Set GetPatInfoRS = rs.Clone
rs.Close
Set rs = Nothing
Set ActiveConnection = Nothing
Set cmd = Nothing
End Function
Explain the DoEvents statement
A. This statement causes Access Basic to yield control to the Windows operating environment.═ Control is not returned to Access Basic until the environment has finished processing the events in its event queue and all keys in the SendKeys queue have been sent.
Difference between standard and class module:
-There's never more than one copy of a standard module's data
Class module data, on the other hand, exists separately for each instance of the class (that is, for each object created from the class).
-Data in a standard module has program scope — that is, it exists for the life of your program — while class module data for each instance of a class exists only for the lifetime of the object
-Variables declared Public in a standard module are visible from anywhere in your project, whereas Public variables in a class module can only be accessed if you have an object variable containing a reference to a particular instance of a class.
Explain the concept of Referential Integrity.
Referential Integrity prevents the following three actions from taking place:
-Adding records to a related table when there is no corresponding record in the primary table.
-Changing values in the primary table that would result in orphan records in a related table.
-Deleting records from a primary table when there are still matching related records.
As an example, consider a table of possible exam grades (A, B, C, etc.) as the primary table and a table of student records as the related table.═ Assume that the table of student records gets its grades from the primary table.
COM+ load balancing
First requirement of a distributed application is scalability. In other words, network traffic and number of clients shouldn't affect performance of an application ( which is impossible in reality though). Load balancing is a mechanism to distribute client calls to multiple servers. COM+ helps using two types of load balancing, called dynamic and static load balancing. In load balancing, client workload is distributed among network servers. COM+ supports load balancing on component level. When a client requests a specific component, it first connects to a load balancing router which contains the information about servers. This router then passes request to a server based on server load and availability. If server is available then client receives an instance of component on the server. The best thing is if a server goes down, COM+ automatically routes client request to another server. Windows 2000 has this service, called clustering service.