.NET Platform
To understand VB.NET, we must first understand the .NET platform.
.NET Framework: a set of approximately 3500 classes.
These classes are divided into namespaces that group similar classes together.
For organization, each class belongs to only one namespace.
Most classes are lumped into a name space called System
System.Data contains classes used for accessing data in a DB
System.XML contains classes used for reading/writing XML
System.Windows.Forms contains classed used for
System.Net contains classes for communicating over the network.
Essentially MS performed a massive re-organization of all the classes, no longer leaving methods or functions without clearly belonging to a specific class. For example, note the difference between Messagebox() in VB6.0 and Messagebox.Show() in VB.NET (to be discussed later).
Visual Studio.NET
Visual Studio.NET is the next version of IDE from MS.
Note: VS.NET does require at least double its system requirements to function feasibly.
Note: VS.NET can be installed on the same machine as VS 6.0. Many have warned against it, yet personal experience has proven otherwise.
VS.NET comes standard with VB.NET, C# (C-Sharp), and VC++.
VS.NET supports more than 20 languages.
All languages compile to .EXE and .DLLs containing Common Intermediate Language (CIL or IL), not machine native code. C++ is the only exception offering an option to compile to machine native code.
These CIL executables then run in the Common Language Runtime (CLR) using a Just-in-Time (JIT) compiler. Note the similarity of .NET to JAVA and JVM.
The JIT compiler dynamically converts the IL to machine native code during execution, and caches the native code for subsequent use.
Advantages of CLR
The JIT allows code to run in a protected environment as managed code. The protected environment polices each application to run in its own memory segment. This prevents a developer from shooting himself in the foot, but it also limits control.
Using a JIT allows the IL code to be hardware independent. As long as the .NET framework is installed, the IL code can be executed.
The CLR also allows for enforcement of code access security.
Verification of type safety.
Access to Metadata (enhanced Type Information)
Support for developer services (profiling, debugging)
Interoperation between managed code, COM objects, pre-existing DLLs (unmanaged code and data).
.NET components can access COM components.
COM components can access .NET components by registering the .Net assembly using the regasm.exe utility.
.NET provides a unified Programming Model
Then: VB for RAD, VC++ for MFC/ATL, ASP for code embedded web pages
Now: Any language to handle any .NET functionality.
.NET Framework supports Web Standards
HTML
XML
XSLT
SOAP
WSDL for Web Services
ILDASM
The IL can be modified using Intermediate Language Dis-assembler (ILDASM). ILDASM is a tool used to properly display IL in a human readable format. A developer can then add remove code as needed for fine tuning. Many developers speak highly of this method for fine tuning code.
Visual Studio.Net vs. Visual Studio 6.0
Syntax of event handling methods:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
In VS.Net CTRL-ESC opens inteli-sense for easy searching of methods
With VB6.0, project files were very simple:
.VBP
.VBW
.CLS / .FRM / .RES
File structure in .NET varies greatly from VB6.0 file structure.
Note: For a tree diagram of the file structure, enter the following in a DOS prompt.
C:\>Tree C:\VBPrograms\WindowsApplication1 /F /A
C:\VBPROGRAMS\WINDOWSAPPLICATION1
| WindowsApplication1.vbproj
| AssemblyInfo.vb
| Form1.vb
| Form1.resx
| WindowsApplication1.vbproj.user
| WindowsApplication1.sln
|
+---bin
| WindowsApplication1.exe
| WindowsApplication1.pdb
|
\---obj
\---Debug
| WindowsApplication1.Form1.resources
| WindowsApplication1.pdb
| WindowsApplication1.exe
|
+---temp
\---TempPE
Both .EXE are executable, pending the user has .NET framework installed.
Use of “Imports System.IO” imports the System.IO. This is similar to the With block code.
Application Deployment
Use XCOPY
Downloading code is also available.
No need to register components.
Can run multiple component versions simultaneously.
Frequently asked Interview Questions and answers
Thursday, July 24, 2008
VB Questions (General)
X as variant and y as integer.
Variant variable size = 22 + Actual data type size.
Instr – integer (Numeric position)
Strcmp - integer ( if both the string are equal they result = 0)
Strcmp (Str1, Str2, Comparetype)
Comparing mode = 0 – Binary Comparing
1 – Textual Comparing
1024
2,048
32,000
255.
Frm, bas, cls, res, vbx, ocx, frx, vbp, exe
When some controls like grid and third party control placed in our application then it will create frx in run time.
Dateadd(), Datediff(), Datepart(), Cdate()
15/4 = 3.75 and 15\4 = 3
ISOperator – Returns Boolean.
2. function and sub procedures (Ask what is the diff. Between them?)
In the general declarations section. To trap undeclared variables.
Scope sharable between projects.
Assigning variable with defined memory space.
Late Binding - Memory size is allotted in later stage.
Ex:- Dim x as object
Early Binding - Memory size is allotted while declaring itself.
New Key word is important.
Ex:- Dim x as New Object
Let – Value is assigned to ActiveX Object from the form.
Let – Value is retried to ActiveX Object from the form.
Control. Restricted data input as well as formatted data output.
State 0 – Source control is being dragged with the range of a target.
1 – Out of the range of a target.
2 – One positon in the target to another.
Field, Form
For each currentcontrol in controls
if typeof currentcontrol is TextBox then
end if
next
Group of control share the same name. Max 32, 767.
VbModaless – 0 (Zero) – We can able to place another window above this form.
Invalid procedure call or argument (Run time error – 5)
Std Global with in the project. Cls Global through out the all project only thing is we want to set the type lib. Class Modules can be Instantiated.
Private – Only for the Specific Module.
Public not creatable – Private & Public
Multi Use - Variable we have to declare.
Single Use – Not possible through dll.
Global Multiuse – Have variable not Required to Declare.
Global Single Use - " Only for exe.
Declare function "
We can have only one MDI form for a project. Multiple Document Interface. This form type is VBModal. We have set the Child property of the forms to True to place forms inside this MDI.
Style availables 1. VbCascade 2. VbTitle Horizontal
64
Inprocess – It will run with in the memory. ( Local Machine).
Out of Process – It will run out of the memory Normally in the server side.
LOB (Large Object Data type).
CLOB (Stores Character Objects).
BLOB ( Store Binary Objects such as Graphic, Video Chips and Sound files).
BFILE(Store file pointers to LOB It may Contain filename for photo’s store on CD_ROM).
Object.Zorder = 1 or 0 Place a Specified mdiform form or control at the font or back of the z-order with n its Graphical Level.
Generic Variable:
Create Object Ex:-Ole-Automation . No need refer the object library.
Specific Variable:
Binding Procedure Early and Late Binding ( Can be Remove from the Memory).
No Properties Available. Only the methods they are SetText, GetText, Setdata(), Getformat(), Clear.
Libraries of procedures external to the application but can be called from the application.
It is tab control to place our controls with in the form in multiple sheets.
Index starts with 1. And to identify
If Tabstrip1.SelectedItem.Index = 1 Then
…..
End if
To list the hierarchial list of the node objects. Such of files and Directories.
Enables an application to exposes objects and methods to other Applications.
No need to reserve memory. No need to write functions. Object library that simplify programming tasks. i.e., No need to Object library. (OLB, TLB).
Create Object - To create an instance of an object.
Get Object – To get the reference to an existing object.
Properties – Public variable of a Class
Method – Public procedure of a class
Similarly to arrays but is 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.
Its Scope will be available through out the life time.
Private cannot be used in front of DIM.
Instance of specific copy of a class with its own settings for the properties defined in that class.
Note: The implicity defined variable is never equal to nothing.
Public , private, Friend
No.
This cannot have user interface. This can be used for the COM creation.
Simple, Dropdown list – We can type and select.
Dropdown Compo – Only Drop Down.
Simple –Single Select , Extended. – Multiple Select.
Predefined, Custom, User Defined.
It is difficult to use database objects declared in a module from within a form.
Vbrunxxx.dll
Yes.
Screen.MousePointer = VBHourGlass/VBNormal.
If(Msgbox("Do you want to delete this Record",VbYesNo)=VbYes)Then End if
Thursday, July 17, 2008
vb questions 11
LockEdits property to False - Optimistic locking - update error
What kind of error is the most expected with optmistic lock? Data changed;
operation stopped
Empty value ByVal 0&, vbNullString
Char ByVal a As Byte
Asciiz String ByVal as String
2 deferent DLLs from 2 vendors - declare private or Use the alias keyword
Adressof MyProc - Correct
In which case is a new object created? set x=new form1
Which Option will not allow to create instances : set Public to FALSE
type library and New Keyword are required for Early Binding.
How to raise an event? First to declare it, use the Event keyword,
then Raise it.
Ambient - change the background color of the control on the container
Create a license package file with a utility from the LPK_TOOL directory.
Run-time license: Application Setup Wizard
Design-time license: Application Setup Wizard
Internet license: LPK_TOOL.EXE, and create a reference to the .LPK file
To navigate between the two ActiveX documents, use the HyperLink object and
its NavigateTo method. Use the GoBack or GoForward methods to go backwards
or forwards through the History list. WebBrowser Object - Use GoHome and
GoSearch
Hyperlink offers a help option on Web.
Data persistence is the ability of a component to store and retrieve data.
The Internet Explorer 3.0 (and higher) and Microsoft Office Binder allows
you to write to a file using the PropertyBag.
Create separate secondary .cab files to reduce download time.
Which two project types can contain an ActiveX Document? ActiveX Dll,
ActiveX Exe.
What project types can have ActiveX documents? - All that can be a container
How to convert an ActiveX.DLL to multithread? - Make it ActiveX. EXE
Advantages of Using ActiveX Documents - Support for the Hyperlink object and
AsyncRead method
Which project template would you select to build an in-process code (ActiveX
Document DLL)?
The AsyncRead method initiates an asynchronous download.
Datatypes to be downloaded: files, pictures, byte arrays
Which 2 actions may disqualify a component for being marked as safe for
scripting? inserts in/reads from registry
When an error occurs in a component, call Err.Raise number.
Err.Source returns the name of the object that generated an Error.
Command1_Click() AND Command2_Click() call each other - Out of Stack Space
error
Which task can you accomplish by packaging in .cab file? register on users
computer
Q: There is a www server application that uses ActiveX controls you
developed. When the application page is browsed with IE it does not show
the ActiveX control. What may be happening?
A1: No Internet download license file on the web server
A2: Options in the Application Setup Wizard were not used correctly
Q: Where do you define conditional compiling variables?
Command line
Project Properties dialog box (under the Make tab)
In code
•Q: Difference between debugging an ActiveX control project and an
in-process component?
A: The component code can run while the client is in Design mode
•Q: When testing a UserControl, you add a standard.exe to your project
group. UserControl in the Toolbox is dimmed. What should you do?
A: Close the UserControl designer and then test again
How to view contents of the Variant?
- Use Debug.print
- Look at the Locals window
Q: What cannot be done when an Internet Control is packaged. (Choose Two)
A: Write to a file
Read from the registry
Q: How can you build ActiveX components for Internet distribution?
A: Use the Application Setup Wizard and pick the appropriate options
------------------------------------------------------------------------
Q: Which function can the Setup Wizard (Enterprise Ed.) of VB 5 perform in
addition to installing your ActiveX EXE project?
A: install your project as an ActiveX shared component
Q: What does locales show in different contexts?
A: In Visual Basic, many functions use the user's system locale, which uses
the Control Panel settings provided by the operating system to automatically
determine the conventions at run time. These functions are called
locale-aware functions.
Q: When should you use public variables instead of property procedures for
read-write properties?
A: The property is a String data type, and there is no constrain on the size
or value of the string.
Q: Where and why to use Friend methods and properties
A: The combination of public to classes in the same project and private to
the external.
Q: You have a Data Control with Bound Controls. You want to provide the
ability to abort changes in the record currently being edited and to
refresh the bound controls. How?
A: Only invoke the UpdateControls method for the Data control.
•Q: A list-box is used as a constituent control. The design window is
closed and the control inserted on a form in another project. The user
then sets the sort property of the control which in turn sets the sort
property of the control. Why does the error occur?
A: Compile the control project ?
Q: How to set properties for the individual Column objects?
A: You must make the DBGrid control UI-active: Select the right mouse
button, and choose Edit. Then use pop-up menu.
Q: How to remove column header?
A: object.ColumnHeaders = False
Q: How to refer a colmun?
A: object.ColIndex [= value]
This property returns the zero-based index of a column within the Columns
collection.
Q: How to check the value of a specific field in the current record?
A: MyString = Data1.Recordset.Fields("Title").Value
Data1.Recordset("PubID") = 43' Set the field values.
Data1.Recordset("PubID") = "12345" ' Change the value.
What are the benefits of Forms collection?
- Allows faster unloading of all forms in the project *
- Faster access
- Standardized mechanism for tracking multiple instances of a form *
- Group forms & drag the group
How to handle resizing of the label in a UserControl?
During design time - Label1_Resize
During run-time – UserControl1_resize
How to refer to the contents of the child of the selected node of a TreeView?
Set nodChild = TreeView1.Nodes(TreeView1.SelectedItem.Index).Child
•
•tvwMyTree.Nodes(10).Children ‘ return the number of children
tvwMyTree.Nodes(10).Parent.Text ‘ return the Text of Parent
What properties can you set while using the Add property for a list view?
•ColumnHeader object.Add(index, key, text, width, alignment, icon)
Which type of Instancing should you use for the class module?
A. private
B. multiUse
C. GlobalMultiUse
D. PublicNotCreatable *
What kind of error is the most expected with optmistic lock? Data changed;
operation stopped
Empty value ByVal 0&, vbNullString
Char ByVal a As Byte
Asciiz String ByVal as String
2 deferent DLLs from 2 vendors - declare private or Use the alias keyword
Adressof MyProc - Correct
In which case is a new object created? set x=new form1
Which Option will not allow to create instances : set Public to FALSE
type library and New Keyword are required for Early Binding.
How to raise an event? First to declare it, use the Event keyword,
then Raise it.
Ambient - change the background color of the control on the container
Create a license package file with a utility from the LPK_TOOL directory.
Run-time license: Application Setup Wizard
Design-time license: Application Setup Wizard
Internet license: LPK_TOOL.EXE, and create a reference to the .LPK file
To navigate between the two ActiveX documents, use the HyperLink object and
its NavigateTo method. Use the GoBack or GoForward methods to go backwards
or forwards through the History list. WebBrowser Object - Use GoHome and
GoSearch
Hyperlink offers a help option on Web.
Data persistence is the ability of a component to store and retrieve data.
The Internet Explorer 3.0 (and higher) and Microsoft Office Binder allows
you to write to a file using the PropertyBag.
Create separate secondary .cab files to reduce download time.
Which two project types can contain an ActiveX Document? ActiveX Dll,
ActiveX Exe.
What project types can have ActiveX documents? - All that can be a container
How to convert an ActiveX.DLL to multithread? - Make it ActiveX. EXE
Advantages of Using ActiveX Documents - Support for the Hyperlink object and
AsyncRead method
Which project template would you select to build an in-process code (ActiveX
Document DLL)?
The AsyncRead method initiates an asynchronous download.
Datatypes to be downloaded: files, pictures, byte arrays
Which 2 actions may disqualify a component for being marked as safe for
scripting? inserts in/reads from registry
When an error occurs in a component, call Err.Raise number.
Err.Source returns the name of the object that generated an Error.
Command1_Click() AND Command2_Click() call each other - Out of Stack Space
error
Which task can you accomplish by packaging in .cab file? register on users
computer
Q: There is a www server application that uses ActiveX controls you
developed. When the application page is browsed with IE it does not show
the ActiveX control. What may be happening?
A1: No Internet download license file on the web server
A2: Options in the Application Setup Wizard were not used correctly
Q: Where do you define conditional compiling variables?
Command line
Project Properties dialog box (under the Make tab)
In code
•Q: Difference between debugging an ActiveX control project and an
in-process component?
A: The component code can run while the client is in Design mode
•Q: When testing a UserControl, you add a standard.exe to your project
group. UserControl in the Toolbox is dimmed. What should you do?
A: Close the UserControl designer and then test again
How to view contents of the Variant?
- Use Debug.print
- Look at the Locals window
Q: What cannot be done when an Internet Control is packaged. (Choose Two)
A: Write to a file
Read from the registry
Q: How can you build ActiveX components for Internet distribution?
A: Use the Application Setup Wizard and pick the appropriate options
------------------------------------------------------------------------
Q: Which function can the Setup Wizard (Enterprise Ed.) of VB 5 perform in
addition to installing your ActiveX EXE project?
A: install your project as an ActiveX shared component
Q: What does locales show in different contexts?
A: In Visual Basic, many functions use the user's system locale, which uses
the Control Panel settings provided by the operating system to automatically
determine the conventions at run time. These functions are called
locale-aware functions.
Q: When should you use public variables instead of property procedures for
read-write properties?
A: The property is a String data type, and there is no constrain on the size
or value of the string.
Q: Where and why to use Friend methods and properties
A: The combination of public to classes in the same project and private to
the external.
Q: You have a Data Control with Bound Controls. You want to provide the
ability to abort changes in the record currently being edited and to
refresh the bound controls. How?
A: Only invoke the UpdateControls method for the Data control.
•Q: A list-box is used as a constituent control. The design window is
closed and the control inserted on a form in another project. The user
then sets the sort property of the control which in turn sets the sort
property of the control. Why does the error occur?
A: Compile the control project ?
Q: How to set properties for the individual Column objects?
A: You must make the DBGrid control UI-active: Select the right mouse
button, and choose Edit. Then use pop-up menu.
Q: How to remove column header?
A: object.ColumnHeaders = False
Q: How to refer a colmun?
A: object.ColIndex [= value]
This property returns the zero-based index of a column within the Columns
collection.
Q: How to check the value of a specific field in the current record?
A: MyString = Data1.Recordset.Fields("Title").Value
Data1.Recordset("PubID") = 43' Set the field values.
Data1.Recordset("PubID") = "12345" ' Change the value.
What are the benefits of Forms collection?
- Allows faster unloading of all forms in the project *
- Faster access
- Standardized mechanism for tracking multiple instances of a form *
- Group forms & drag the group
How to handle resizing of the label in a UserControl?
During design time - Label1_Resize
During run-time – UserControl1_resize
How to refer to the contents of the child of the selected node of a TreeView?
Set nodChild = TreeView1.Nodes(TreeView1.SelectedItem.Index).Child
•
•tvwMyTree.Nodes(10).Children ‘ return the number of children
tvwMyTree.Nodes(10).Parent.Text ‘ return the Text of Parent
What properties can you set while using the Add property for a list view?
•ColumnHeader object.Add(index, key, text, width, alignment, icon)
Which type of Instancing should you use for the class module?
A. private
B. multiUse
C. GlobalMultiUse
D. PublicNotCreatable *
vb questions 10
Q: Why would you want to set the LockEdits property to False?
A: Optimistic locking is in effect for editing. The 2K page containing the
record is not locked until the Update method is executed.
What kind of error is the most expected with optmistic lock? Data changed;
operation stopped
If recordset.lockedits=false, which would be the most like to occur:
A. update error: record locked on by *
B. save error: record locked on by
C. can not read database...
Incorporate dynamic-link libraries (DLLs) into an application.
•Declare and call a DLL routine.
Q: How to declare a DLL with a C Char datatype?
A: ByVal variable As Byte
Declare Function Publicname Lib "libname" [Alias "alias"] [Arguments List]
As Type
Empty value ByVal 0&, vbNullString
Char ByVal a As Byte
Asciiz String ByVal as String
There are 2 deferent DLL from 2 vendors and the DLL have the same name.
What must you do to be able to call both functions?
A. modify function name in one
B. declare public in separate module use the alias keyword to
C. declare private rename one function *
D. Use the alias keyword to rename one function *
We obtained many DLL functions from different vendors. Two functions happen
to have the same name but different purposes. What can we do?
A. Using an alias *
B. Declaring each Private in separate modules *
C. Registering one with another name
D. Modifying the DLL function.
Pass argument contain address of a Vb subroutine named MyProc to a MicWind
HPL
A. Aressof := MyProc
B. Adressof Me.MyProc
C. Adressof MyProc *
D. Adressof (MyProc)
Which code will create a new instance of object named Form1 in Project1?
A. Dim Frmx As Form1
B. Dim Frmx As New Form1 *
C. Set Frmx = Form1
D. Set Frmx = GetObject("Project1.Form1")
How many instances of class1 after running exist after the following code?
Dim a As Class1
Dim b As new Class1
b.MyProperty = 3
Set a = new Class1
A. 0
B. 1
C. 2 *
D. 3
In which case is a new object created? set x=new form1
Which Option will not allow to create instances : set Public to FALSE
Create an Automation server that exposes objects, properties, methods, and
events.
Q: The differences between early binding vs. late binding
•A: Late binding occurs when the compiler does not know about an object
until run time.
Early binding occurs when Visual Basic knows at compile time exactly which
interface will be used with an object variable.
Which two required for Early Binding?
A. Type library *
B. Dual Interface
C. New Keyword *
D. CreateObject Function
For Early Binding
Dim Varnaem as Class
Set varname = CreateObject(ClassName)
Create and use an ActiveX control.
•Declare and raise events.
How to raise an event?
First to declare it, use the Event keyword, then Raise it.
e.g. RaiseEvent ABC (arguments)
How Project Groups can be used when debugging ActiveX controls(lots of Qs).
Ambient & Extender
What is the property of a container that can be used to change the
background color of the control on the container when the background color
of the container changes?
A. Ambient *
B. Extender
C. Appearance
D. Property Pages
How do you create a license package file containing the licensing
information for all controls on a Web page?
A. With the Visual Basic License Manager.
B. With the CODEBASE parameter of an HTML page's
A: Optimistic locking is in effect for editing. The 2K page containing the
record is not locked until the Update method is executed.
What kind of error is the most expected with optmistic lock? Data changed;
operation stopped
If recordset.lockedits=false, which would be the most like to occur:
A. update error: record locked on
B. save error: record locked on
C. can not read database...
Incorporate dynamic-link libraries (DLLs) into an application.
•Declare and call a DLL routine.
Q: How to declare a DLL with a C Char datatype?
A: ByVal variable As Byte
Declare Function Publicname Lib "libname" [Alias "alias"] [Arguments List]
As Type
Empty value ByVal 0&, vbNullString
Char ByVal a As Byte
Asciiz String ByVal as String
There are 2 deferent DLL from 2 vendors and the DLL have the same name.
What must you do to be able to call both functions?
A. modify function name in one
B. declare public in separate module use the alias keyword to
C. declare private rename one function *
D. Use the alias keyword to rename one function *
We obtained many DLL functions from different vendors. Two functions happen
to have the same name but different purposes. What can we do?
A. Using an alias *
B. Declaring each Private in separate modules *
C. Registering one with another name
D. Modifying the DLL function.
Pass argument contain address of a Vb subroutine named MyProc to a MicWind
HPL
A. Aressof := MyProc
B. Adressof Me.MyProc
C. Adressof MyProc *
D. Adressof (MyProc)
Which code will create a new instance of object named Form1 in Project1?
A. Dim Frmx As Form1
B. Dim Frmx As New Form1 *
C. Set Frmx = Form1
D. Set Frmx = GetObject("Project1.Form1")
How many instances of class1 after running exist after the following code?
Dim a As Class1
Dim b As new Class1
b.MyProperty = 3
Set a = new Class1
A. 0
B. 1
C. 2 *
D. 3
In which case is a new object created? set x=new form1
Which Option will not allow to create instances : set Public to FALSE
Create an Automation server that exposes objects, properties, methods, and
events.
Q: The differences between early binding vs. late binding
•A: Late binding occurs when the compiler does not know about an object
until run time.
Early binding occurs when Visual Basic knows at compile time exactly which
interface will be used with an object variable.
Which two required for Early Binding?
A. Type library *
B. Dual Interface
C. New Keyword *
D. CreateObject Function
For Early Binding
Dim Varnaem as Class
Set varname = CreateObject(ClassName)
Create and use an ActiveX control.
•Declare and raise events.
How to raise an event?
First to declare it, use the Event keyword, then Raise it.
e.g. RaiseEvent ABC (arguments)
How Project Groups can be used when debugging ActiveX controls(lots of Qs).
Ambient & Extender
What is the property of a container that can be used to change the
background color of the control on the container when the background color
of the container changes?
A. Ambient *
B. Extender
C. Appearance
D. Property Pages
How do you create a license package file containing the licensing
information for all controls on a Web page?
A. With the Visual Basic License Manager.
B. With the CODEBASE parameter of an HTML page's