.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
vb questions 9
Debug windows
Immediate window
•Automatically opens in Break-mode
•To evaluate any executable statement
•To find and change the value of variables and properties.
•To Query or changethe value of a variable while running an application.
Watch Window
•Add Watch : In Break or Design Mode from the Debug Menu
•You can watch the expression, breaking when the value of the watch
expression is true or breaking when the value changes
•It shows the current watch expression
•The context column indicates the
procedure module(s) in which each watch expression is Evaluated
•You can edit a value
Locals Window
•Automatically displays all of the declared variables in the current
procedure scope and their values.
Calls Stack lists all active procedure calls in the Application that where
started but not completed. You can only display the Call stack window when
the application is in break mode.
q: You have two text boxes Text1 and Text2. the Tab index of text1 is set to
0. what will happen when u set the tab index of text2 to 0?
A: Tab index of text1 is set to 1
Which code fragment is proper use of the Forms collections?
A. Dim form1 As Form *
For each form1 in Forms
MsgBox form1.Caption
Next Form1
B. Dim form1 As Form
For each form1 in Forms
MsgBox Forms.Item(form1).caption
Next Form1
C. Dim form1 As Form
For each form1 in forms
Msgbox form1.remove
Next Form1
D. Dim form1 As Form
For each form1 in Forms
Msgbox form1.add()
Next Form1
Which property is only valid for a collection object?
A. UBOUND
B. LBOUND
C. Count *
D. Index
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
Default firing order of events of a form?
A. Load, Initialize, Resize, Paint
B. Load, Initialize, Paint, Resize
C. Initialize, Load, Resize, Paint *
D. Initialize, Load, Paint, Resize
Start from Main, contain form1, Form1.caption = "blah". Which events will be triggered?
A. load
B. initialize
C. initialize, load *
D. initialize, load, activate
•How do you dynamically load controls : Load object_name
Q: What is the sequence in which the events in the form will trigger
A: Initialize, Load, Resize, Activate, Paint
Dim x As Integer
What event gets fired? Initialize
-----------------------------------------------------------------------
Which control can you place directly on an MDI-Form?
- Image
– Richtext Box
– Picture Box *
- Hscrollbar
- Option Control
- Frame
The PictureBox, Data controls, Timer controls and Menu controls are the only
standard Visual Basic controls that you can place in the internal area of an
MDI form.
Form1 contains a command button control that has code in one of its events.
To cut the control from form1 and than paste the control onto form2.
Where is the event located?
A. It is in the same event of the command button control of form2
B. It is in a different event of the command button control on form2
C. It is deleted when the command button control is cut from form1
D. It is in the General object procedures of form1 *
ProgressBar with visible property set true. To display progress of a lengthy
operation in you application. Which property will you set?
A. value *
B. width
C. max
D. index
DragOver Form1 to change color of label1
A. Target.color = true
B. Source.color = true *
C. DragLabel.color = true
D. DragControl.color = true
Form1 allow dragging Label1. Which line code use in DragOver event of Form1
to change bg color of Label1 to red?
A. Target.BC = vbRed
B. Source= vbRed *
C. DragLabel= vbRed
D. DragControl= vbRed
Which OleDragOver event parameter indicates dragging onto or away from a
target object?
A. effect
B. state *
C. index
D. data
Copy picture from picturebox control to other app which prop use?
A. oledropMode of the picturebox control
B. oledropMode of the form containing pictureBox control
C. oledragMode of the picturebox control *
D. oledragMode of the form containing pictureBox control
You want to trap a function key in a textbox. - Use the Keydown event.
A textbox to allow only numeric entries. - Use the Keypress event.
Form1 and Form2 place code in the Terminate event of Form1. Which code to
add in order to cause the Terminate event of Form1 to occur from Form2?
A. F1.Click unload F1
B. F1.hide F1.close
C. unload F1 set F1=nothing *
D. unload F1 end
You have a Label1 on an UserControl1, what event for Label1 to be stretched
during design time?
A. UserControl_Initialize
B. UserControl_Resize
C. Label1_Initialize
D. Label1_Resize *
Q: You have a Label Control in USERCONTROL. If the user resizes the
usercontrol during run-time, in which event will u handle the resizing of the
label (so as to view the Label control)?
A: USERCONTROL_RESIZE
How do you find out if F2 is being pressed?
A. Click
B. Validate
C. KeyDown *
D. KeyPressed
Your form contains a command button control named Command1. The index
property of command1 is set to 0. You want to load a second instance of the
command button that has its index property set to
1. Which line should you use?
A. load command1.1
B. load command1(1) *
C. load command1.index = 1
D. load command1.index (1)
Combine menu controls of object1 with the existing menu on form1
A. form1.NegotiateMenu = true *
B. form1.NegotiatePosition = true
C. object1.NegotiateMenu = true
D. object1.NegotiatePosition = true
Using the NegotiateMenus property, you determine if the menu bar of a form
will share (or negotiate) space with the menus of an active object on the
form.If you uncheck the Visible property for a menu item, the menu items
below will move up to fill the empty space.
How to attribute Access Keys to menus? &Save
What can you do with a dynamic menu?
A. You can add function keys to it
B. You can add pop-up menus to it *
C. You can deleted it after creating it *
D. You can create it from the Menu Editor
How to allow menu items to be added at runtime?
A. redimension the menu control array
B. use the add method *//dynamic menu
C. use the load statement
D. set up the menu with blank spaces initially and change at runtime
Q: How will you allow users to edit your control at design time?
A: Set the EditAtDesignTime property of your UserControl object to True.
Q: How do you make your UserControl Object Invisible at run-time?
A: Set the InvisibleAtRuntime property of the UserControl object to True.
Menu control: Which property can only be changed during design time?
- visible
- caption
- checked
- shortcut *
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
Display Icon for each item in the hierarchy of the website?
A. Outline
B. Listbox
C. Listview
D. Treeview *
A TreeView control displays a hierarchical list of Node objects, each of
which consists of a label and an optional bitmap. A TreeView is typically
used to display the headings in a document, the entries in an index, the
files and directories on a disk, or any other kind of information that might
usefully be displayed as a hierarchy.
You are writing code for a Drag and Drop operation. You want to set the
DropHighLight property to highlight the target TreeView control element?
A. HitTest *
B. Drag
C. TextHeight
D. StartlabelEdit
The DropHighlight property is typically used in combination with the HitTest
method in drag-and-drop operations for TreeView and ListView Controls.
You use the add method of the TreeView control, which parameter can you use
to control the creation of a child node?
A. Key
B. Text
C. Relative *
D. Relationship
How to add the column to a ListView?
MyListView.ColumnHeaders.Add ,, "MyNewCol"
A unique feature of the Report view is ColumnHeader objects.
The ListView control contains a collection of ColumnHeader objects in the
ColumnHeaders collection.
What properties can you set while using the Add property for a list view?
•ColumnHeader object.Add(index, key, text, width, alignment, icon)
•Provide controls with images by using the ImageList control.
For which control does the ImageList control act as a central repository of
images? ListImage
An ImageList control contains a collection of ListImage objects, each of
Which can be referred to by its index or key.
Dim pnlX As Panel
Set pnlX = StatusBar1.Panels.Add() ' Add a new Panel object.
Set pnlX.Picture = ImageList1.ListImages(1).Picture ' Setting Picture must
use set.
TreeView1.ImageList = ImageList1 ' Specify ImageList
TreeView1.Nodes(3).Image = 1 ' Use Index property of ImageList1.
TreeView1.Nodes(3).Image = "image 1" ' or Use the Key property "image 1."
What Property will you use to access BUTTONS of TOOLBAR?
Key & Index
Which StatusBar property allows the display of common data such as date, time
etc?
A. Text
B. Style *
C. Object
D. SimpleText
Statusbar SB1 Second panel set key property to panel2
Which display the message "blah" in second panel
A. SB1.(2)Text = ..
B. SB1.panels(2).text = .. *
C. SB1.Panels.(panel2).text = ..
D. SB1.PanelItems("panel2").text = ..
If you intend to add a user control or any ActiveX control to your form,
you must either add the control to the Toolbox, or add its License key to
the Licenses collection.
•Option Explicit
Private WithEvents extCtl As VBControlExtender
Private Sub Form_Load()
Licenses.Add "project1.WeeksCtl", "xydsfasfjewfe"
Set extCtl = Form1.Controls.Add("project1.WeeksCtl", "ctl1")
extCtl.Visible = True ' The control is invisible by default.
End Sub
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.
Correctly use of ParamArray keyword?
- At the end of the (……. As….. , ……As ……, Param Array )
- And not in combination with the Optional keyword
You have a variable x. You use the Watch window to see the contents of x. At one time the value of x=100 and the next step is says. It has occurred when the 1 process was finished and the second process was started. How was x declared?
A. Local to 1st procedure *
B. Local to 2end procedure
C. Public in a procedure
D. Public in the General declaration section of the form
Procedure in class module visible to the project not to other application
A. private function Report1 as bool
B. private function Report1() as bool
C. public function Report1() as bool
D. friend function Report1() as bool *
A variable is declared as Public in a form. From where can the Variable be
referenced?
A. Only from other procedures in the same form.
B. Only from forms in the same project
C. From anywhere in the same project *
D. From modules in other project
Which elements are supported in the definition of property procedures
- optional argument *
- address of operator
- alias keyword
- paramArray keyword *
You want a procedure to be visible only to objects in the current project.
You want that this procedure should be accessible by external clients.
How will you declare the Procedure?
A. Private
B. Friend
C. Public
D. Static
How can you create a read-only property Private and a write-only property
Public. Which of the following are true?
•A. Private Property Get Name() As String *
Name = txtname.text
End Property
Public Property Let Name(ByVal NewName as String)
TxtName.text = NewName
PropertyChanged "Name"
End Property
B. Public Property Set Name() As String
•Name = txtname.text
End Property
Private Property Let Name(ByVal NewName as String)
TxtName.text = NewName
PropertyChanged "Name"
End Property
C. Public Property Let Name() As String
Name = txtname.text
End Property
Public Property Set Name(ByVal NewName as String)
TxtName.text = NewName
PropertyChanged "Name"
End Property
You have to indicate the property changes for an object.
Which of the following is best suited for the above scenario?
A. Property Get
B. property Let
C. Public Sub() *
D. Public Function()
How can you create a read-only property for a class?
A. Define a Property Get procedure and define a Property Let procedure with
no arguments.
B. Define a Property Get procedure and a Property Let procedure.
C. Define a Property Get procedure without a Property Set or Property Let
procedure. *
D. Define a Property Set or Property Let procedure without a Property Get
procedure.
How can you create a read-only property?
A. Omit the Property Let procedure *
B. Omit the Property Set procedure
C. Set its ReadOnly property to true
D. Use the Private keyword when declaring the procedure
What are the two restrictions on how the Implements statement can be used?
A. It requires a reference to a type Library *
B. It can be used only once in an application
C. It cannot be used in standard module *
D. It cannot be placed in the general declaration section of a module
Q: What is the purpose of the Implements keyword?
•A: The Implements keyword is used to create a secondary interface.
For instance, if your application has a reference to a type library that
describes the IGrowth interface, you could create a secondary interface in a
class module using "Implements IGrowth".
You want to create an instance of an ActiveX component that can Asynchronously
signal projects that use it. What should you create? (Choose two)
A. an event
B. an object callback *
C. the Addressof Operator *
D. the Implements statement
Which type of Instancing should you use for the class module?
A. private
B. multiUse
C. GlobalMultiUse *
D. PublicNotCreatable
Sink the events of class1. How define a variable MyVar
A. Dim MyVar as object
B. Dim MyVar as Variant
C. Dim MyVar as new Class1
D. Dim WithEvents my as class1 *
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.
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?
Only invoke the UpdateControls method for the Data control.
UpdateRecord Updates database (recordset) with data from bound controls.
UpdateControls Updates database (recordset) changes to bound controls.
Refresh Creates a new recordset based on data control properties.
Update Update recordset with data from bound controls or through code.
Your application has just deleted a record from a dynaset-type Recordset.
What is the current record? The delete record.
Which properties of the data control can be changed at run time?
Recordset, databasename, recordsource
•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 ?
U have Form,a FRAME & ListBox inside frame. If u set SORT property of Listbox
at design time, what will happen.
•box.List(index)
box.RemoveItem index
box.AddItem item[, index]
DBGrid is a collection of Column objects.
the DBGrid control depends on two other objects:
•The Recordset object of the data control
•The Columns collection of the DBGrid itself
Each cell of a DBGrid control can hold text values, but not linked or
embedded objects.
•Add a data control to a new form, and set its DatabaseName and RecordSource
properties to the database and table you want to display.
•Add a DBGrid control to the form, and set its DataSource property to the
data control you just created. The DBGrid column headers set automatically
from a Data control's Recordset object.
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
The data in the currently selected row can be accessed using the Bookmark
property, which provides access to the underlying Recordset object’s current
record.
You have 2 tables based upon which reports are to be generated by making use
of a common Field. The existing Table structure and Report definitions should
not be changed. Which of the following is most appropriate.
A. create a new table and use Filter
B. Create a new table and use Sort
C. create a new Dynaset using Filter*
Which type of recordset you will use to populate country names into a
ListBox? Forward-only Which recordset you will use to find a record in
multi-user environment? Dynaset
To locate specific records you can use the Find methods with dynaset- and
snapshot-type Recordset objects, and the Seek method with table-type
The Seek method works only with table type recordsets, because Visual Basic
uses the table’s current index
•table.Seek comparison, key1, key2 ...
Immediate window
•Automatically opens in Break-mode
•To evaluate any executable statement
•To find and change the value of variables and properties.
•To Query or changethe value of a variable while running an application.
Watch Window
•Add Watch : In Break or Design Mode from the Debug Menu
•You can watch the expression, breaking when the value of the watch
expression is true or breaking when the value changes
•It shows the current watch expression
•The context column indicates the
procedure module(s) in which each watch expression is Evaluated
•You can edit a value
Locals Window
•Automatically displays all of the declared variables in the current
procedure scope and their values.
Calls Stack lists all active procedure calls in the Application that where
started but not completed. You can only display the Call stack window when
the application is in break mode.
q: You have two text boxes Text1 and Text2. the Tab index of text1 is set to
0. what will happen when u set the tab index of text2 to 0?
A: Tab index of text1 is set to 1
Which code fragment is proper use of the Forms collections?
A. Dim form1 As Form *
For each form1 in Forms
MsgBox form1.Caption
Next Form1
B. Dim form1 As Form
For each form1 in Forms
MsgBox Forms.Item(form1).caption
Next Form1
C. Dim form1 As Form
For each form1 in forms
Msgbox form1.remove
Next Form1
D. Dim form1 As Form
For each form1 in Forms
Msgbox form1.add()
Next Form1
Which property is only valid for a collection object?
A. UBOUND
B. LBOUND
C. Count *
D. Index
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
Default firing order of events of a form?
A. Load, Initialize, Resize, Paint
B. Load, Initialize, Paint, Resize
C. Initialize, Load, Resize, Paint *
D. Initialize, Load, Paint, Resize
Start from Main, contain form1, Form1.caption = "blah". Which events will be triggered?
A. load
B. initialize
C. initialize, load *
D. initialize, load, activate
•How do you dynamically load controls : Load object_name
Q: What is the sequence in which the events in the form will trigger
A: Initialize, Load, Resize, Activate, Paint
Dim x As Integer
What event gets fired? Initialize
-----------------------------------------------------------------------
Which control can you place directly on an MDI-Form?
- Image
– Richtext Box
– Picture Box *
- Hscrollbar
- Option Control
- Frame
The PictureBox, Data controls, Timer controls and Menu controls are the only
standard Visual Basic controls that you can place in the internal area of an
MDI form.
Form1 contains a command button control that has code in one of its events.
To cut the control from form1 and than paste the control onto form2.
Where is the event located?
A. It is in the same event of the command button control of form2
B. It is in a different event of the command button control on form2
C. It is deleted when the command button control is cut from form1
D. It is in the General object procedures of form1 *
ProgressBar with visible property set true. To display progress of a lengthy
operation in you application. Which property will you set?
A. value *
B. width
C. max
D. index
DragOver Form1 to change color of label1
A. Target.color = true
B. Source.color = true *
C. DragLabel.color = true
D. DragControl.color = true
Form1 allow dragging Label1. Which line code use in DragOver event of Form1
to change bg color of Label1 to red?
A. Target.BC = vbRed
B. Source= vbRed *
C. DragLabel= vbRed
D. DragControl= vbRed
Which OleDragOver event parameter indicates dragging onto or away from a
target object?
A. effect
B. state *
C. index
D. data
Copy picture from picturebox control to other app which prop use?
A. oledropMode of the picturebox control
B. oledropMode of the form containing pictureBox control
C. oledragMode of the picturebox control *
D. oledragMode of the form containing pictureBox control
You want to trap a function key in a textbox. - Use the Keydown event.
A textbox to allow only numeric entries. - Use the Keypress event.
Form1 and Form2 place code in the Terminate event of Form1. Which code to
add in order to cause the Terminate event of Form1 to occur from Form2?
A. F1.Click unload F1
B. F1.hide F1.close
C. unload F1 set F1=nothing *
D. unload F1 end
You have a Label1 on an UserControl1, what event for Label1 to be stretched
during design time?
A. UserControl_Initialize
B. UserControl_Resize
C. Label1_Initialize
D. Label1_Resize *
Q: You have a Label Control in USERCONTROL. If the user resizes the
usercontrol during run-time, in which event will u handle the resizing of the
label (so as to view the Label control)?
A: USERCONTROL_RESIZE
How do you find out if F2 is being pressed?
A. Click
B. Validate
C. KeyDown *
D. KeyPressed
Your form contains a command button control named Command1. The index
property of command1 is set to 0. You want to load a second instance of the
command button that has its index property set to
1. Which line should you use?
A. load command1.1
B. load command1(1) *
C. load command1.index = 1
D. load command1.index (1)
Combine menu controls of object1 with the existing menu on form1
A. form1.NegotiateMenu = true *
B. form1.NegotiatePosition = true
C. object1.NegotiateMenu = true
D. object1.NegotiatePosition = true
Using the NegotiateMenus property, you determine if the menu bar of a form
will share (or negotiate) space with the menus of an active object on the
form.If you uncheck the Visible property for a menu item, the menu items
below will move up to fill the empty space.
How to attribute Access Keys to menus? &Save
What can you do with a dynamic menu?
A. You can add function keys to it
B. You can add pop-up menus to it *
C. You can deleted it after creating it *
D. You can create it from the Menu Editor
How to allow menu items to be added at runtime?
A. redimension the menu control array
B. use the add method *//dynamic menu
C. use the load statement
D. set up the menu with blank spaces initially and change at runtime
Q: How will you allow users to edit your control at design time?
A: Set the EditAtDesignTime property of your UserControl object to True.
Q: How do you make your UserControl Object Invisible at run-time?
A: Set the InvisibleAtRuntime property of the UserControl object to True.
Menu control: Which property can only be changed during design time?
- visible
- caption
- checked
- shortcut *
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
Display Icon for each item in the hierarchy of the website?
A. Outline
B. Listbox
C. Listview
D. Treeview *
A TreeView control displays a hierarchical list of Node objects, each of
which consists of a label and an optional bitmap. A TreeView is typically
used to display the headings in a document, the entries in an index, the
files and directories on a disk, or any other kind of information that might
usefully be displayed as a hierarchy.
You are writing code for a Drag and Drop operation. You want to set the
DropHighLight property to highlight the target TreeView control element?
A. HitTest *
B. Drag
C. TextHeight
D. StartlabelEdit
The DropHighlight property is typically used in combination with the HitTest
method in drag-and-drop operations for TreeView and ListView Controls.
You use the add method of the TreeView control, which parameter can you use
to control the creation of a child node?
A. Key
B. Text
C. Relative *
D. Relationship
How to add the column to a ListView?
MyListView.ColumnHeaders.Add ,, "MyNewCol"
A unique feature of the Report view is ColumnHeader objects.
The ListView control contains a collection of ColumnHeader objects in the
ColumnHeaders collection.
What properties can you set while using the Add property for a list view?
•ColumnHeader object.Add(index, key, text, width, alignment, icon)
•Provide controls with images by using the ImageList control.
For which control does the ImageList control act as a central repository of
images? ListImage
An ImageList control contains a collection of ListImage objects, each of
Which can be referred to by its index or key.
Dim pnlX As Panel
Set pnlX = StatusBar1.Panels.Add() ' Add a new Panel object.
Set pnlX.Picture = ImageList1.ListImages(1).Picture ' Setting Picture must
use set.
TreeView1.ImageList = ImageList1 ' Specify ImageList
TreeView1.Nodes(3).Image = 1 ' Use Index property of ImageList1.
TreeView1.Nodes(3).Image = "image 1" ' or Use the Key property "image 1."
What Property will you use to access BUTTONS of TOOLBAR?
Key & Index
Which StatusBar property allows the display of common data such as date, time
etc?
A. Text
B. Style *
C. Object
D. SimpleText
Statusbar SB1 Second panel set key property to panel2
Which display the message "blah" in second panel
A. SB1.(2)Text = ..
B. SB1.panels(2).text = .. *
C. SB1.Panels.(panel2).text = ..
D. SB1.PanelItems("panel2").text = ..
If you intend to add a user control or any ActiveX control to your form,
you must either add the control to the Toolbox, or add its License key to
the Licenses collection.
•Option Explicit
Private WithEvents extCtl As VBControlExtender
Private Sub Form_Load()
Licenses.Add "project1.WeeksCtl", "xydsfasfjewfe"
Set extCtl = Form1.Controls.Add("project1.WeeksCtl", "ctl1")
extCtl.Visible = True ' The control is invisible by default.
End Sub
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.
Correctly use of ParamArray keyword?
- At the end of the (……. As….. , ……As ……, Param Array )
- And not in combination with the Optional keyword
You have a variable x. You use the Watch window to see the contents of x. At one time the value of x=100 and the next step is says. It has occurred when the 1 process was finished and the second process was started. How was x declared?
A. Local to 1st procedure *
B. Local to 2end procedure
C. Public in a procedure
D. Public in the General declaration section of the form
Procedure in class module visible to the project not to other application
A. private function Report1 as bool
B. private function Report1() as bool
C. public function Report1() as bool
D. friend function Report1() as bool *
A variable is declared as Public in a form. From where can the Variable be
referenced?
A. Only from other procedures in the same form.
B. Only from forms in the same project
C. From anywhere in the same project *
D. From modules in other project
Which elements are supported in the definition of property procedures
- optional argument *
- address of operator
- alias keyword
- paramArray keyword *
You want a procedure to be visible only to objects in the current project.
You want that this procedure should be accessible by external clients.
How will you declare the Procedure?
A. Private
B. Friend
C. Public
D. Static
How can you create a read-only property Private and a write-only property
Public. Which of the following are true?
•A. Private Property Get Name() As String *
Name = txtname.text
End Property
Public Property Let Name(ByVal NewName as String)
TxtName.text = NewName
PropertyChanged "Name"
End Property
B. Public Property Set Name() As String
•Name = txtname.text
End Property
Private Property Let Name(ByVal NewName as String)
TxtName.text = NewName
PropertyChanged "Name"
End Property
C. Public Property Let Name() As String
Name = txtname.text
End Property
Public Property Set Name(ByVal NewName as String)
TxtName.text = NewName
PropertyChanged "Name"
End Property
You have to indicate the property changes for an object.
Which of the following is best suited for the above scenario?
A. Property Get
B. property Let
C. Public Sub() *
D. Public Function()
How can you create a read-only property for a class?
A. Define a Property Get procedure and define a Property Let procedure with
no arguments.
B. Define a Property Get procedure and a Property Let procedure.
C. Define a Property Get procedure without a Property Set or Property Let
procedure. *
D. Define a Property Set or Property Let procedure without a Property Get
procedure.
How can you create a read-only property?
A. Omit the Property Let procedure *
B. Omit the Property Set procedure
C. Set its ReadOnly property to true
D. Use the Private keyword when declaring the procedure
What are the two restrictions on how the Implements statement can be used?
A. It requires a reference to a type Library *
B. It can be used only once in an application
C. It cannot be used in standard module *
D. It cannot be placed in the general declaration section of a module
Q: What is the purpose of the Implements keyword?
•A: The Implements keyword is used to create a secondary interface.
For instance, if your application has a reference to a type library that
describes the IGrowth interface, you could create a secondary interface in a
class module using "Implements IGrowth".
You want to create an instance of an ActiveX component that can Asynchronously
signal projects that use it. What should you create? (Choose two)
A. an event
B. an object callback *
C. the Addressof Operator *
D. the Implements statement
Which type of Instancing should you use for the class module?
A. private
B. multiUse
C. GlobalMultiUse *
D. PublicNotCreatable
Sink the events of class1. How define a variable MyVar
A. Dim MyVar as object
B. Dim MyVar as Variant
C. Dim MyVar as new Class1
D. Dim WithEvents my as class1 *
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.
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?
Only invoke the UpdateControls method for the Data control.
UpdateRecord Updates database (recordset) with data from bound controls.
UpdateControls Updates database (recordset) changes to bound controls.
Refresh Creates a new recordset based on data control properties.
Update Update recordset with data from bound controls or through code.
Your application has just deleted a record from a dynaset-type Recordset.
What is the current record? The delete record.
Which properties of the data control can be changed at run time?
Recordset, databasename, recordsource
•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 ?
U have Form,a FRAME & ListBox inside frame. If u set SORT property of Listbox
at design time, what will happen.
•box.List(index)
box.RemoveItem index
box.AddItem item[, index]
DBGrid is a collection of Column objects.
the DBGrid control depends on two other objects:
•The Recordset object of the data control
•The Columns collection of the DBGrid itself
Each cell of a DBGrid control can hold text values, but not linked or
embedded objects.
•Add a data control to a new form, and set its DatabaseName and RecordSource
properties to the database and table you want to display.
•Add a DBGrid control to the form, and set its DataSource property to the
data control you just created. The DBGrid column headers set automatically
from a Data control's Recordset object.
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
The data in the currently selected row can be accessed using the Bookmark
property, which provides access to the underlying Recordset object’s current
record.
You have 2 tables based upon which reports are to be generated by making use
of a common Field. The existing Table structure and Report definitions should
not be changed. Which of the following is most appropriate.
A. create a new table and use Filter
B. Create a new table and use Sort
C. create a new Dynaset using Filter*
Which type of recordset you will use to populate country names into a
ListBox? Forward-only Which recordset you will use to find a record in
multi-user environment? Dynaset
To locate specific records you can use the Find methods with dynaset- and
snapshot-type Recordset objects, and the Seek method with table-type
The Seek method works only with table type recordsets, because Visual Basic
uses the table’s current index
•table.Seek comparison, key1, key2 ...
vb questions 8
Class Module
Property procedures
Property Get - Returns the value of a property.
Property Let - Sets the value of a property. – Let x = 3
Property Set - Sets the value of an object property. – Set objThing = New
Thing
•Property procedures are public by default. •The Property Get declaration
must use arguments with the same name and data type and less one number as
the arguments in the Property Let procedure. •
Property procedures
Property Get - Returns the value of a property.
Property Let - Sets the value of a property. – Let x = 3
Property Set - Sets the value of an object property. – Set objThing = New
Thing
•Property procedures are public by default. •The Property Get declaration
must use arguments with the same name and data type and less one number as
the arguments in the Property Let procedure. •
vb questions 7
1) If your user wants to uninstall the application you developed, which
method will you use to make it easy for him
a) Use setup wizard (*)
b) Customize the Setup.exe
2) If you have a progress bar. what propertry would you use to show its
status.
a) Index
b) Value(*)
3) What error do you get if the following code is executed
Private Command1_Click()
Command2.Value = TRUE
End sub
Private Command2_Click()
Command1.Value = TRUE
End sub
Ans : Stack Overflow error
4) How do you create a Public read only and Private Read/Write. The options
were something like
a) Public Get Name()
Name = stname
End
Private Let Name( stname as string)
stname = Name
End
b) Public Get Name()
Public Let Name()
c) Private Get Name()
Private Set Name()
d) Public Get Name()
Private Set Name()
5) When a user browses a web page which has a control you developed and the
browser displays a warning. what will you ask your user to do.
Ans : Ask the user to set his browsers security level to none or zero.
6) What event would you use if a user presses F2
7) A ListBox is in a frame. The HelpContextId of the ListBox is set to 0.
When the user presses F1 and the ListBox has focus What happens.
8) If you have a number of controls to distribute over the Web. How would you
decrease the download time for the user.
9) When the following code executes. What will the user see
Public Sub MyTest()
On Error GoTo ErrHandler
Dim X as Integer
MyProc(X)
MsgBox "XXX"
Errhandler:
MsgBox "YYY"
End Sub
Public Sub MyProc()
On Error GoTo MyprocErr
X = X / 0
MyprocErr:
MsgBox "ZZZ"
End Sub
a) "XXX" Only
b) "ZZZ" Only
c) "XXX", "ZZZ" and "YYY" Only
d) "XXX" and "ZZZ" Only
10) When you are testing your user control. you add a standard exe to your
project group. But the user control in your tool bar is dommed. What should
you do?
11) Which code would you use to create a instance of Form1
a) Dim Frmx as Form1
b) Dim Frmx as New Form1
c) Dim Form1 as Form
d) Set Frmx = GetObject("Project1.Form1")
12) How would you display text in a status bar which has its 2nd panel key
as"Panel2"
a) Statusbar1.Panel2.Text = "Printing ..."
b) Statusbar1.Panel(2).Text = "Printing ..."
c) StatusBar1.Panel("Panel2") = "Printing ..."
1 . Use Regsvr32.exe to install Active X DLL, EXE, OCX.
To install ActiveX.dll: Regsvr32 dllname
To install Activex.Exe: AX_exename /Regserver
------------------------------------------------------------------------
2 Test Activex.EXE (out-of-process) component
2 instances of VB
Test Activex.DLL (in-process) component
Add Standard.EXE and use 1 instance of VB
Debug ActiveX control project
Run Active x control while the client is in design mode
------------------------------------------------------------------------
1)When testing a User Control, you add a standard.exe to your project group.
User control in the Toolbox is dimmed. What should you do? Close the User
Control designer and then test again.
------------------------------------------------------------------------
4 Advantages of using Watch window:
-----------------------------------------------------------------------
5 What can be viewed in the local window?
All the variables in the procedure scope
------------------------------------------------------------------------
6 Immediate Window:
view, add, change and declare variables and see the result being returned.
------------------------------------------------------------------------
7 What Call stack shows?
------------------------------------------------------------------------
8 Why the context property in Immediate window is useful?
-----------------------------------------------------------------------
9 Autoredraw = False only affects line, pset, cicle created at run-time, not
design time. Use Refresh instead of Autoredraw to save system resources.
------------------------------------------------------------------------
10 DropHighlight used for drag-and-drop operation on a TreeView and
DropHightlight goes with HitTest in an OLE dragDrop operation
------------------------------------------------------------------------
11 ActiveXDocument.Hyperlink.Helpfile
Use Hyperlink object on ActiveX Document, needs a hyperlink-aware container,
e.g. IE4
------------------------------------------------------------------------
12 Property procedures e.g. Public Property Get ABC (ByVal... ByRef...
Optional...ParamArry intNum) Those in parantgese are optional argument types.
------------------------------------------------------------------------
13 How to declare DLL functions:
------------------------------------------------------------------------
14 AsynRead method is used to do asynchronous download. Datatypes to be
downloaded: files, pictures, byte arrays
------------------------------------------------------------------------
15 Implements as keyword used in a class module - used for Automation
Implements ABCDE
'ABCDE is a secondary interface created based on the type library's abstract
interface. How to do it? Set reference to the type library
What should be the syntax using Implements keyword?
-----------------------------------------------------------------------
16 Disadvantage of using Implements keyword:
Can only be used in Standard module;
Need to declare all the public variables, etc.
------------------------------------------------------------------------
17 LockEdits = False
Optimistic locking, the record (2k page) be locked when you use the method
update
LockEdits = True
Pessimistic locking, the record (2k page) will be locked when you use the
method Edit
Get familiar with different situations using LockEdits and understand it.
------------------------------------------------------------------------
18 Create private property - read only
Private Property Get ABC (no Property Let nor Property Set)
Create public property - write only
Public Property Let
PropertyChanged "BBB"
------------------------------------------------------------------------
19 What can be placed on MDI form?
Picturebox control (not image control)
timer control, Data control, Menu control
------------------------------------------------------------------------
20 Public variable declared in a form
Scope : entire application, make reference to form name if necessary
------------------------------------------------------------------------
21 Data control's default Recordset type: dynaset-type recordset
------------------------------------------------------------------------
22 HelpContextId = 0 is the default. If the HelpContextId of a botton control is set to zero, the container, i.e. frame or form's HelpContextId will be used. If there are no HelpContextID specified in the container, then NO HELP.
------------------------------------------------------------------------
23 CommonDialog1.ShowHelp
This requires : CommonDialog1.HelpFile to be set
CommonDialog1.HelpCommand to be set
maybe a reference to CommonDialog1.HelpKey
------------------------------------------------------------------------
24 Change the BackColor of UserControl's label1
Use Ambient Properties
------------------------------------------------------------------------
25 In a DragOver event, how to change the backcolor of the label which is
being dragged over the target?
Source.BackColor = vbRed
------------------------------------------------------------------------
26 Active X files for internet distribution:
Inf file equivalent to Setup.lst file
Inf file contains references to files, support files
.cab file (contains ActiveX.dll or .exe, inf file that is equ. to Setup.lst
file with links to support files, sec. cab files, space for digital signing)
.vbd file
.htm file
------------------------------------------------------------------------
27 How to reduce the time for downloading on Internet an Active X componet?
Create separate secondary .cab files.
Users may already have these secondary .cab files on the system or the
secondary .cab files can be downloaded from Microsoft's web site.
------------------------------------------------------------------------
28 StatusBar panels - is 1-based?
Get familiar with how to show a string in, for instance, the 2nd panel of a
statusbar.
------------------------------------------------------------------------
29 Toolbar
Properties: Button.Key and Button.Index
------------------------------------------------------------------------
30 What event will be fired when you move from one record to another in a
recordset?
Update
------------------------------------------------------------------------
31 How to Pass Null to DLL
ByVal as String
pass vbNullString
------------------------------------------------------------------------
32 Conditional Compilation
Can use literal statements except the IS operator
------------------------------------------------------------------------
33 Where do you define conditional compiling variables?
Command line
Project Properties dialog box (under the Make tab)
In code
------------------------------------------------------------------------
34 Dim x As Integer
What event gets fired? Initialize
-----------------------------------------------------------------------
35 How to convert an ActiveX.DLL to multithread?
Make it ActiveX. EXE
------------------------------------------------------------------------
36 How to raise an event"
first to declare it, use the Event keyword, then Raise it. e.g. RaiseEvent
ABC (arguments)
------------------------------------------------------------------------
37 How to add a control to a web page? By scripting
------------------------------------------------------------------------
38 Press F2, what event is fired? KeyDown
------------------------------------------------------------------------
39 What property of ProgressBar to show status? Value
------------------------------------------------------------------------
40 Under what situation will you have this error message "Out of Stack
space"?
------------------------------------------------------------------------
41 With TreeView control, use Add method to add a child node.
It goes with "Relationship" not "Relative", know the keyword tvwFirst,
vwLast, etc.
------------------------------------------------------------------------
42 Hyperlink object, GoForward and GoBack
Webrowser, GoHome and GoSearch
------------------------------------------------------------------------
43 How to pass Null pointer to a C function that is expecting a character
type?
VB byte type?
------------------------------------------------------------------------
44 GlobalMultiuse
For ActiveX.DLL and ActiveX.EXE
Enable you to use the properties as if the component is an intrinsic
controls, there's no need to declare the variables, one instance of the
class created for multiple client use.
------------------------------------------------------------------------
45 DBGrid's column property is 0-based
------------------------------------------------------------------------
46 Dynaset and filter property
------------------------------------------------------------------------
47 Setup a standard.exe, VB5DEP.INI is the dependency file
------------------------------------------------------------------------
48 An error occurs in a component that you wrote, how to notify client:
Err.Raise number
------------------------------------------------------------------------
49 How to create a license package for ActiveX control licensing
Use LPK_Tool.exe
------------------------------------------------------------------------
50 How to dynamically create or remove controls?
Set up control arrays at design time, at run time, use Load and Unload
control statements.
e.g. Load ABC(index#)
e.g. Load mnuFile(2) for dynamic menu
------------------------------------------------------------------------
51 When can you add watch statements?
At design time or break mode.
------------------------------------------------------------------------
52 What property to set if you want both menus (from the object and from the
container) shown ?
NegotiageMenus on the container
------------------------------------------------------------------------
53 How do you implement a sink event of a class using a variable?
Visual Basic 6.0 Study Guide
Program Structure
A typical application consists of one or more modules: a form module for
each form in the application, optional standard modules for shared code,
and optional class modules. Each module contains one or more procedures that
contain the code: event procedures, Sub or Function procedures, and Property
procedures.
Startup Form can be set in Project Properties. Sub Main() can only be in a
standard module. To display a splash screen, use a Sub Main procedure as
startup object and use the Show method to display the form:
Private Sub Main()
frmSplash.Show ' Show the splash screen.
… ' Add startup procedures here.
frmMain.Show ' Show the main form and unload the splash screen.
Unload frmSplash
End Sub
Three ways to end an application:
Single Form
Multiple Forms
Private Sub cmdQuit_Click ()
Unload Me
End Sub
Private Sub Form_Unload (Cancel As Integer)
Dim i as integer
' Loop through the forms collection and unload
' each form.
For i = Forms.Count – 1 to 0 Step - 1
Unload Forms(i)
Next
End Sub
End statement
Ends an application immediately: no code after the End statement is executed,
and no further events occur. Object references will be freed, but if you
have defined your own classes, Visual Basic will not execute the Terminate
events of objects created from your classes.
Life Cycle of Visual Basic Forms
1.Created, but not loaded. (Initialize) This is the only state all forms
pass through. 2.Loaded, but not shown. (Load) Create Controls. Assign hWin,
hDC. 3.Shown.
(Resize) - Occurs when an object is first displayed or when the window state
of an object changes. (For example, a form is maximized, minimized, or
restored.)
(Activate) - Occurs when an object becomes the active window.
(Paint) - Occurs when part or all of an object is exposed after being moved
or enlarged, or after a window that was covering the object has been
moved. 4.Memory and resources completely reclaimed.
(QueryUnload) – Prompt user for saving.
(Unload) - Remove from Forms Collection. Module-level variables may still
exist.
The only way to release all memory and resources is to unload the form and
then set all references to Nothing. Set Form1 = Nothing
(Terminate)
Executing the End statement unloads all forms and sets all object variables
in your program to Nothing. However, this is a very abrupt way to terminate
program. None of the forms will get their QueryUnload, Unload, or Terminate
events, and objects created will not get their Terminate events. 5.Unloaded
and unreferenced while a control is still referenced.
Object Concept
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, and can be viewed with object browsers.
To use an object, you must keep a reference to it in an object variable. The type of binding determines the speed with which an object’s methods are accessed using the object variable. An object variable can be late bound (slowest), or early bound. Early-bound variables can be DispID bound or vtable bound (fastest).
A set of properties and methods is called an interface. The default interface of a Visual Basic object is a dual interface which supports all three forms of binding. If an object variable is strongly typed (that is, Dim … As classname), it will use the fastest form of binding.
Using Code Editor
In a form module, the list includes a general section, a section for the form itself, and a section for each control contained on the form. For a class module, the list includes a general section and a class section; for a standard module only a general section is shown.
Class modules list only the event procedures for the class itself — Initialize and Terminate. Standard modules don't list any event procedures, because a standard module doesn't support events.
Breaking and combining statements
Text1.Text = "Hello" : Red = 255 : Text1.BackColor = _
Red
Declaring Variables
Dim variablename [As type]
••Declaring a variable in the Declarations section of a form, standard, or class module, rather than within a procedure, makes the variable available to all the procedures in the module. •Declaring a variable using the Public keyword makes it available throughout your application. •Declaring a local variable using the Static keyword preserves its value even when a procedure ends.
Implicit Declaration - You don't have to declare a variable before using it.
Explicit Declaration - Using "Option Explicit"
•
•The Option Explicit statement operates on a per-module basis; it must be placed in the Declarations section of every form, standard, and class module for which you want Visual Basic to enforce explicit variable declarations. If you select Require Variable Declaration, Visual Basic inserts Option Explicit in all subsequent form, standard, and class modules, but does not add it to existing code. You must manually add Option Explicit to any existing modules within a proje<
Scoping Variables
Depending on how it is declared, a variable is scoped as either a procedure-level (local) or module-level variable.
Scope
Private
Public
Procedure-level
( Dim, Static )
Variables are private to the procedure in which they appear.
Not applicable. You cannot declare public variables within a procedure.
Module-level
( In Declaration Section )
Variables are private to the module in which they appear.
Variables are available to all modules.
Values in local variables declared with Static exist the entire time your application is running while variables declared with Dim exist only as long as the procedure is executing. At the module level, there is no difference between Private and Dim. You can't declare public variables within a procedure.
Static Function or Sub will make all the local variables in the procedure static regardless their declaration inside.
Constant has the same scope rule as variable does.
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.
Because Friend members aren't part of an object's public interface, they can't be accessed late bound — that is, through variables declared As Object. To use Friend members, you must declare variables with early binding — that is, As classname.
The Friend keyword can only be used in class modules. However, Friend procedures can be accessed by procedures in any module of a project. A Friend procedure doesn't appear in the type library of its parent class, nor can a Friend procedure be late bound.
Friend makes the procedure visible throughout the project, but not to a controller of an instance of the object.
Name Conflicting and Resolving
The forms and controls can have the same name as a restricted keyword. To resolve conflict, using:
•
•MyForm.Loop.Visible = True ' Qualified with the form name.
[Loop].Visible = True ' Square brackets also work.
Within the form module, local variables with the same names as controls on the form shadow the controls.
To resolve conflict, using: a reference or keyword Me
Private Sub Form_Click ()
Dim Text1 ' Assume there is also a control on the form called Text1.
Text1 = "Variable" ' Variable shadows control.
Text1.Top = 0 ' This causes an error!
Me.Text1.Top = 0 ' Must qualify with Me to get
End Sub
A variable in the module cannot have the same name as any procedures or types defined in the module. It can, however, have the same name as public procedures, types, or variables defined in other modules. In this case, when the variable is accessed from another module, it must be qualified with the module name.
Constant Name is referenced in case of collision depends on which object library has the higher priority.
To resolve conflict, using: [libname.][modulename.]constname
Data types
Dim EmpName As String * 50
Fixed-length strings in standard modules can be declared as Public or Private. In forms and class modules, fixed-length strings must be declared Private. You can assign a string to a numeric variable if the string represents a numeric value.
The default value of Boolean variable is False.
Object variable is actual a 32-bit pointer referring to an object within an application or within some other application. Using the Set statement to refer to any actual object recognized by the application.
•
•Dim objDb As Object ‘or Database
Set objDb = OpenDatabase("c:\Vb5\Biblio.mdb")
By default, if you don't supply a data type, the variable is given the Variant data type. A Variant variable is capable of storing all system-defined types of data. You don't have to convert between these types of data if you assign them to a Variant variable; Visual Basic automatically performs any necessary conversion. For example:
Dim SomeValue ' Variant by default.
SomeValue = "17" ' "17" (a two-character string)
SomeValue = SomeValue - 15 ' numeric value 2
SomeValue = "U" & SomeValue ' "U2" (a two- character string)
••If you perform arithmetic operations on a Variant, the Variant must contain something that is a number. •If you are concatenating strings, use the & operator instead of the + operator. •Variants can contain three special values: Empty, Null, and Error.
•Empty is used to see if a value has ever been assigned to a created variable.
•Null is commonly used in database applications to indicate unknown or missing data. Null will propagate through expressions involving Variant variables. Variables are not set to Null unless you explicitly assign Null to them.
•Error is a special value used to indicate that an error condition has occurred in a procedure. Error values are created by converting real numbers to error values using the CVErr function.
Note: A variant always takes up 16 bytes, no matter what you store in it. Objects, strings, and arrays are not physically stored in the Variant; in these cases, four bytes of the Variant are used to hold either an object reference, or a pointer to the string or array. The actual data are stored elsewhere.
ParamArray
•It can only be used in as the final argument in an argument list. •It represents an optional array of variant Data type •It cannot be used with ByVal, ByRef or Optional keywords •It is used in these contexts:
••Declare Statement •Function Statement •Property Get Statement •Property Let Statement •Sub Statement
You create a user-defined type with the Type statement, which must be placed in the Declarations section of a module.
User-defined types are always passed by reference.
•
•Public Type udtAccount
Number As Long
Type As Byte
CustomerName As String
Balance As Double
End Type
Enumeration data type
Public Enum WorkDays
Saturday
Sunday = 0
Monday
Tuesday
Wednesday
Thursday
Friday
Invalid = -1
End Enum
Arrays
Dim Sums(20) As Double ' 21 elements. The default lower bound is 0.
Dim Counters(1 To 15) As Integer
Dim MultiD(3, 1 To 10, 1 To 15) 'multi-dimension
Dim DynArray() 'dynamic array
ReDim DynArray(4 to 12) 'is an executable statement, can appear only in a procedure
ReDim Preserve DynArray(UBound(DynArray) + 1) 'reserve the old values
•
•
•
•
•
•ReDim Preserve Matrix(UBound(Matrix, 1) + 1, 10) 'Error: Only the upper bound of the last 'dimension in a multidimensional array can be changed
You may want to use a collection instead of array if you're working with a small, dynamic set of items.
A Collection object stores each item in a Variant. A Collection object has three methods (add, item, remove) and one property (count). Collection are not polymorphic. Forms collection contains all of the currently loaded Visual Basic forms in the program. Collection class contains anything that can be stored in a Variant. Thus the Collection object can contain an object or an integer, but not a user-defined type.
control array
A group of controls that share a common name, type, and event procedures. Each control in an array has a unique index number that can be used to determine which control recognizes an event.
There are three ways to create a control array at design time:
Assign the same name to more than one control.
Copy an existing control and then paste it onto the form.
Set the control's Index property to a value that is not Null.
Note: You must create menu control arrays in the Menu Editor.
At run time, use:
Load Object(index%)
Unload Object(index%)
•The control must be created at design-time to be ready loaded at run-time. You can use the Unload statement to remove any control created with Load. However, you cannot use Unload to remove controls created at design time.
Procedure
Declaration Statement
[Public | Private] Declare Sub name Lib "libname" [Alias "aliasname"] [([arglist])]
[Public | Private] Declare Function name Lib "libname" [Alias "aliasname"] [([arglist])] [As type]
Sub procedures are by default Public in all modules, which means they can be called from anywhere in the application. There are two types of Sub procedures, general procedures and event procedures.
Sub ButtonManager(Button As Control) ‘general procedure, usually in bas. module
Private Sub cmdUp_Click() ‘event procedure
There are two ways to call a Sub procedure:
' Both of these statements call a Sub named MyProc.
Call MyProc (FirstArgument, SecondArgument)
MyProc FirstArgument, SecondArgument
Function has return value.
There are three ways to call a Function procedure:
X = functionForX
Call function(x) ‘will throw away return value
Function x ‘will throw away return value
Argument
Sub ListText(ByVal x As String, Optional y As _Integer = 12345)
Using the ParamArray keyword allows you to specify that a procedure will accept an arbitrary number of arguments.
ParamArray is used only as the last argument in arglist to indicate that the final argument is an Optional array of Variant elements. The ParamArray keyword allows you to provide an arbitrary number of arguments. The ParamArray keyword can't be used with ByVal, ByRef, or Optional.
Named argument for many built-in functions, statements, and methods:
Function ListText(strName As String, Optional strAddress As String)
List1.AddItem strName
List2.AddItem strAddress
End Sub
Private Sub Command1_Click()
ListText strAddress:="12345", strName:="Your Name" ‘in reverse order
End Sub
Control Structure
For Each element In group
statements
Next element
This is helpful if you don't know how many elements are in a collection.
••For collections, element can only be a Variant variable, a generic Object variable, or an object listed in the Object Browser. •For arrays, element can only be a Variant variable. •You cannot use For Each...Next with an array of user-defined types because a Variant cannot contain a user-defined type.
•Exit For … Exit Do … Exit Sub … Exit Function ‘exit control structure
Object
Properties that you can set and get at run time are called read-write properties. Properties you can only read at run time are called read-only properties.
There are some common cases in Visual Basic where one object contains other objects. Forms, Controls, Printers.
Three ways to refer a collection member:
Controls("List1")
Controls!List1
Controls(3)
You can use the Container property to change an object's container within a form.
The following controls can contain other controls:
••Frame control •Picture box control •Toolbar control (Professional and Enterprise editions only)
Menu
Each menu you create can include up to five levels of submenus. Ctrl+E: Menu Editor
A menu control array is a set of menu items on the same menu that share the same name and event procedures. Each menu control array element is identified by a unique index. Use a menu control array to:
••Create a new menu item at run time when it must be a member of a control array. For example, a menu control array may be used to store a list of recently opened files. •Simplify code, because common blocks of code can be used for all menu items.
Elements of a menu control array must be contiguous in the menu control list box and must be at the same level of indentation. When you're creating menu control arrays, be sure to include any separator bars that appear on the menu.
What is the restrictions of dynamically created menu items?
Cannot have shortcut keys
Cannot be used for a WindowList
Must be menu control array elements
Pop-up menu
Private Sub Form_MouseUp (Button As Integer, Shift As _
Integer, X As Single, Y As Single)
If Button = 2 Then ' Check if right mouse button was clicked.
PopupMenu mnuFile ' Display the File menu as a pop-up menu.
End If
End Sub
•Any code following a call to the PopupMenu method is not run until the user selects an item in the menu or cancels the menu. Only one pop-up menu can be displayed at a time. While a pop-up menu is displayed, calls to the PopupMenu method are ignored. Calls to the PopupMenu method are also ignored whenever a menu control is active.
Menu and toolbar negotiation will occur only for insertable objects that support in-place activation.
1.The NegotiateMenus property does not apply to MDI Forms. 2.The NegotiateToolbars property applies only to MDI forms.
There are three ways to set conditional compilation constants:
•Project Properties dialog box - Public to all modules in the project •Command line - Public to all modules in the project
•
•vb6.exe /make MyProj.vbp /d conFrenchVersion=–1:conANSI=0
••#Const statement in code - Private to the module in which they are declared.
•
•
•
•- Only conditional compiler constants and literals can be used in expression.
Conditional compilation can use literal statements except for IS operator.
method will you use to make it easy for him
a) Use setup wizard (*)
b) Customize the Setup.exe
2) If you have a progress bar. what propertry would you use to show its
status.
a) Index
b) Value(*)
3) What error do you get if the following code is executed
Private Command1_Click()
Command2.Value = TRUE
End sub
Private Command2_Click()
Command1.Value = TRUE
End sub
Ans : Stack Overflow error
4) How do you create a Public read only and Private Read/Write. The options
were something like
a) Public Get Name()
Name = stname
End
Private Let Name( stname as string)
stname = Name
End
b) Public Get Name()
Public Let Name()
c) Private Get Name()
Private Set Name()
d) Public Get Name()
Private Set Name()
5) When a user browses a web page which has a control you developed and the
browser displays a warning. what will you ask your user to do.
Ans : Ask the user to set his browsers security level to none or zero.
6) What event would you use if a user presses F2
7) A ListBox is in a frame. The HelpContextId of the ListBox is set to 0.
When the user presses F1 and the ListBox has focus What happens.
8) If you have a number of controls to distribute over the Web. How would you
decrease the download time for the user.
9) When the following code executes. What will the user see
Public Sub MyTest()
On Error GoTo ErrHandler
Dim X as Integer
MyProc(X)
MsgBox "XXX"
Errhandler:
MsgBox "YYY"
End Sub
Public Sub MyProc()
On Error GoTo MyprocErr
X = X / 0
MyprocErr:
MsgBox "ZZZ"
End Sub
a) "XXX" Only
b) "ZZZ" Only
c) "XXX", "ZZZ" and "YYY" Only
d) "XXX" and "ZZZ" Only
10) When you are testing your user control. you add a standard exe to your
project group. But the user control in your tool bar is dommed. What should
you do?
11) Which code would you use to create a instance of Form1
a) Dim Frmx as Form1
b) Dim Frmx as New Form1
c) Dim Form1 as Form
d) Set Frmx = GetObject("Project1.Form1")
12) How would you display text in a status bar which has its 2nd panel key
as"Panel2"
a) Statusbar1.Panel2.Text = "Printing ..."
b) Statusbar1.Panel(2).Text = "Printing ..."
c) StatusBar1.Panel("Panel2") = "Printing ..."
1 . Use Regsvr32.exe to install Active X DLL, EXE, OCX.
To install ActiveX.dll: Regsvr32 dllname
To install Activex.Exe: AX_exename /Regserver
------------------------------------------------------------------------
2 Test Activex.EXE (out-of-process) component
2 instances of VB
Test Activex.DLL (in-process) component
Add Standard.EXE and use 1 instance of VB
Debug ActiveX control project
Run Active x control while the client is in design mode
------------------------------------------------------------------------
1)When testing a User Control, you add a standard.exe to your project group.
User control in the Toolbox is dimmed. What should you do? Close the User
Control designer and then test again.
------------------------------------------------------------------------
4 Advantages of using Watch window:
-----------------------------------------------------------------------
5 What can be viewed in the local window?
All the variables in the procedure scope
------------------------------------------------------------------------
6 Immediate Window:
view, add, change and declare variables and see the result being returned.
------------------------------------------------------------------------
7 What Call stack shows?
------------------------------------------------------------------------
8 Why the context property in Immediate window is useful?
-----------------------------------------------------------------------
9 Autoredraw = False only affects line, pset, cicle created at run-time, not
design time. Use Refresh instead of Autoredraw to save system resources.
------------------------------------------------------------------------
10 DropHighlight used for drag-and-drop operation on a TreeView and
DropHightlight goes with HitTest in an OLE dragDrop operation
------------------------------------------------------------------------
11 ActiveXDocument.Hyperlink.Helpfile
Use Hyperlink object on ActiveX Document, needs a hyperlink-aware container,
e.g. IE4
------------------------------------------------------------------------
12 Property procedures e.g. Public Property Get ABC (ByVal... ByRef...
Optional...ParamArry intNum) Those in parantgese are optional argument types.
------------------------------------------------------------------------
13 How to declare DLL functions:
------------------------------------------------------------------------
14 AsynRead method is used to do asynchronous download. Datatypes to be
downloaded: files, pictures, byte arrays
------------------------------------------------------------------------
15 Implements as keyword used in a class module - used for Automation
Implements ABCDE
'ABCDE is a secondary interface created based on the type library's abstract
interface. How to do it? Set reference to the type library
What should be the syntax using Implements keyword?
-----------------------------------------------------------------------
16 Disadvantage of using Implements keyword:
Can only be used in Standard module;
Need to declare all the public variables, etc.
------------------------------------------------------------------------
17 LockEdits = False
Optimistic locking, the record (2k page) be locked when you use the method
update
LockEdits = True
Pessimistic locking, the record (2k page) will be locked when you use the
method Edit
Get familiar with different situations using LockEdits and understand it.
------------------------------------------------------------------------
18 Create private property - read only
Private Property Get ABC (no Property Let nor Property Set)
Create public property - write only
Public Property Let
PropertyChanged "BBB"
------------------------------------------------------------------------
19 What can be placed on MDI form?
Picturebox control (not image control)
timer control, Data control, Menu control
------------------------------------------------------------------------
20 Public variable declared in a form
Scope : entire application, make reference to form name if necessary
------------------------------------------------------------------------
21 Data control's default Recordset type: dynaset-type recordset
------------------------------------------------------------------------
22 HelpContextId = 0 is the default. If the HelpContextId of a botton control is set to zero, the container, i.e. frame or form's HelpContextId will be used. If there are no HelpContextID specified in the container, then NO HELP.
------------------------------------------------------------------------
23 CommonDialog1.ShowHelp
This requires : CommonDialog1.HelpFile to be set
CommonDialog1.HelpCommand to be set
maybe a reference to CommonDialog1.HelpKey
------------------------------------------------------------------------
24 Change the BackColor of UserControl's label1
Use Ambient Properties
------------------------------------------------------------------------
25 In a DragOver event, how to change the backcolor of the label which is
being dragged over the target?
Source.BackColor = vbRed
------------------------------------------------------------------------
26 Active X files for internet distribution:
Inf file equivalent to Setup.lst file
Inf file contains references to files, support files
.cab file (contains ActiveX.dll or .exe, inf file that is equ. to Setup.lst
file with links to support files, sec. cab files, space for digital signing)
.vbd file
.htm file
------------------------------------------------------------------------
27 How to reduce the time for downloading on Internet an Active X componet?
Create separate secondary .cab files.
Users may already have these secondary .cab files on the system or the
secondary .cab files can be downloaded from Microsoft's web site.
------------------------------------------------------------------------
28 StatusBar panels - is 1-based?
Get familiar with how to show a string in, for instance, the 2nd panel of a
statusbar.
------------------------------------------------------------------------
29 Toolbar
Properties: Button.Key and Button.Index
------------------------------------------------------------------------
30 What event will be fired when you move from one record to another in a
recordset?
Update
------------------------------------------------------------------------
31 How to Pass Null to DLL
ByVal as String
pass vbNullString
------------------------------------------------------------------------
32 Conditional Compilation
Can use literal statements except the IS operator
------------------------------------------------------------------------
33 Where do you define conditional compiling variables?
Command line
Project Properties dialog box (under the Make tab)
In code
------------------------------------------------------------------------
34 Dim x As Integer
What event gets fired? Initialize
-----------------------------------------------------------------------
35 How to convert an ActiveX.DLL to multithread?
Make it ActiveX. EXE
------------------------------------------------------------------------
36 How to raise an event"
first to declare it, use the Event keyword, then Raise it. e.g. RaiseEvent
ABC (arguments)
------------------------------------------------------------------------
37 How to add a control to a web page? By scripting
------------------------------------------------------------------------
38 Press F2, what event is fired? KeyDown
------------------------------------------------------------------------
39 What property of ProgressBar to show status? Value
------------------------------------------------------------------------
40 Under what situation will you have this error message "Out of Stack
space"?
------------------------------------------------------------------------
41 With TreeView control, use Add method to add a child node.
It goes with "Relationship" not "Relative", know the keyword tvwFirst,
vwLast, etc.
------------------------------------------------------------------------
42 Hyperlink object, GoForward and GoBack
Webrowser, GoHome and GoSearch
------------------------------------------------------------------------
43 How to pass Null pointer to a C function that is expecting a character
type?
VB byte type?
------------------------------------------------------------------------
44 GlobalMultiuse
For ActiveX.DLL and ActiveX.EXE
Enable you to use the properties as if the component is an intrinsic
controls, there's no need to declare the variables, one instance of the
class created for multiple client use.
------------------------------------------------------------------------
45 DBGrid's column property is 0-based
------------------------------------------------------------------------
46 Dynaset and filter property
------------------------------------------------------------------------
47 Setup a standard.exe, VB5DEP.INI is the dependency file
------------------------------------------------------------------------
48 An error occurs in a component that you wrote, how to notify client:
Err.Raise number
------------------------------------------------------------------------
49 How to create a license package for ActiveX control licensing
Use LPK_Tool.exe
------------------------------------------------------------------------
50 How to dynamically create or remove controls?
Set up control arrays at design time, at run time, use Load and Unload
control statements.
e.g. Load ABC(index#)
e.g. Load mnuFile(2) for dynamic menu
------------------------------------------------------------------------
51 When can you add watch statements?
At design time or break mode.
------------------------------------------------------------------------
52 What property to set if you want both menus (from the object and from the
container) shown ?
NegotiageMenus on the container
------------------------------------------------------------------------
53 How do you implement a sink event of a class using a variable?
Visual Basic 6.0 Study Guide
Program Structure
A typical application consists of one or more modules: a form module for
each form in the application, optional standard modules for shared code,
and optional class modules. Each module contains one or more procedures that
contain the code: event procedures, Sub or Function procedures, and Property
procedures.
Startup Form can be set in Project Properties. Sub Main() can only be in a
standard module. To display a splash screen, use a Sub Main procedure as
startup object and use the Show method to display the form:
Private Sub Main()
frmSplash.Show ' Show the splash screen.
… ' Add startup procedures here.
frmMain.Show ' Show the main form and unload the splash screen.
Unload frmSplash
End Sub
Three ways to end an application:
Single Form
Multiple Forms
Private Sub cmdQuit_Click ()
Unload Me
End Sub
Private Sub Form_Unload (Cancel As Integer)
Dim i as integer
' Loop through the forms collection and unload
' each form.
For i = Forms.Count – 1 to 0 Step - 1
Unload Forms(i)
Next
End Sub
End statement
Ends an application immediately: no code after the End statement is executed,
and no further events occur. Object references will be freed, but if you
have defined your own classes, Visual Basic will not execute the Terminate
events of objects created from your classes.
Life Cycle of Visual Basic Forms
1.Created, but not loaded. (Initialize) This is the only state all forms
pass through. 2.Loaded, but not shown. (Load) Create Controls. Assign hWin,
hDC. 3.Shown.
(Resize) - Occurs when an object is first displayed or when the window state
of an object changes. (For example, a form is maximized, minimized, or
restored.)
(Activate) - Occurs when an object becomes the active window.
(Paint) - Occurs when part or all of an object is exposed after being moved
or enlarged, or after a window that was covering the object has been
moved. 4.Memory and resources completely reclaimed.
(QueryUnload) – Prompt user for saving.
(Unload) - Remove from Forms Collection. Module-level variables may still
exist.
The only way to release all memory and resources is to unload the form and
then set all references to Nothing. Set Form1 = Nothing
(Terminate)
Executing the End statement unloads all forms and sets all object variables
in your program to Nothing. However, this is a very abrupt way to terminate
program. None of the forms will get their QueryUnload, Unload, or Terminate
events, and objects created will not get their Terminate events. 5.Unloaded
and unreferenced while a control is still referenced.
Object Concept
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, and can be viewed with object browsers.
To use an object, you must keep a reference to it in an object variable. The type of binding determines the speed with which an object’s methods are accessed using the object variable. An object variable can be late bound (slowest), or early bound. Early-bound variables can be DispID bound or vtable bound (fastest).
A set of properties and methods is called an interface. The default interface of a Visual Basic object is a dual interface which supports all three forms of binding. If an object variable is strongly typed (that is, Dim … As classname), it will use the fastest form of binding.
Using Code Editor
In a form module, the list includes a general section, a section for the form itself, and a section for each control contained on the form. For a class module, the list includes a general section and a class section; for a standard module only a general section is shown.
Class modules list only the event procedures for the class itself — Initialize and Terminate. Standard modules don't list any event procedures, because a standard module doesn't support events.
Breaking and combining statements
Text1.Text = "Hello" : Red = 255 : Text1.BackColor = _
Red
Declaring Variables
Dim variablename [As type]
••Declaring a variable in the Declarations section of a form, standard, or class module, rather than within a procedure, makes the variable available to all the procedures in the module. •Declaring a variable using the Public keyword makes it available throughout your application. •Declaring a local variable using the Static keyword preserves its value even when a procedure ends.
Implicit Declaration - You don't have to declare a variable before using it.
Explicit Declaration - Using "Option Explicit"
•
•The Option Explicit statement operates on a per-module basis; it must be placed in the Declarations section of every form, standard, and class module for which you want Visual Basic to enforce explicit variable declarations. If you select Require Variable Declaration, Visual Basic inserts Option Explicit in all subsequent form, standard, and class modules, but does not add it to existing code. You must manually add Option Explicit to any existing modules within a proje<
Scoping Variables
Depending on how it is declared, a variable is scoped as either a procedure-level (local) or module-level variable.
Scope
Private
Public
Procedure-level
( Dim, Static )
Variables are private to the procedure in which they appear.
Not applicable. You cannot declare public variables within a procedure.
Module-level
( In Declaration Section )
Variables are private to the module in which they appear.
Variables are available to all modules.
Values in local variables declared with Static exist the entire time your application is running while variables declared with Dim exist only as long as the procedure is executing. At the module level, there is no difference between Private and Dim. You can't declare public variables within a procedure.
Static Function or Sub will make all the local variables in the procedure static regardless their declaration inside.
Constant has the same scope rule as variable does.
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.
Because Friend members aren't part of an object's public interface, they can't be accessed late bound — that is, through variables declared As Object. To use Friend members, you must declare variables with early binding — that is, As classname.
The Friend keyword can only be used in class modules. However, Friend procedures can be accessed by procedures in any module of a project. A Friend procedure doesn't appear in the type library of its parent class, nor can a Friend procedure be late bound.
Friend makes the procedure visible throughout the project, but not to a controller of an instance of the object.
Name Conflicting and Resolving
The forms and controls can have the same name as a restricted keyword. To resolve conflict, using:
•
•MyForm.Loop.Visible = True ' Qualified with the form name.
[Loop].Visible = True ' Square brackets also work.
Within the form module, local variables with the same names as controls on the form shadow the controls.
To resolve conflict, using: a reference or keyword Me
Private Sub Form_Click ()
Dim Text1 ' Assume there is also a control on the form called Text1.
Text1 = "Variable" ' Variable shadows control.
Text1.Top = 0 ' This causes an error!
Me.Text1.Top = 0 ' Must qualify with Me to get
End Sub
A variable in the module cannot have the same name as any procedures or types defined in the module. It can, however, have the same name as public procedures, types, or variables defined in other modules. In this case, when the variable is accessed from another module, it must be qualified with the module name.
Constant Name is referenced in case of collision depends on which object library has the higher priority.
To resolve conflict, using: [libname.][modulename.]constname
Data types
Dim EmpName As String * 50
Fixed-length strings in standard modules can be declared as Public or Private. In forms and class modules, fixed-length strings must be declared Private. You can assign a string to a numeric variable if the string represents a numeric value.
The default value of Boolean variable is False.
Object variable is actual a 32-bit pointer referring to an object within an application or within some other application. Using the Set statement to refer to any actual object recognized by the application.
•
•Dim objDb As Object ‘or Database
Set objDb = OpenDatabase("c:\Vb5\Biblio.mdb")
By default, if you don't supply a data type, the variable is given the Variant data type. A Variant variable is capable of storing all system-defined types of data. You don't have to convert between these types of data if you assign them to a Variant variable; Visual Basic automatically performs any necessary conversion. For example:
Dim SomeValue ' Variant by default.
SomeValue = "17" ' "17" (a two-character string)
SomeValue = SomeValue - 15 ' numeric value 2
SomeValue = "U" & SomeValue ' "U2" (a two- character string)
••If you perform arithmetic operations on a Variant, the Variant must contain something that is a number. •If you are concatenating strings, use the & operator instead of the + operator. •Variants can contain three special values: Empty, Null, and Error.
•Empty is used to see if a value has ever been assigned to a created variable.
•Null is commonly used in database applications to indicate unknown or missing data. Null will propagate through expressions involving Variant variables. Variables are not set to Null unless you explicitly assign Null to them.
•Error is a special value used to indicate that an error condition has occurred in a procedure. Error values are created by converting real numbers to error values using the CVErr function.
Note: A variant always takes up 16 bytes, no matter what you store in it. Objects, strings, and arrays are not physically stored in the Variant; in these cases, four bytes of the Variant are used to hold either an object reference, or a pointer to the string or array. The actual data are stored elsewhere.
ParamArray
•It can only be used in as the final argument in an argument list. •It represents an optional array of variant Data type •It cannot be used with ByVal, ByRef or Optional keywords •It is used in these contexts:
••Declare Statement •Function Statement •Property Get Statement •Property Let Statement •Sub Statement
You create a user-defined type with the Type statement, which must be placed in the Declarations section of a module.
User-defined types are always passed by reference.
•
•Public Type udtAccount
Number As Long
Type As Byte
CustomerName As String
Balance As Double
End Type
Enumeration data type
Public Enum WorkDays
Saturday
Sunday = 0
Monday
Tuesday
Wednesday
Thursday
Friday
Invalid = -1
End Enum
Arrays
Dim Sums(20) As Double ' 21 elements. The default lower bound is 0.
Dim Counters(1 To 15) As Integer
Dim MultiD(3, 1 To 10, 1 To 15) 'multi-dimension
Dim DynArray() 'dynamic array
ReDim DynArray(4 to 12) 'is an executable statement, can appear only in a procedure
ReDim Preserve DynArray(UBound(DynArray) + 1) 'reserve the old values
•
•
•
•
•
•ReDim Preserve Matrix(UBound(Matrix, 1) + 1, 10) 'Error: Only the upper bound of the last 'dimension in a multidimensional array can be changed
You may want to use a collection instead of array if you're working with a small, dynamic set of items.
A Collection object stores each item in a Variant. A Collection object has three methods (add, item, remove) and one property (count). Collection are not polymorphic. Forms collection contains all of the currently loaded Visual Basic forms in the program. Collection class contains anything that can be stored in a Variant. Thus the Collection object can contain an object or an integer, but not a user-defined type.
control array
A group of controls that share a common name, type, and event procedures. Each control in an array has a unique index number that can be used to determine which control recognizes an event.
There are three ways to create a control array at design time:
Assign the same name to more than one control.
Copy an existing control and then paste it onto the form.
Set the control's Index property to a value that is not Null.
Note: You must create menu control arrays in the Menu Editor.
At run time, use:
Load Object(index%)
Unload Object(index%)
•The control must be created at design-time to be ready loaded at run-time. You can use the Unload statement to remove any control created with Load. However, you cannot use Unload to remove controls created at design time.
Procedure
Declaration Statement
[Public | Private] Declare Sub name Lib "libname" [Alias "aliasname"] [([arglist])]
[Public | Private] Declare Function name Lib "libname" [Alias "aliasname"] [([arglist])] [As type]
Sub procedures are by default Public in all modules, which means they can be called from anywhere in the application. There are two types of Sub procedures, general procedures and event procedures.
Sub ButtonManager(Button As Control) ‘general procedure, usually in bas. module
Private Sub cmdUp_Click() ‘event procedure
There are two ways to call a Sub procedure:
' Both of these statements call a Sub named MyProc.
Call MyProc (FirstArgument, SecondArgument)
MyProc FirstArgument, SecondArgument
Function has return value.
There are three ways to call a Function procedure:
X = functionForX
Call function(x) ‘will throw away return value
Function x ‘will throw away return value
Argument
Sub ListText(ByVal x As String, Optional y As _Integer = 12345)
Using the ParamArray keyword allows you to specify that a procedure will accept an arbitrary number of arguments.
ParamArray is used only as the last argument in arglist to indicate that the final argument is an Optional array of Variant elements. The ParamArray keyword allows you to provide an arbitrary number of arguments. The ParamArray keyword can't be used with ByVal, ByRef, or Optional.
Named argument for many built-in functions, statements, and methods:
Function ListText(strName As String, Optional strAddress As String)
List1.AddItem strName
List2.AddItem strAddress
End Sub
Private Sub Command1_Click()
ListText strAddress:="12345", strName:="Your Name" ‘in reverse order
End Sub
Control Structure
For Each element In group
statements
Next element
This is helpful if you don't know how many elements are in a collection.
••For collections, element can only be a Variant variable, a generic Object variable, or an object listed in the Object Browser. •For arrays, element can only be a Variant variable. •You cannot use For Each...Next with an array of user-defined types because a Variant cannot contain a user-defined type.
•Exit For … Exit Do … Exit Sub … Exit Function ‘exit control structure
Object
Properties that you can set and get at run time are called read-write properties. Properties you can only read at run time are called read-only properties.
There are some common cases in Visual Basic where one object contains other objects. Forms, Controls, Printers.
Three ways to refer a collection member:
Controls("List1")
Controls!List1
Controls(3)
You can use the Container property to change an object's container within a form.
The following controls can contain other controls:
••Frame control •Picture box control •Toolbar control (Professional and Enterprise editions only)
Menu
Each menu you create can include up to five levels of submenus. Ctrl+E: Menu Editor
A menu control array is a set of menu items on the same menu that share the same name and event procedures. Each menu control array element is identified by a unique index. Use a menu control array to:
••Create a new menu item at run time when it must be a member of a control array. For example, a menu control array may be used to store a list of recently opened files. •Simplify code, because common blocks of code can be used for all menu items.
Elements of a menu control array must be contiguous in the menu control list box and must be at the same level of indentation. When you're creating menu control arrays, be sure to include any separator bars that appear on the menu.
What is the restrictions of dynamically created menu items?
Cannot have shortcut keys
Cannot be used for a WindowList
Must be menu control array elements
Pop-up menu
Private Sub Form_MouseUp (Button As Integer, Shift As _
Integer, X As Single, Y As Single)
If Button = 2 Then ' Check if right mouse button was clicked.
PopupMenu mnuFile ' Display the File menu as a pop-up menu.
End If
End Sub
•Any code following a call to the PopupMenu method is not run until the user selects an item in the menu or cancels the menu. Only one pop-up menu can be displayed at a time. While a pop-up menu is displayed, calls to the PopupMenu method are ignored. Calls to the PopupMenu method are also ignored whenever a menu control is active.
Menu and toolbar negotiation will occur only for insertable objects that support in-place activation.
1.The NegotiateMenus property does not apply to MDI Forms. 2.The NegotiateToolbars property applies only to MDI forms.
There are three ways to set conditional compilation constants:
•Project Properties dialog box - Public to all modules in the project •Command line - Public to all modules in the project
•
•vb6.exe /make MyProj.vbp /d conFrenchVersion=–1:conANSI=0
••#Const statement in code - Private to the module in which they are declared.
•
•
•
•- Only conditional compiler constants and literals can be used in expression.
Conditional compilation can use literal statements except for IS operator.
Subscribe to:
Posts (Atom)