473,748 Members | 9,416 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB FAQs (Interview Questions) lot lot

Question
Do ActiveX DLLs made in VB still need the VB runtimes on
the
machine?

_______________ _______________ __________
Answer
In a word, Yes.

Visual Basic does not support what is known as "Static
Linking". What that means is that all componets, controls,
and applications developed with Visual Basic, also requier
the Visual Basic Runtime libraries.
Question
What is a circular reference? Why is it bad?

_______________ _______________ __________
Answer
Consider two objects, A and B. A holds a reference to B,
and B holds a reference to A. A only releases its
reference to B when A terminates. B only releases its
reference to A when B terminates. Since neither A nor B
will terminate until all active references to them are
released, A and B are now immortal (which might sound cool,
but is really a 'bad thing').

Circular references should be avoided whenever possible,
but in some designs they can be unavoidable. For those
cases, there are various methods for "breaking" circular
references. One technique is to require the client to
manually clear them (eg. Set A.BReference = Nothing or call
a method which releases the reference). Another technique
is to use unsupported functions (ObjPtr, etc.) to get a non-
binding reference to the object. Yet another method is to
use a proxy object to dynamically obtain a reference which
is held only for the duration of the call

Question
What is meant by "Early Binding" and "Late Binding"? Which
is better?

_______________ _______________ __________
Answer
Early binding and late binding refer to the method used to
bind an interface's properties and methods to an object
reference (variable). Early binding uses type library
information at design time to reference procedures, while
late binding handles this at run time. Late binding
handles this by interrogating the reference before each
call to insure that it supports a particular method. Since
every call to a late bound object actually requires two
calls ("Do you do this?" followed by "Okay, do it then"),
late binding is much less efficient than early binding.
Except where early binding is not supported (ASP,
scripting, etc.), late binding should only be used in very
special cases.

It is a common misconception that any code using the
CreateObject function instead of Set = New is using late
binding. This is not the case. The type declaration of
the object variable determines whether it is late or early
bound, as in the following:

Dim A As Foo
Dim B As Foo
Dim C As Object
Dim D As Object

Set A = New Foo 'Early Bound
Set B = CreateObject("F ooLib.Foo") 'Early Bound
Set C = CreateObject("F ooLib.Foo") 'Late Bound
Set D = New Foo 'Late Bound
Question
I have been reading on the topic callin win32 APIs, but as
I think its a very complex topic I hope anyone can help me
sort it out a little more when answering my question:

In what kind of circumstances do you actually have
use accessing WIN32 API?

_______________ _______________ __________
Answer
There are approximately 15,000 functions included in the
WIN32 API. It's a 'collection' of functions that make up
the 'guts' of how Windows works.

Every application uses these functions to 'be' a Windows
application. In VB we are just shielded from most of it
because they wrote a bunch of 'wrapper' functions over the
API's for us.

Sometimes however they didn't give us all the functionality
we need and we will have to use a specific API function
ourselves to overcome this limitation. There are a number
of areas where we can do this. Actually just about
anything and anywhere.

However below you will find some quick examples of 'why' we
would use the API directly. As far as the AddressOf
operator, this is because some API functions require
a 'callback' function. This is a routine that the API will
call when it has finished it's processing and wants to let
you know it's 'your turn' again.

Some examples...

* Putting icons in the System Tray

* Getting / Setting text to other applications (commonly
called "Screen-Scrapping")

* Creating high precision timer functions (vb's are very
limited)

* Subclassing a form or window (<--too much here to
explain shortly)

* Making a specific window always being on top of other
windows
Question
Why do so many example programs not use the DLL name
directly without an alias? Surely the DLL names do not
commonly clash with existing names.

_______________ _______________ __________
Answer
There are a lot of reasons to use aliases. For instance, the
SendMessage API. You need to change the data types you are
sending to the API, so you need to have multiple
declarations of the same API.

There are many structures (UDTs) which are bigger or smaller
in NT than they are in Win9x. So, again, you need to change
what UDT you are pointing at depending on the OS. Since you
can''t do this on the fly, you need to write to different
declares.

Also, there are a lot of APIs that need to differentiate
between whether you are sending it a unicode or an ansi
string.

Question
What is a hWnd and what can it be used for?
Code examples for different kinds of usage are welcome.

_______________ _______________ __________
Answer
An hWnd is a Handle to a Window if you will. A handle is a
long integer generated by the operating system so it can
keep track of the all the objects (a form, a command button
etc.)

You can't set a hwnd at design or runtime, and the value of
the handle changes each time the form is opened. Handles
are used when you make calls to API functions, the function
needs to know the handle of the window, plus other
arguements depending on the what
the API does.

The GetWindowsText API frx:

Declare Function GetWindowText Lib "user32" alias _
"GetWindowTextA " (byval Hwnd as long, byval lpstring as _
string, byval cch as long) as Long

Assuming the object in question is a form, passing the hwnd
of the form to the api will cause a search to performed in
windows internal data structures looking for that handle,
and then return what text is in the forms title bar
or caption.

Question
Is there an event that fires when an application loses the
focus (Deactivate fires when a form loses focus to another
form in the same app, but not when I bring another
application to the front).

_______________ _______________ __________
Answer
No event fires ... but the active window receives the
WM_ACTIVATEAPP message.

Question
How can I close another program?

_______________ _______________ __________
Answer
You have to use the API - here's a code example, you'll
need to create a CommandButton called "Command1" on a form
and paste this code in. You'll need to modify the function
call under the Command1_Click event to reflect the Window
Caption \ Class you are trying to close.

Option Explicit

'This API is for the SendMessage function call - basically
sends a message to the specified hWnd
Private Declare Function SendMessage Lib "user32"
Alias "SendMessag eA" (ByVal hwnd As Long, ByVal wMsg As
Long, ByVal wParam As Long, ByVal lParam As Any) As Long
'This API is for the FindWindow call - is used to Find a
window based ona given Window class name or Window title
(caption)
Private Declare Function FindWindow Lib "user32"
Alias "FindWindow A" (ByVal lpClassName As String, ByVal
lpWindowName As String) As Long
'This API will return a formatted string for a give DLL
error
Private Declare Function FormatMessage Lib "kernel32"
Alias "FormatMessageA " (ByVal dwFlags As Long, ByVal
lpSource As Long, ByVal dwMessageId As Long, ByVal
dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize
As Long, Arguments As Any) As Long
'const required for FormatMessage
Private Const FORMAT_MESSAGE_ FROM_SYSTEM = &H1000

'Our string buffer length
Private Const BUFFER_LENGTH As Long = 255
'This const is used with the SendMessage call
Private Const WM_CLOSE As Long = &H10
'Our custom consts (for readability)
Private Const NO_ERROR As Long = 0
Private Const BYVAL_NULL As Long = 0&

Private Sub Command1_Click( )
'Function call
'in this case we are looking for a window with the
caption "KillMe"
'change it to suit your needs
KillWindow , "KillMe"
End Sub

Public Function KillWindow(Opti onal WindowClass As String =
vbNullString, Optional WindowTitle As String = vbNullString)

'************** *************** *************** ***************
*****
'* Function Name:
KillWindow *
'* Author: Lewis Cornick
(co**@developer exchange.co.uk) *
'* Description: Use to find and close a specific
Window. *
'* Date Created: 18th January
2001 *
'* Date
Modified: *
'*
Mods:
*
'************** *************** *************** ***************
*****

Dim lhWnd As Long
Dim lRes As Long
Dim lErrorNumber As Long
Dim sErrorDescripti on As String * BUFFER_LENGTH
Dim lFlags As Long

On Error GoTo Err_Handler

'Ensure our strings are null terminated
WindowClass = WindowClass & vbNullString
WindowTitle = WindowTitle & vbNullString

'In this case we are going to try and find the the
WindowHandle,
'if we already knew the hWnd we could just pass that
straight to
'the SendMessage call.

'Call the FindWindow API, this will return us a valid
WindowHandle,
'If its not a valid window (window isn't found)
FindWindow will return
'0 and Err.LastDLLErro r will be populated with an
Windows error number
'(see the FormatMessage call)
lhWnd = FindWindow(Wind owClass, WindowTitle)

'We assume we have a valid WindowHandle, now its time
to send the
'WM_CLOSE message to tell the window \ app to close.
lRes = SendMessage(lhW nd, WM_CLOSE, BYVAL_NULL,
BYVAL_NULL)

Err_Handler:

'Our Error Handler.
'Check the standard windows error number *and* the DLL
Error to ensure
'that neither the FindWindow or the SendMessage call
failed.

If Err.Number <NO_ERROR Or Err.LastDllErro r <>
NO_ERROR Then

'Something failed - need to decide what it was

If Err.Number <NO_ERROR Then
'Must be a straight VB error
lErrorNumber = Err.Number
sErrorDescripti on = Err.Description
Else
'An API failed - probably FindWindow due to the
Window not being found.
lErrorNumber = Err.LastDllErro r
'This API will take the Error number generated
from the API call and
'Format it into a English string for us to
report back to the user.
lRes = FormatMessage
(FORMAT_MESSAGE _FROM_SYSTEM, BYVAL_NULL, lErrorNumber,
BYVAL_NULL, sErrorDescripti on, BUFFER_LENGTH, BYVAL_NULL)
End If

'Raise the error up to whoever called the function.
Err.Raise lErrorNumber, "KillWindow ",
sErrorDescripti on
End If

End Function
Question
How do I make Windows shut down or restart?

_______________ _______________ __________
Answer
The API function ExitWindowsEx causes Windows to shut down
or restart. It is declared:

Private Declare Function ExitWindowsEx Lib "user32"
Alias "ExitWindow sEx" (ByVal uFlags As Long, ByVal
dwReserved As Long) As Long

The following constants may be passed as the first
parameter:

Private Const EWX_LOGOFF = 0
Private Const EWX_REBOOT = 2
Private Const EWX_SHUTDOWN = 1

Their use is self-explanatory. Always pass 0& as the
second parameter.

ExitWindowsEx may not work properly in NT or Windows 2000
if the server or workstation is locked. If you encounter
such difficulties, search the a fix is available from the
Microsoft KB. Search it for "ExitWindowsEx" .
Question
How do I send keystrokes to another application?

_______________ _______________ __________
Answer
First you have to make the App active, with AppActivate,
then you can send keys using SendKeys, both are well
documented in the MSDN libary.
Here is an example.

Dim dblReturnValue As Double
' The Apps Handle
dblReturnValue = Shell("Notepad. EXE", 1)
'Shell Notepad, and return the Handle to the app

AppActivate dblReturnValue
'Activate the app pointed to by the handle

SendKeys "VB-FAQ! Thanks for Visiting!"
'Send some keys to the app

SendKeys "%{F4}" ' Quit
'Close the app using % = ALT + {F4} key(F4)
Question
Why should I use ADO as opposed to DAO?

_______________ _______________ __________
Answer
DAO has not been supported by microsoft for a long time
now. ADO is Microsoft's data access technology for all the
current applications.

The only use for dao is internally within an older version
of access which doesn't have the currentproject. connection
property to get the ADO connection from.

All external access to an ACCESS database should be done
throught the oledb drivers with ADO

Question
Why should I use a stored procedure?

_______________ _______________ __________
Answer
Many RDBMS's (Relational DataBase Management System's)
support stored procedures SQLServer, Oracle, etc. Let's
look at what a Stored Procedure 'is' before we answer why
you should use them.

A stored procedure is essentially a routine you create that
will execute an SQL statement. You can define parameters
for the Stored Procedure to take, and most RDBMS's allow
them to have a return value as well. You can create stored
procedures to handle your UPDATEs, INSERTs, SELECTs, and
DELETEs...and even a couple things that don't have much to
do with any of those, and some that do all of those at the
same time. It's up to what you need it to perform.

There are four major reasons why using them can
slightly/greatly beneficial.

1. They can dramatically increase security.
If you set up a series of Stored Procedures to handle all
of your interaction to the data then this means that you
can remove all the user rights on all of your tables and
such. For example; say I create a stored procedure for
inserting a new employee. I design that stored procedure
so that it expects all the required parameters to insert
into the EMPLOYEES table as well as some data to insert
into related tables. I then write the stored procedure to
do exactly that. I can remove everyone's rights to the
actual EMPLOYEES table and require them to only do INSERTS
via the stored procedure. I have effectively forced them
to always insert data my way.

2. They can assist you in centralizing your code.
If I ever need to change the structure of that EMPLOYEES
table I don't have to worry about any applications crashing
if when they try to insert something new. Since all
interaction is via that stored procedure I just have to
make the updates in that one stored procedures code and
nowhere else.

3. They are executed on the Server's machine.
Because they actually reside on the server's machine, they
will use the process resources there as well. Generally
your Database Server will be much more 'beefy' as far as
processor and memory resources go than your clients
machines.

4. Better than that. (They are precompiled)
Since the stored procedure is stored into the RDBMS, the
RDBMS can actually look at how the SQL Statement is
processed and 'precompile' the statement. This means that
since the database can convert your stored procedure into
binary code and execute it as one command rather than parse
the SQL statement through an interpreter as if it was
text. Execution speeds can be vastly improved by this
alone.

So to recap, the reasons you might want to consider stored
procedures are 1. Security, 2. Maintenance, 3. More
abundant resources, 4. Precompiled for speed execution.
Question
How can I embed a Crystal Report (version 8) into my VB
project?

_______________ _______________ __________
Answer
You'll have to use the embedded report designer. To make it
available, go to the Project Menu >Components >>
Insertable Objects, and check it off. Now you'll have an
option in the Add menu (right-click project explorer, or
use the Project menu) named, "Crystal Reports 8...."
Question
How can I stop and start a SQL Server in Code?

_______________ _______________ __________
Answer
Using the SQLDMO object you can control a SQL Server at the
managment level.
Thus

Dim objSQL as SQlDMO.SQLServe r
set objSQL = new SQLDMO.SQLServe r
on error resume next
objSQL.start strServerName, strUserName, strPassword
if err.number <0 then '* server is already running
objSQL.connect strServerName, strUserName, strPassword
objSQL.shutdown True
end if
set objSql = nothing
Question
What is MSDE? How is it different from MS Access? SQL
Server?

_______________ _______________ __________
Answer
MSDE (Microsoft Data Engine) is the desktop version of SQL
Server. It is essentially the SQL Server database engine,
with some limitations: databases are limited to 2
gigabytes, MSDE can't be a publisher for replication, and
it is designed for 5 or fewer concurrent users. It does
support many of the same features as the full version of
SQL Server, most notably, stored procedures.

Like SQL Server, MSDE is a true database server. Data
requests are processed on the machine where MSDE resides,
as opposed to on the client with Microsoft Access
databases. This fact makes MSDE much more suitable than
Access for solutions with a small number of concurrent
users.
Question
How can I determine the capacity of drives?

_______________ _______________ __________
Answer
The following was downloaded off the Internet. Apologies
that the author cannot be credited. The code provides a
number of functions related to drives. Beware of word wrap
when copying this code.

'************** ****Drives.bas* *************** ***********
'In its present form it runs from Sub Main() and shows the
'debug window: no user interface. I did not need, for
'instance, total disc space. One could, however, change
'Debug.Print to Form1.Print or List1.AddItem and place
' 'DetectDrives' in Form_activate or a Command Button
'and start with the form instead of Sub Main(). Paste
'this code into a module. Place a floppy and a CD in
'the drives. Either remove form from project or start
'from Sub Main(). I have tried to include the most
'important comments for easy understanding. Functions
'are Private except 'DetectDrives'.
'************** *************** *************** ***********

Private Declare Function GetLogicalDrive Strings _
Lib "kernel32" Alias "GetLogicalDriv eStringsA" (ByVal _
nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function GetDriveType Lib "kernel32" _
Alias "GetDriveTy peA" (ByVal nDrive As String) As Long
Private Declare Function GetDiskFreeSpac e Lib "kernel32" _
Alias "GetDiskFreeSpa ceA" (ByVal lpRootPathName As _
String, lpSectorsPerClu ster As Long, lpBytesPerSecto r _
As Long, lpNumberOfFreeC lusters As Long, _
lpTotalNumberOf Clusters As Long) As Long
Private Declare Function GetVolumeInform ation Lib _
"kernel32.d ll" Alias "GetVolumeInfor mationA" (ByVal _
lpRootPathName As String, ByVal lpVolumeNameBuf fer As _
String, ByVal nVolumeNameSize As Integer, _
lpVolumeSerialN umber As Long, lpMaximumCompon entLength _
As Long, lpFileSystemFla gs As Long, ByVal _
lpFileSystemNam eBuffer As String, ByVal _
nFileSystemName Size As Long) As Long
Public Const DRIVE_REMOVABLE = 2
Public Const DRIVE_FIXED = 3
Public Const DRIVE_REMOTE = 4
Public Const DRIVE_CDROM = 5
Public Const DRIVE_RAMDISK = 6
Sub Main()
DetectDrives
End Sub

Private Function Serial(dPath As String) As Long
Dim N As Long
Dim lRet As Long
Dim fBuf As String
Dim sBuf As String
fBuf = Space(255)
sBuf = Space(255)
lRet = GetVolumeInform ation(dPath, fBuf, Len(fBuf), _
N, 0, 0, sBuf, Len(sBuf))
Serial = N
End Function

Private Function Range(ByVal nBytes As Long) As String

Const KB As Double = 1024
Const MB As Double = 1024 * KB
Const GB As Double = 1024 * MB

If nBytes < KB Then
Range = Format(nBytes) & " bytes"
ElseIf nBytes < MB Then
Range = Format(nBytes / KB, "0.00") & " KB"
ElseIf nBytes < GB Then
Range = Format(nBytes / MB, "0.00") & " MB"
Else
Range = Format(nBytes / GB, "0.00") & " GB"
End If
End Function

Private Function FreeSpace(ByVal DrvPath As String) As
String
Dim Sectors As Long 'per cluster
Dim Bytes As Long 'per sector
Dim FreeClusters As Long
Dim Clusters As Long 'total

If GetDiskFreeSpac e(DrvPath, Sectors, Bytes,
FreeClusters, Clusters) Then
FreeSpace = FreeClusters * Sectors * Bytes
Else
FreeSpace = 0
End If
FreeSpace = Range(FreeSpace ) 'converts to bytes or MB
End Function

Public Function DetectDrives()

Dim i As Integer
Dim drvStr As String
Dim AllDrvs As String
Dim lRet As Long
Dim dType As Integer 'see constants in general
declarations
AllDrvs = Space(255)
lRet = GetLogicalDrive Strings(Len(All Drvs), AllDrvs)
For i = 1 To lRet Step 4 'AllDrvs contains paths With
spaces in between
drvStr = UCase(Mid(AllDr vs, i, 3)) ' like: A:\ C:\
D:\
dType = GetDriveType(dr vStr) ' hence: Step 4
Select Case dType 'for each type shows Path,
Serial#, and Freespace.
Case 2
Debug.Print drvStr & " Floppy #" & Serial _
(drvStr) & " Freespace " & FreeSpace(drvSt r)
Case 3
Debug.Print drvStr & " Hard Disk #" & Serial _
(drvStr) & " Freespace " & FreeSpace(drvSt r)
Case 4
Debug.Print drvStr & " External Drive #" & _
Serial(drvStr) & " Freespace " & FreeSpace(drvSt r)
Case 5
Debug.Print drvStr & " CD-Rom #" & Serial _
(drvStr) & " Freespace " & FreeSpace(drvSt r)
Case 6
Debug.Print drvStr & " Ram Drive #" & Serial _
(drvStr) & " Freespace " & FreeSpace(drvSt r)
End Select

Next i
End Function
Question
I would like to use a text file to hold very simple
information such as integers or doubles. How can i save and
retrieve information from a text file into my program and
perhaps put it into a variable?

_______________ _______________ __________
Answer
'Write to the file
Open "thefile" for Output as 1
Print #1, "This is my file."
Print #1, 12345
Close #1

'Append to the file
Open "thefile" for Append as 1
Print #1, "This is another line."
Close #1

'Read from the file
Dim mystring As String, mynumber As Integer
Open "thefile" for input as 1
Input #1, mystring
Input #1, mynumber
Close #1
Question
How do I keep my form on top of all other windows?

_______________ _______________ __________
Answer
To keep a form on top of all other windows is a simple
matter of making one call the the SetWindowPos API. Below
is a code example:

' The API used to keep a window on top of all other windows.
Private Declare Function SetWindowPos Lib "user32" (ByVal _
hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As _
Long, ByVal y As Long, ByVal cx As Long, ByVal cy As _
Long, ByVal wFlags As Long) As Long

' Several constants that are used in conjunction with that
' API. Not all of these will be used to keep a form on top,
' but feel free to play with them.
Private Const SWP_FRAMECHANGE D = &H20
Private Const SWP_DRAWFRAME = SWP_FRAMECHANGE D
Private Const SWP_HIDEWINDOW = &H80
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_NOCOPYBITS = &H100
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOOWNERZORD ER = &H200
Private Const SWP_NOREDRAW = &H8
Private Const SWP_NOREPOSITIO N = SWP_NOOWNERZORD ER
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOZORDER = &H4
Private Const SWP_SHOWWINDOW = &H40
Private Const HWND_BOTTOM = 1
Private Const HWND_TOP = 0
Private Const HWND_NOTOPMOST = -2
Private Const HWND_TOPMOST = -1

' In the event of your choice you can place the positioning
' code. In this example the code is placed in the form's
' load event.

' If you want to stop a form from being the topmost window,
' simply replace the HWND_TOPMOST constant with the
' HWND_NOTOPMOST constant.

Private Sub Form_Load()

' A long to hold the return value of the SetWindowPos
' API.
Dim lngRetVal As Long

' Set the form to be the topmost window.
lngRetVal = SetWindowPos(Me .hwnd, HWND_TOPMOST, 0, 0, _
0, 0, SWP_NOSIZE Or SWP_NOMOVE)

End Sub
Question
I have a situation where I need to load a form by its name
rather than simply creating an object variable. How can I
do this?

_______________ _______________ __________
Answer
There are definitely some circumstances where one would
need to load a form by its name. Not getting into those
circumstances, here is how it's accomplished:

Public Sub LoadFormByName( ByVal sFormName As String)
Dim frm As Form
Set frm = Forms.Add(sForm Name)
frm.Show
End Sub

Of course, adequate error handling should be added to the
procedure to ensure the app doesn't crash if the form
referenced in sFormName doesn't exist.
Question
I have a form called MyForm. I'd like to create multiple
instances of this form, but when I do MyForm.Show it
creates a single instance and manipulates that single
instance. How can I create multiple instances of MyForm?

_______________ _______________ __________
Answer
You need to use form variables to accomplish this. Here is
a short sample showing how you might create 3 separate and
distinct instances of a form named MyForm.

Public Sub Show3Forms()

Dim f1 As MyForm
Dim f2 As MyForm
Dim f3 As MyForm

Set f1 = New MyForm
Set f2 = New MyForm
Set f3 = New MyForm

f1.Show
f2.Show
f3.Show

End Sub
Question
On a login form, I have a combo box with 2 entries that
will allow the user to select which DB environment they
wish to work in.

On start up I want the combo box to have "Production " show
as the default selection. I cannot seem to have this
happen. Everytime the form loads the user must click the
arrow to make a selection.

_______________ _______________ __________
Answer
Try adding this code.

If cboEnvironment. ListCount 0 Then
cboEnvironment. ListIndex = 0
End If
Question
I've been trying and searching and cannot find any
information explaining how to disable the "X" in the upper
right hand corner in an MDI child form. Any ideas?

_______________ _______________ __________
Answer
' *** Begin APIs for removing the close button from the
control box.

' Menu item constants.
Private Const SC_CLOSE As Long = &HF060&

' SetMenuItemInfo Mask constants.
Private Const MIIM_STATE As Long = &H1&
Private Const MIIM_ID As Long = &H2&

' SetMenuItemInfo State constants.
Private Const MFS_GRAYED As Long = &H3&
Private Const MFS_CHECKED As Long = &H8&

' SendMessage constants.
Private Const WM_NCACTIVATE As Long = &H86

' User-defined Type to contain menu info.
Private Type MENUITEMINFO
cbSize As Long
fMask As Long
fType As Long
fState As Long
wID As Long
hSubMenu As Long
hbmpChecked As Long
hbmpUnchecked As Long
dwItemData As Long
dwTypeData As String
cch As Long
End Type

' Declarations for retrieving and setting menus and menu
info.
Private Declare Function GetSystemMenu Lib "user32" ( _
ByVal hWnd As Long, ByVal bRevert As Long) As Long

Private Declare Function GetMenuItemInfo Lib "user32" Alias
_
"GetMenuItemInf oA" (ByVal hMenu As Long, ByVal un As
Long, _
ByVal b As Boolean, lpMenuItemInfo As MENUITEMINFO) As
Long

Private Declare Function SetMenuItemInfo Lib "user32" Alias
_
"SetMenuItemInf oA" (ByVal hMenu As Long, ByVal un As
Long, _
ByVal BOOL As Boolean, lpcMenuItemInfo As MENUITEMINFO)
As Long

' A long to contain the handle to the menu we are
manipulating.
Private hMenu As Long

' A menuiteminfo type used for passing to API calls.
Private MII As MENUITEMINFO

' A constant used for changing the ID of the menu item. This
is done
' because VB will reset our changes if we leave the ID
alone.
Const xSC_CLOSE = -10

' This function is used to send messages to windows.
Private Declare Function SendMessage Lib "user32" Alias
"SendMessag eA"
(ByVal hWnd As _
Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
String) As Long

' *** End APIs for removing the close button from control
box.
Private Sub Form_Load()

' Disable the close button in the control box.
Dim Ret As Long
Dim lngOldID As Long

' Retrieve the menu item info.
hMenu = GetSystemMenu(M e.hWnd, 0)
MII.cbSize = Len(MII)
MII.dwTypeData = String(80, 0)
MII.cch = Len(MII.dwTypeD ata)
MII.fMask = MIIM_STATE
MII.wID = SC_CLOSE
Ret = GetMenuItemInfo (hMenu, MII.wID, False, MII)

' Set the state to disabled and greyed.
MII.fState = MFS_GRAYED

' Store the old ID.
lngOldID = MII.wID

' Change the ID.
MII.wID = xSC_CLOSE

' Indicate to the structure that we are changing the ID
and the state.
MII.fMask = MIIM_ID Or MIIM_STATE

' Set the menu item to the new value.
Ret = SetMenuItemInfo (hMenu, lngOldID, False, MII)

' Send the WM_NCACTIVATE message to the form so it
updates the control
box.
Call SendMessage(Me. hWnd, WM_NCACTIVATE, True, 0)

End Sub
Question
How do I get the name of the logged on user?

_______________ _______________ __________
Answer
Option Explicit

' The first thing to do is to declare the proper API
' function, as follows:

Private Declare Function GetUserName Lib "advapi32.d ll" _
Alias "GetUserNam eA" (ByVal lpBuffer As String, nSize _
As Long) As Long

' Now we need a function which calls the API we just
' declared and then grabs it's value and returns
' it in the format we desire.

Public Function RetrieveUserNam e() As String

' A const to specify the max length of the user name.
Const MaxLen = 50

' Dim some variables to store the info.

' A string variable to hold the user name. This variable
' must be buffered in order for the function to work.
Dim strName As String

' Used to contain the length of the name retrieved.
Dim lngRetVal As Long

' Buffer the string with spaces.
strName = Space$(MaxLen)

' Get the user name and assign it to strName;
' lngRetVal will hold the length of the user name.
lngRetVal = GetUserName(str Name, MaxLen)

' Now we must trim the remaining buffering spaces.
strName = Trim$(strName)

' Because GetUserName returns a value with a trailing
' null termination character, we must remove that
' character.
strName = Left$(strName, Len(strName) - 1)

RetrieveUserNam e = strName

End Function

' Now from whatever event we want we can call the procedure
' we just wrote to get the user name and assign it to a
' string variable. In this example we will call it from
' the click event of a command button named Command1.

Private Sub Command1_Click( )

MsgBox RetrieveUserNam e

End Sub
Question
When someone talks about an object's "Interface" , what do
they mean?

_______________ _______________ __________
Answer
An interface is nothing more than a defined set of public
methods and properties (which are really methods, also)
that are supported by an object. More than one type of
object can support the same interface (for example,
TextBoxes and ComboBoxes are both Controls) and an object
can support more than one interface (a TextBox is both a
TextBox and a Control).

Interfaces serve as a contract between the creator of an
object and the user of that object. Any object which
supports an interface is required to provide each and every
property and method that makes up that interface.
Question
What does the term "Inheritanc e" mean?

_______________ _______________ __________
Answer
Inheritance, along with encapsulation and polymorphism, is
one of the three pillars of object-oriented theory.
Inheritance refers to the concept of deriving new objects
from existing ones. This creates "is a type of"
relationships between the object. Generally this works
along the lines of specific object A is a type of general
object B (ie. object "Poodle" is a type of "Dog" object).
This classifying of objects into base types and sub types
is also referred to as abstraction.

Inheritance can also take on different meanings. There is
implementation inheritance (sometimes called "true"
inheritance), where a derived object inherits the behavior
(code) of its parent(s). The derived object may use this
behavior or in some cases may define its own behavior for
selected methods. Interface inheritance, on the other
hand, involves a derived object sharing the same interface
as its parent. With interface inheritance, the derived
class is responsible for providing its own implementation
for each inherited method.
Question
Why should I use property procedures instead of public
variables in classes?

_______________ _______________ __________
Answer
Property procedures represent control; always use them
instead of public variables. Using public variables in a
class means giving up the ability to validate changes to
the class's data. Using property procedures is also the
only way to get Read-Only or Write-Only properties
Is Visual Basic an Object-Oriented Language?
_______________ _______________ __________
Question
I've seen people arguing over whether Visual Basic is an
object-oriented language. What's the answer (and why)?

_______________ _______________ __________
Answer
This question is probably more religious than technical in
nature (ie. there's no way to answer it without provoking
someone). While it offers encapsulation and polymorphism,
its lack of implementation inheritance makes the
answer 'No' if you adhere to the strictest definition (VB
only offers interface inheritance). Visual Basic in its
current form (version 6.0) is more of a component-based
language. Its object technology is closely bound to the
Component Object Model (COM). The version known as VB.Net,
however, will meet all of the requirements to be an object-
oriented language.
Question
How do I open the default web browser from a VB program?

_______________ _______________ __________
Answer
Use the ShellExecute API function, and pass it a URL.

Example:
'************** *************** *************** *************
'in form module
Const SW_SHOWDEFAULT = 10

Private Declare Function ShellExecute Lib "shell32.dl l" _
Alias "ShellExecu teA" (ByVal hWnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) _
As Long

'within form (e.g., click event for command or menu)
dim lAns as long
lAns = ShellExecute(me .Hwnd, "open", _
"http://www.yahoo.com", vbNullString, _
vbNullString, SW_SHOWDEFAULT)
Question
Just what *is* a dll file?

Are they files I create.. The compiler creates..etc?

_______________ _______________ __________
Answer
A dynamic link library (DLL) is a self-contained program or
set of small programs, that can be called when needed
by other applications running on the computer.

The DLL is not compiled within the standard applications
(EXEs) to conserve memory, conserve drive space and to
make the specific code within the DLL available to any
number of applications.

A good example is the VB runtime files. A single copy of
each file is all that is needed on the hard drive, yet
you can have any number of VB apps installed and they will
all access the same set of runtime files. This is much
better than compiling the files within each and every
VB app.

Yes, you can write your own DLL files. It is the compiler
that creates or *builds* the DLL.

Jan 16 '07 #1
14 4110
"shamirza" <sh******@gmail .comwrote in message
news:11******** *************@v 45g2000cwv.goog legroups.com...
<snip>
Why did you bother posting this in this particulat newsgroup?

Come to that, why did you bother posting it at all?

Jan 16 '07 #2
Stephany;

for the record; I was posting in this newsgroup a couple of months ago;
asking for information like this.. and NOBODY ANSWERED ME

please feel free to post things like this into the newsgroup whenever
you want

all VB people are welcome in _ALL_ vb newsgroups

-Aaron
Stephany Young wrote:
"shamirza" <sh******@gmail .comwrote in message
news:11******** *************@v 45g2000cwv.goog legroups.com...
<snip>

Why did you bother posting this in this particulat newsgroup?

Come to that, why did you bother posting it at all?
Jan 16 '07 #3
"Stephany Young" <noone@localhos tschrieb:
><snip>

Why did you bother posting this in this particulat newsgroup?

Come to that, why did you bother posting it at all?
In addition, note that the questions target VB6 and not VB.NET specifically.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jan 17 '07 #4
That's thae reason I asked the question.
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.atwrote in message
news:eP******** ******@TK2MSFTN GP04.phx.gbl...
"Stephany Young" <noone@localhos tschrieb:
>><snip>

Why did you bother posting this in this particulat newsgroup?

Come to that, why did you bother posting it at all?

In addition, note that the questions target VB6 and not VB.NET
specifically.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jan 17 '07 #5
you guys are WRONG.

microsoft broke the rules and traditions of newsgroups; the dipshit
project manager that decided to name the 'newsgroup for the current
version of vb' to be this verbose:

microsoft.publi c.dotnet.langau ges.vb

SHOULD BE DRAWN AND FUCKING QUARTERED

newsgroups shouldn't have thier name changed from microsoft.publi c.vb
to dotnet.vb; for starters; I am not ever going to use a product named
VB DOTNET.

I use a product called VB TWO THOUSAND FIVE

VB.NET didn't have edit and continue so VB.net can suck my salty balls

-Aaron
Stephany Young wrote:
That's thae reason I asked the question.
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.atwrote in message
news:eP******** ******@TK2MSFTN GP04.phx.gbl...
"Stephany Young" <noone@localhos tschrieb:
><snip>

Why did you bother posting this in this particulat newsgroup?

Come to that, why did you bother posting it at all?
In addition, note that the questions target VB6 and not VB.NET
specifically.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Jan 18 '07 #6
Aaron,

I doubt that MS would do something so unsanitary as taking something out of
your mouth and putting it into their own.
<aa*********@gm ail.comwrote in message
news:11******** **************@ 51g2000cwl.goog legroups.com...
VB.NET didn't have edit and continue so VB.net can suck my salty balls

Jan 19 '07 #7
eat shit mofo

why am i writing about VB 2005 in a newsgroup that is called DOTNET?

the product i use is NOT called DOTNET

-Aaron

Bruce W. Darby wrote:
Aaron,

I doubt that MS would do something so unsanitary as taking something out of
your mouth and putting it into their own.
<aa*********@gm ail.comwrote in message
news:11******** **************@ 51g2000cwl.goog legroups.com...
VB.NET didn't have edit and continue so VB.net can suck my salty balls
Jan 19 '07 #8
Since I'm breaking my personal rule to not feed trolls, I'll only
respond just this once. Here it goes:

You do know the difference between a programming language and an IDE
right?

You see, having VB2005 (the name of the IDE) isn't even required to
program on the .Net platform. All you need is to have .Net installed on
the pc, and some form of text editor. As a matter of fact, I can
program a complete Vb.Net program using Notepad - but the language I'm
using is still vb.net. Most people just use the ide to get the features
like breakpoints, designers, object browser, intellisense, etc. But
they are in no means required.

So should Microsoft name the newsgroup after the actual
language/version (VB DotNet) or after the most commonly used
developer's environment (vb 2005)? I say they chose right in naming it
after the language version.

Oh, and seeing how you always curse wildly and tell responders to eat
something, you can just leave that off of your further posts - we'll
just assume it's included.

Thanks,

Seth Rowe
aa*********@gma il.com wrote:
eat shit mofo

why am i writing about VB 2005 in a newsgroup that is called DOTNET?

the product i use is NOT called DOTNET

-Aaron

Bruce W. Darby wrote:
Aaron,

I doubt that MS would do something so unsanitary as taking something out of
your mouth and putting it into their own.
<aa*********@gm ail.comwrote in message
news:11******** **************@ 51g2000cwl.goog legroups.com...
VB.NET didn't have edit and continue so VB.net can suck my salty balls
Jan 19 '07 #9
Seth,

His response isn't showing the same 'zing' anymore. I think he's running out
of epithets to hurl around. :) But you make a truly valid point in your
post. Will he accept it, however?

Bruce

"rowe_newsgroup s" <ro********@yah oo.comwrote in message
news:11******** *************@3 8g2000cwa.googl egroups.com...
Since I'm breaking my personal rule to not feed trolls, I'll only
respond just this once. Here it goes:

You do know the difference between a programming language and an IDE
right?

You see, having VB2005 (the name of the IDE) isn't even required to
program on the .Net platform. All you need is to have .Net installed on
the pc, and some form of text editor. As a matter of fact, I can
program a complete Vb.Net program using Notepad - but the language I'm
using is still vb.net. Most people just use the ide to get the features
like breakpoints, designers, object browser, intellisense, etc. But
they are in no means required.

So should Microsoft name the newsgroup after the actual
language/version (VB DotNet) or after the most commonly used
developer's environment (vb 2005)? I say they chose right in naming it
after the language version.

Oh, and seeing how you always curse wildly and tell responders to eat
something, you can just leave that off of your further posts - we'll
just assume it's included.

Thanks,

Seth Rowe

Jan 20 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4101
by: softwareengineer2006 | last post by:
All Interview Questions And Answers 10000 Interview Questions And Answers(C,C++,JAVA,DOTNET,Oracle,SAP) I have listed over 10000 interview questions asked in interview/placement test papers for all companies between year 2000-2005 in my website http://www.geocities.com/allinterviewquestion/ So please have a look and make use of it.
0
6167
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip 2000 Interview questions of .NET , JAVA and SQL Server Interview questions (worth downloading it)
2
6964
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
0
4596
by: connectrajesh | last post by:
INTERVIEWINFO.NET http://www.interviewinfo.net FREE WEB SITE AND SERVICE FOR JOB SEEKERS /FRESH GRADUATES NO ADVERTISEMENT
2
7224
by: freepdfforjobs | last post by:
Full eBook with 4000 C#, JAVA,.NET and SQL Server Interview questions http://www.questpond.com/SampleInterviewQuestionBook.zip Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
0
4508
by: ramu | last post by:
C# Interview Questions and Answers8 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers8.html C# Interview Questions and Answers7 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers7.html C# Interview Questions and Answers 6 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers-6.html C# Interview Questions and Answers 5...
0
3432
by: reema | last post by:
EJB Interview Questions http://interviewdoor.com/technical/EJB-Interview-Questions.htm CSS Interview Questions http://interviewdoor.com/technical/CSS-Interview-Questions.htm C Interview Questions http://interviewdoor.com/technical/C-Interview-Questions.htm C# Interview Questions http://interviewdoor.com/technical/C-sharp-Interview-Questions.htm C++ Interview Questions http://interviewdoor.com/technical/C++-Interview-Questions.htm
0
2943
by: reema | last post by:
EJB Interview Questions http://interviewdoor.com/technical/EJB-Interview-Questions.htm CSS Interview Questions http://interviewdoor.com/technical/CSS-Interview-Questions.htm C Interview Questions http://interviewdoor.com/technical/C-Interview-Questions.htm C# Interview Questions http://interviewdoor.com/technical/C-sharp-Interview-Questions.htm C++ Interview Questions http://interviewdoor.com/technical/C++-Interview-Questions.htm
10
2058
by: anil reddy | last post by:
Dotnet Interview questions and FAQs, Jobs. Please give your feed back http://interviews.dotnetthread.com
0
8823
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.