By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,678 Members | 1,146 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,678 IT Pros & Developers. It's quick & easy.

VB FAQs (Interview Questions) lot lot

P: n/a
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("FooLib.Foo") 'Early Bound
Set C = CreateObject("FooLib.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 "SendMessageA" (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 "FindWindowA" (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(Optional WindowClass As String =
vbNullString, Optional WindowTitle As String = vbNullString)

'************************************************* **********
*****
'* Function Name:
KillWindow *
'* Author: Lewis Cornick
(co**@developerexchange.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 sErrorDescription 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.LastDLLError will be populated with an
Windows error number
'(see the FormatMessage call)
lhWnd = FindWindow(WindowClass, 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(lhWnd, 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.LastDllError <>
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
sErrorDescription = Err.Description
Else
'An API failed - probably FindWindow due to the
Window not being found.
lErrorNumber = Err.LastDllError
'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, sErrorDescription, BUFFER_LENGTH, BYVAL_NULL)
End If

'Raise the error up to whoever called the function.
Err.Raise lErrorNumber, "KillWindow",
sErrorDescription
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 "ExitWindowsEx" (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.SQLServer
set objSQL = new SQLDMO.SQLServer
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 GetLogicalDriveStrings _
Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal _
nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function GetDriveType Lib "kernel32" _
Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Declare Function GetDiskFreeSpace Lib "kernel32" _
Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As _
String, lpSectorsPerCluster As Long, lpBytesPerSector _
As Long, lpNumberOfFreeClusters As Long, _
lpTotalNumberOfClusters As Long) As Long
Private Declare Function GetVolumeInformation Lib _
"kernel32.dll" Alias "GetVolumeInformationA" (ByVal _
lpRootPathName As String, ByVal lpVolumeNameBuffer As _
String, ByVal nVolumeNameSize As Integer, _
lpVolumeSerialNumber As Long, lpMaximumComponentLength _
As Long, lpFileSystemFlags As Long, ByVal _
lpFileSystemNameBuffer As String, ByVal _
nFileSystemNameSize 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 = GetVolumeInformation(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 GetDiskFreeSpace(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 = GetLogicalDriveStrings(Len(AllDrvs), AllDrvs)
For i = 1 To lRet Step 4 'AllDrvs contains paths With
spaces in between
drvStr = UCase(Mid(AllDrvs, i, 3)) ' like: A:\ C:\
D:\
dType = GetDriveType(drvStr) ' hence: Step 4
Select Case dType 'for each type shows Path,
Serial#, and Freespace.
Case 2
Debug.Print drvStr & " Floppy #" & Serial _
(drvStr) & " Freespace " & FreeSpace(drvStr)
Case 3
Debug.Print drvStr & " Hard Disk #" & Serial _
(drvStr) & " Freespace " & FreeSpace(drvStr)
Case 4
Debug.Print drvStr & " External Drive #" & _
Serial(drvStr) & " Freespace " & FreeSpace(drvStr)
Case 5
Debug.Print drvStr & " CD-Rom #" & Serial _
(drvStr) & " Freespace " & FreeSpace(drvStr)
Case 6
Debug.Print drvStr & " Ram Drive #" & Serial _
(drvStr) & " Freespace " & FreeSpace(drvStr)
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_FRAMECHANGED = &H20
Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
Private Const SWP_HIDEWINDOW = &H80
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_NOCOPYBITS = &H100
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOOWNERZORDER = &H200
Private Const SWP_NOREDRAW = &H8
Private Const SWP_NOREPOSITION = SWP_NOOWNERZORDER
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(sFormName)
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
_
"GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As
Long, _
ByVal b As Boolean, lpMenuItemInfo As MENUITEMINFO) As
Long

Private Declare Function SetMenuItemInfo Lib "user32" Alias
_
"SetMenuItemInfoA" (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
"SendMessageA"
(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(Me.hWnd, 0)
MII.cbSize = Len(MII)
MII.dwTypeData = String(80, 0)
MII.cch = Len(MII.dwTypeData)
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.dll" _
Alias "GetUserNameA" (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 RetrieveUserName() 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(strName, 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)

RetrieveUserName = 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 RetrieveUserName

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 "Inheritance" 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.dll" _
Alias "ShellExecuteA" (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
Share this Question
Share on Google+
14 Replies


P: n/a
"shamirza" <sh******@gmail.comwrote in message
news:11*********************@v45g2000cwv.googlegro ups.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

P: n/a
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*********************@v45g2000cwv.googlegro ups.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

P: n/a
"Stephany Young" <noone@localhostschrieb:
><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

P: n/a
That's thae reason I asked the question.
"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:eP**************@TK2MSFTNGP04.phx.gbl...
"Stephany Young" <noone@localhostschrieb:
>><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

P: n/a
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.public.dotnet.langauges.vb

SHOULD BE DRAWN AND FUCKING QUARTERED

newsgroups shouldn't have thier name changed from microsoft.public.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**************@TK2MSFTNGP04.phx.gbl...
"Stephany Young" <noone@localhostschrieb:
><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

P: n/a
Aaron,

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

Jan 19 '07 #7

P: n/a
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*********@gmail.comwrote in message
news:11**********************@51g2000cwl.googlegro ups.com...
VB.NET didn't have edit and continue so VB.net can suck my salty balls
Jan 19 '07 #8

P: n/a
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*********@gmail.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*********@gmail.comwrote in message
news:11**********************@51g2000cwl.googlegro ups.com...
VB.NET didn't have edit and continue so VB.net can suck my salty balls
Jan 19 '07 #9

P: n/a
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_newsgroups" <ro********@yahoo.comwrote in message
news:11*********************@38g2000cwa.googlegrou ps.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

P: n/a
eat a dick fag

it's not called VB.net

the language is NOT called VB.net it has NOT BEEN CALLED VB.NET for
what.. 15 months?

the language was RENAMED from VB DOTNET to VB 2005 BECAUSE THE PHRASE
DOTNET, THE MONIKER-- is a complete failure

Seriously.

Please show me one piece of literate from MIcrosoft that calls it 'vb
dotnet 2005'

-Aaron

rowe_newsgroups wrote:
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*********@gmail.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*********@gmail.comwrote in message
news:11**********************@51g2000cwl.googlegro ups.com...
VB.NET didn't have edit and continue so VB.net can suck my salty balls
Jan 21 '07 #11

P: n/a
eat a dick fag

it's not called VB.net

the language is NOT called VB.net it has NOT BEEN CALLED VB.NET for
what.. 15 months?

the language was RENAMED from VB DOTNET to VB 2005 BECAUSE THE PHRASE
DOTNET, THE MONIKER-- is a complete failure

Seriously.

Please show me one piece of literatature from MIcrosoft that calls it
'vb dotnet 2005'

-Aaron

rowe_newsgroups wrote:
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*********@gmail.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*********@gmail.comwrote in message
news:11**********************@51g2000cwl.googlegro ups.com...
VB.NET didn't have edit and continue so VB.net can suck my salty balls
Jan 21 '07 #12

P: n/a
I militantly disagree with your diagnosis

maybe if you weren't infected with DOTNET then maybe you wouldn't be
such a dipshit

I'll never use a language named DOTNET

the IDE is not called DOTNET
the LANGUAGE is not called DOTNET

the faggot that renamed the 'main vb newsgroup' from
microsoft.public.vb to microsoft.public.dotnet.languages.vb is a
fucking idiot

the fucking idiot that pulled the DNS redirect for microsoft.com/vb
should be shot

newbies come to microsoft.com/vb and they think 'oh shit, ms has killed
VB'
newbies come to microsoft.public.vb and they think 'oh shit, ms has
killed VB'

it's a marketing thing, and you're no KENNEDY fucker
-Aaron
rowe_newsgroups wrote:
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*********@gmail.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*********@gmail.comwrote in message
news:11**********************@51g2000cwl.googlegro ups.com...
VB.NET didn't have edit and continue so VB.net can suck my salty balls
Jan 21 '07 #13

P: n/a
please _FAG_ please please tell me _ANYWHERE_ that it says DOTNET at
this location

http://msdn.microsoft.com/vstudio/express/vb/

and for the record; what kindof studid fucking URL is this:
http://msdn.microsoft.com/vstudio/express/vb/

I shouldn't have to write VSTUDIO; that is an abbreviation
I shouldn't have to write MSDN; I don't subscribe to MSDN

WHEN MICROSOFT BRINGS THE VISUAL OR THE BASIC BACK TO VISUAL BASIC IS
WHEN I STFU

-Aaron

aa*********@gmail.com wrote:
I militantly disagree with your diagnosis

maybe if you weren't infected with DOTNET then maybe you wouldn't be
such a dipshit

I'll never use a language named DOTNET

the IDE is not called DOTNET
the LANGUAGE is not called DOTNET

the faggot that renamed the 'main vb newsgroup' from
microsoft.public.vb to microsoft.public.dotnet.languages.vb is a
fucking idiot

the fucking idiot that pulled the DNS redirect for microsoft.com/vb
should be shot

newbies come to microsoft.com/vb and they think 'oh shit, ms has killed
VB'
newbies come to microsoft.public.vb and they think 'oh shit, ms has
killed VB'

it's a marketing thing, and you're no KENNEDY fucker
-Aaron
rowe_newsgroups wrote:
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*********@gmail.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*********@gmail.comwrote in message
news:11**********************@51g2000cwl.googlegro ups.com...
VB.NET didn't have edit and continue so VB.net can suck my salty balls
Jan 21 '07 #14

P: n/a
Forgot every all past messages....bosses... why the hell we are
fighting....
what ever microsoft does is for people's. He is simple great from my
personal
view. Thanks to all microsoft supporters. hey hey hey.... :)

Bruce W. Darby wrote:
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_newsgroups" <ro********@yahoo.comwrote in message
news:11*********************@38g2000cwa.googlegrou ps.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 23 '07 #15

This discussion thread is closed

Replies have been disabled for this discussion.