A security issue has been identified that could allow an attacker to compromise your Windows-based system running Microsoft Visual Basic 6.0 Service Pack 6 and gain complete control over it. You can help protect your computer by installing this update from Microsoft.

To download, click here.


 
Categories: Link | News | VB

If you are stuck using VB6 and .NET check out the site below.

http://msdn.microsoft.com/en-ca/vbrun/ms788241.aspx


 
Categories: .NET | Link | VB | VB.NET

May 20, 2008
@ 03:47 PM

It's finally official as of May 2008, I am a patented inventor for this pretty cool project I did when I worked at Proflowers.com!
 
http://www.google.com/patents?id=9xeqAAAAEBAJ&dq=%22David+McCarter%22
 
The other guy on the patented is the president of the company, had nothing to do with it. I called one of the attorneys back in 2001 and tried to get the guy who wrote the FTP part put on it but they weren't listening to me. Also told them the diagrams submitted were wrong! Oh well.


 
Categories: dotNetDave | VB

November 15, 2007
@ 03:01 PM

Visual Basic Beer? Well not really, but we can only hope. Don't look for this in your local store unless you are in Australia.

VB Beer


 
Categories: Geek Humor | VB | VB.NET

April 15, 2004
@ 11:15 PM

You can keep your window on top by using the code listed below.

Declare

Declare Sub SetWindowPos Lib "User" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, 
ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer,
ByVal wFlags As Integer)
Const SWP_NOMOVE = 2
Const SWP_NOSIZE = 1
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2

Code

Sub KeepOnTop (frmIn As Form, bOnTop As Integer)
     Dim iTopFlag As Integer
     Const wFlags = SWP_NOMOVE Or SWP_NOSIZE
 
     If bOnTop = True Then
           iTopFlag = HWND_TOPMOST
     Else
           iTopFlag = HWND_NOTOPMOST
     End If
     SetWindowPos frmIn.hWnd, iTopFlag, 0, 0, 0, 0, wFlags
     DoEvents
End Sub

Usage

To put a Form on top of all windows, then call:

KeepOnTop Me, True

To remove the Form from being on top, call:

KeepOnTop Me, False

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.
Parts of this tip was submitted by: Henk Hakvoort
Compatible With  Visual Basic 3.0, Visual Basic 4.0 16-bit


 
Categories: VB

Instead of SetWindowPos, it uses SetWindowWord. This lets you create a floating toolbar that stays above its app's window without staying on top of ALL windows. Very handy for that professional look.

Declare Sub SetWindowWord Lib "USER" (ByVal hWnd, ByVal nCmd, ByVal nVal) 
Const SWW_hParent = (-8)

Form_Load of the form that you want to keep on top. Set it about form1.

Sub Form_Load () 
     SetWindowWord hWnd, SWW_hParent, form1.hWnd
End Sub

Form_Unload of the from you want to keep on top this is for cleaning up.

Sub Form_Unload (Cancel As Integer) 
     SetWindowWord hWnd, SWW_hParent, 0
End Sub

 

Tip Submitted By: Jonathon Twigg


 
Categories: VB

Background

I was almost finished with an app I was writing. Twice in this app I did some time consuming formatting and I thought it would be nice to have a status bar in these loops. My program had Modal windows so the problem begun. I could not show a non modal window on to of a modal window and if I loaded a Modal window I could not execute the code in the current module. I did not want to put the code in the status window because there were 2 big loops that had to be in the modules they were. So this is what I found. You can show a window non-modal with the SetWindowPos call from windows. By showing the window with this call I had two windows that could get the focus so I had to disable the first form and I just did that with Me.Enabled = False. When the loop was finished I just Enabled my for again and unloaded the status form.

Code

Global Declare:

Declare Function SetWindowPos Lib "User" (ByVal hWnd As Integer, ByVal hWndInsertAfter As Integer,
ByVal X As Integer, ByVal Y As Integer, ByVal cX As Integer, ByVal cY As Integer,
ByVal wFlags As Integer) As Integer
 
Global Const SWP_NOMOVE = &H2
Global Const SWP_NOSIZE = &H1
Global Const SWP_SHOWWINDOW = &H40
Global Const HWND_TOP = 0

The loop:

Sub DoAnyThing ()
     ' Show the status window
     i = SetWindowPos(frm_Status.hWnd, HWND_TOP, 0, 0, 0, 0, 
SWP_NOSIZE Or SWP_NOMOVE Or SWP_SHOWWINDOW)
     ' Disable Me
     Me.Enabled = False
     DoEvents
 
     ' Do the loop
     For I = 1 To 200
           ' do stuff
           ' set the status
           frm_Status.pic_Status.Line (0, 0)-(I, 100), QBColor(1), BF
           frm_Status.pic_Status.Refresh
           DoEvents
     Next I
 
     'Unload the status window
     Unload frm_Status
     ' Enable Me ...
     Me.Enabled = True
     ' and give me the focus
     Me.SetFocus
End Sub

 

Tip Submitted By: Olafur Orn Jonsson


 
Categories: VB

April 15, 2004
@ 11:05 PM

You could move the cursor off the screen, but there is an easy way to make the cursor invisible with an API call:

Declare

Declare Function ShowCursor Lib "User" (ByVal bShow As Integer) As Integer

Usage

To use the API, simply call:

R = ShowCursor(True)

or

R = ShowCursor(False)

There is one thing you should know about this API call. Whenever a program calls ShowCursor, Windows keeps an internal count of how many times ShowCursor was called. The problem is that there is no way to retrieve this counter. So just calling ShowCursor(False) might not work because it just decreases the counter by one. Unless the counter is zero, the cursor will not disappear. Use this routine instead.

Sub EnableCursor (iSetting As Integer)
     Select Case iSetting
           Case True
                 Do While ShowCursor(True) <= 0
                 Loop
           Case False
                 Do While ShowCursor(False) >= 0
                 Loop
     End Select
End Sub

To use this Sub, call it with the iSetting parameter set to either True or False. The cool thing about this API call is that it makes the cursor invisible but MouseMove, etc., events still work. This technique also works in Windows 95.

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.
Parts of this tip was submitted by: David McCarter

Compatible with: Visual Basic 3.0, Visual Basic 4.0 16-bit


 
Categories: VB

April 15, 2004
@ 11:02 PM

To do effective error handling, you must write them into each and every routine. What a pain! There are many ways to do error handling, from coding it yourself to purchasing add-on tools that will do most of the code writing for you.

This tip is for those who prefer to do it themselves. This is a good idea, because you have much more control over it. Also, another important part of error handling is writing the error to a file. This will save you tons of time in development and also help with technical support problems. Instead of trying to get information on the error message from the user, they can simply send the error log. This tip incorporates that philosophy.

Declare

Global Const errExit = 0
Global Const errResume = 1
Global Const errNext = 2
Global Const errSelect = 3

Code

Public Function ErrorHandler(iErrorNumber As Integer, sErrText As String, 
iErrOption As Integer) As Integer
Dim sMessage As String
Dim iReturn As Integer
     'Create message string
     sMessage = "Error #:" & Str(iErrorNumber) & " - "
     sMessage = sMessage & sErrText
     'Save to error log file
     ErrWriteLogFile sMessage
 
     Select Case iErrOption
           Case errExit
                 MsgBox sMessage, vbCritical, _
                       "Exiting program..."
                 GoTo errHandlerEnd
           Case errResume
                 MsgBox sMessage, vbCritical, "Error"
                 ErrorHandler = errResume
           Case errNext
                 MsgBox sMessage, vbCritical, "Error"
                 ErrorHandler = errNext
           Case errSelect
                 iReturn = MsgBox(sMessage, vbCritical + _
                       vbAbortRetryIgnore, "Error")
                 Select Case iReturn
                       Case Is = vbAbort
                             GoTo errHandlerEnd
                       Case Is = vbRetry
                             ErrorHandler = errResume
                       Case Is = vbIgnore
                             ErrorHandler = errNext
                 End Select
     End Select
     Exit Function
errHandlerEnd:
     MsgBox "Click OK to Exit Program"
     End
End Function
 
Public Sub ErrWriteLogFile(sLogMsg As String)
     Dim sFile As String
     Dim lFile As Long
     Dim sErrDir As String
 
     On Error GoTo errWriteLogFileErr
     sErrDir = App.Path
     lFile = FreeFile
     sFile = sErrDir & "\" & App.EXEName & ".err"
     Open sFile For Append As lFile
     Print #lFile, Format$(Now, "General Date") & ": " _
           & sLogMsg
     Close #lFile
     GoTo errWriteLogFileExit
errWriteLogFileErr:
     MsgBox Str(Err) + "-" + Error$, vbCritical, _
           "Unable to Write Error Log"
     Exit Sub
errWriteLogFileExit:
End Sub

Example

This is a sample of how you could use this tip:

Dim R As Long
Dim I As Integer
On Error GoTo ErrorHandler1
     For I = 3000 To 100000
           DoEvents
     Next I
ErrorHandler1:
     R = ErrorHandler(iErrorNumber:=Err.Number, sErrText:=Err.Description, iErrOption:=errNext)

Even though this tip was written in Visual Basic 4.0, it can be easily modified for any other version of Visual Basic. It’s also easy to modify for your particular needs.

 

This tips is reprinted from the VB Tips & Tricks Volume 1 book.
Some parts of this tips was submitted by: George Graff


 
Categories: VB

April 15, 2004
@ 10:57 PM

Declare

Private Declare Function MakeSureDirectoryPathExists Lib "IMAGEHLP.DLL" 
(ByVal DirPath As String) As Long

Code

Public Sub CreatePath(ByVal DestPath As String)
    If Right(DestPath, 1) <> "\" Then
        DestPath = DestPath & "\"
    End If
    If MakeSureDirectoryPathExists(DestPath) = 0 Then
        MsgBox "Error creating path: " & DestPath
    End If
End Sub

 

Tip Submitted By: Kevin Buchan


 
Categories: VB

This is a multi-part download of Service Pack 6 for Visual Basic 6.0. Customers with broadband connections are encouraged to download the one-file version. See the Related Resources link.

Service Pack 6 for Visual Basic 6.0 provides the latest updates to Visual Basic 6.0. It is recommended for all users of Visual Basic 6.0.

 

http://www.microsoft.com/downloads/details.aspx?familyid=83bf08e6-012d-4db2-8109-20c8d7d5c1fc&displaylang=en


 
Categories: VB

vbrun60sp6.exe is a self-extracting executable file that installs versions of the Microsoft Visual Basic run-time files required by all applications created with Visual Basic 6.0. The files include the fixes shipped with Service Pack 6 for Visual Basic 6.0.

 

http://www.microsoft.com/downloads/details.aspx?familyid=7b9ba261-7a9c-43e7-9117-f673077ffb3c&displaylang=en


 
Categories: VB

Positioning the cursor over the button they will are likely to make the action quicker and easier.

The following code will center the mouse cursor over any control that has an hWnd property.

Declare

#If Win32 Then
     Type RECT
           left As Long
           top As Long
           right As Long
           bottom As Long
     End Type
     Declare Sub GetWindowRect Lib "User32" (ByVal hWnd As _
           Long, lpRect As RECT)
     Declare Sub SetCursorPos Lib "User32" (ByVal X As _
           Long, ByVal Y As Long)
#Else
     Type RECT
           left As Integer
           top As Integer
           right As Integer
           bottom As Integer
     End Type
 
     Declare Sub GetWindowRect Lib "User" (ByVal hWnd _
           As Integer, lpRect As RECT)
     Declare Sub SetCursorPos Lib "User" (ByVal X As _
           Integer, ByVal Y As Integer)
#End If
Code
Sub CenterCursor(hWnd As Long)
Dim rPosition As RECT
#If Win32 Then
     Dim X As Long
     Dim Y As Long
#Else
     Dim X As Integer
     Dim Y As Integer
#End If
 
     GetWindowRect hWnd, rPosition
     X = (rPosition.right + rPosition.left) / 2
     Y = (rPosition.bottom + rPosition.top) / 2
     SetCursorPos X, Y
End Sub

Usage

CenterCursor hWnd:=Command1.hWnd

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.
Parts of this tip were submitted by: Donovan Olivier
Compatible With Visual Basic 4.0
Applies To Controls


 
Categories: VB

March 11, 2004
@ 12:25 AM

This is not an easy task because the TAB does NOT generate the Key_Press event. So, you need to use the GetKeyState windows API function for this.

Declare

Private Declare Function GetKeyState Lib "User32" (ByVal nVirtKey As Long) As Integer
' Virtual key values
Const VK_TAB = &H9
Const VK_SHIFT = &H10

Code

Sub txtAreaCode_LostFocus()
Dim iRetVal As Integer
 
    ' Check for a tab out of this control
    ' Skip the state field
    iRetVal = GetKeyState(VK_SHIFT)
    ' If the shift was NOT on, check the tab
    If iRetVal <> -128 And iRetVal <> -127 Then
        iRetVal = GetKeyState(VK_TAB)
        If iRetVal = -128 Or iRetVal = -127 Then ' tab key pressed
            txtPhone.SetFocus
        End If
    End If
End Sub

 

Tip Submitted By: Deborah Kurata

 


 
Categories: VB

March 9, 2004
@ 11:16 PM

Even though this code is relatively simple, it's surprising to see the number of major applications on the shelves that fail to correctly handle this scenario.

The code shown below consists of two functions. The bValDIR function is needed because in Visual Basic, if you try to create a directory using the MkDir function that already exists, MkDir will generate an error.

Code

Sub MakeDir (sDirName As String)
Dim iMouseState As Integer
Dim iNewLen As Integer
Dim iDirLen As Integer
    'Get Mouse State
     iMouseState = Screen.MousePointer
     'Change Mouse To Hour Glass
     Screen.MousePointer = 11
     'Set Start Length To Search For [\]
     iNewLen = 4
     'Add [\] To Directory Name If Not There
     If Right$(sDirName, 1) <> "\" Then
           sDirName = sDirName + "\"
     End If
     'Create Nested Directory
     Do While Not bValDir(sDirName)
           iDirLen = InStr$(iNewLen, sDirName, "\")
           If Not bValDir(Left$(sDirName, iDirLen)) Then
                 MkDir Left$(sDirName, iDirLen - 1)
           End If
           iNewLen = iDirLen + 1
     Loop
     'Leave The Mouse The Way You Found It
     Screen.MousePointer = iMouseState
End Sub
Function bValDir (sIncoming As String) As Integer
Dim iCheck As String
Dim iErrResult As Integer

    On Local Error GoTo ValDirError
     If Right$(sIncoming, 1) <> "\" Then
           sIncoming = sIncoming + "\"
     End If
     iCheck = Dir$(sIncoming)
     If iErrResult = 76 Then
           bValDir = False
     Else
           bValDir = True
     End If 
Exit Function
ValDirError:
     Select Case Err
           Case Is = 76
                 iErrResult = Err
                 Resume Next
           Case Else
     End Select
End Function

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.
Parts of this tip was submitted by: David McCarter

Compatible With All Versions of Visual Basic
Applies To Disk Directory


 
Categories: VB

March 9, 2004
@ 11:12 PM

Well Visual Basic 5.0 comes with a program that create them for you, but what a pain. Wouldn't it be nice to just do it via code? Well now you can with the sample code below.

Declare

Type GUID Data1 As Long
    Data2 As Integer
    Data3 As Integer
    Data4(7) As Byte
End Type
 
Private Declare Function CoCreateGuid Lib "ole32.dll" (pguid As GUID) As Long
Private Declare Function StringFromGUID2 Lib "ole32.dll" 
(rguid As Any, ByVal lpstrClsId As Long, ByVal cbMax As Long) As Long

Code

Public Function GetGUID() As String
Dim pudtGUID As GUID
Dim pstrGUID As String
Dim pbytGUID() As Byte
Dim plngRet As Long
Dim plngLen As Long
    plngLen = 40
    pbytGUID = String(plngLen, 0)
    CoCreateGuid pudtGUID
    plngRet = StringFromGUID2(pudtGUID, VarPtr(pbytGUID(0)), plngLen)
    pstrGUID = pbytGUID
    If (Asc(Mid$(pstrGUID, plngRet, 1)) = 0) Then plngRet = plngRet - 1
    GetGUID = Left(pstrGUID, plngRet)
End Function

 

Tip Submitted By: David McCarter/Woody Pewitt


 
Categories: VB

This is really easy to do.

Declare

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

Code

Dim X
    X = ShellExecute(hwnd, "Open", "http://www.microsoft.com/vbasic", &O0, &O0, SW_NORMAL)

 

Tip Submitted By: Ryan Martinsen


 
Categories: VB

March 9, 2004
@ 11:07 PM

The 32-bit API has a call that will create a unique file for you in the Windows temporary directory.

Declare

Declare Function OSGetTempPath& Lib "kernel32" Alias "GetTempPathA" 
(ByVal BufferLength&, ByVal Result$)
Declare Function OSGetTempFilename& Lib "kernel32" Alias "GetTempFileNameA" 
(ByVal FilePath$, ByVal Prefix$, ByVal wUnique&, ByVal TempFileName$)
Code
Function sGetTempFile(ByRef sPrefix As String)
Dim sFilePath As String
Dim sTempResult As String
Dim lCharCount As Long
Const MAX_RETURN = 3000
     sTempResult = Space$(MAX_RETURN)
     lCharCount = OSGetTempPath&(MAX_RETURN, sTempResult)
     sFilePath = Left$(sTempResult, lCharCount)
 
     sTempResult = Space$(MAX_RETURN)
     lCharCount = OSGetTempFilename&(sFilePath, sPrefix, 0, sTempResult)
     sGetTempFile = Left$(sTempResult, lCharCount)
End Function

Usage

sTempFile = sGetTempFile(sPrefix:="VBT")

This API call will tag a prefix (up to 3 characters) to the file. This makes it easier for you find, use, or delete your temporary files.

NOTE: Windows will NOT automatically delete these temporary files. So be kind to your user, keep track of them and delete them when the application closes.

This tip is reprinted from the VB Tips & Tricks Volume 1 book.
Parts of this tip was submitted by: David McCarter
Compatible With Visual Basic 4.0 32-bit
Applies To Files


 
Categories: VB

 The code below can be easily added to a module and even includes code to make a backup (Access is notorious for corrupting databases at a drop of a pin). Compacting large databases can take a long time, so provide your user with a "Please wait..." type message.

NOTE: Remember, you cannot compact a database while it's open. Be sure to run this code before any code is run that opens the database, or any form with a data control is loaded. You could also run this at the end of your program.

Function bCompactMDB (sDatabase As String, bBackup As Integer) As Integer
Dim sNewFile As String
Dim sBakFile As String
     bCompactMDB = False
     MousePointer = 11
     sNewFile = Left$(sDatabase, Len(sDatabase) - 3) & "NEW"
     sBakFile = Left$(sDatabase, Len(sDatabase) - 3) & "BAK"
     On Error GoTo CompactError
     If Dir(sNewFile) <> "" Then
        Kill sNewFile
     End If
     CompactDatabase sDatabase, sNewFile
     If Dir(sBakFile) <> "" Then
       Kill sBakFile
     End If
     If bBackup = True Then
       Name sDatabase As sBakFile
     End If
     If Dir(sDatabase) <> "" Then
       Kill sDatabase
     End If
     Name sNewFile As sDatabase
     bCompactMDB = True
     MousePointer = 0
     Exit Function
CompactError:
     bCompactMDB = False
     MousePointer = True
End Function

This tip is reprinted from the VB Tips & Tricks Volume 1 book.
Parts of this tip was submitted by: David McCarter

Compatible With Visual Basic
Applies To Access 2.x Database File


 
Categories: VB

March 9, 2004
@ 11:01 PM

You can use the following function to defragment memory, making the maximum available to your program, before beginning any operation that will require a lot of memory.

Declare

Declare Function GlobalCompact Lib "Kernel" (ByVal dwMinFree&) As Long

Code

Sub CompactMemory ()
     Dim R As Long
     R = GlobalCompact(&HFFFFFFFF)
End Sub

Usage

Call CompactMemory

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.

Compatible With Visual Basic 3.0, Visual Basic 4.0 16-bit
Applies To Windows 3


 
Categories: VB

During the development of your project, the types and number of settings can grow and grow. With these routines, you can write the code once, then you usually won't need to update this code even when you add new controls.

For each setting that you save, whether to the Registry or an INI, you'll need to define "section" and "key" strings. See the help on GetSetting and/ or SaveSetting for examples.

For each control that you'll use to maintain a setting, put the name of the "key" in the control's TAG property. Put the default value of that key in the control itself at design time. For the section name, you must put your control into a container control with the desired "section" string in its own .TAG field. Often, this is actually very convenient, as controls get grouped into frames and other logical containers. When that isn't fully effective, use any kind of invisible container which supports a .TAG property, or use the TAG of the form itself. I usually reserve that last tactic for the most general of settings.

Call GetOptions before showing the form to the user (I usually call it from form_load) and call PutOptions whenever you need to save settings.

Code

Public Sub GetOptions(Frm As Form)
Dim Ctrl As Control
    For Each Ctrl In Frm.Controls
        With Ctrl
            If .Enabled Then
                If Len(.Parent.Tag & .Tag) Then
                    If TypeOf Ctrl Is TextBox Then
                        .Text = Trim$(GetSettingString(.Parent.Tag, .Tag, .Text))
                        ElseIf TypeOf Ctrl Is CheckBox _
                            Or TypeOf Ctrl Is HScrollBar _
                            Or TypeOf Ctrl Is VScrollBar _
                            Then
                            .Value = GetSettingInt(.Parent.Tag, .Tag, .Value)
                    End If
                End If
            End If
        End With
    Next
End Sub
 
Public Sub PutOptions(Frm As Form)
Dim Ctrl As Control
    For Each Ctrl In Frm.Controls
        With Ctrl
            If .Enabled Then
                If Len(.Parent.Tag & .Tag) Then
                    If TypeOf Ctrl Is TextBox Then
                        SaveSettingString .Parent.Tag, .Tag, .Text
                        ElseIf TypeOf Ctrl Is CheckBox _
                            Or TypeOf Ctrl Is HScrollBar _
                            Or TypeOf Ctrl Is VScrollBar _
                            Then
                            SaveSettingInt .Parent.Tag, .Tag, .Value
                    End If
                End If
            End If
        End With
    Next
End Sub

You'll need to include GetSettingInt, GetSettingString, SaveSettingInt, and SaveSettingString routines to save the settings to your own INI file.

Also, you can certainly adjust the code for other types of controls besides the TextBox, CheckBox, HScrollBar and VScrollBar.

Additional Code

'Set this public variable before you call GetOptions or PutOptions
Public gsIniFile As String
Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" 
(ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long,
ByVal lpFileName As String) As Long
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" 
(ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String,
ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" 
(ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any,
ByVal lpFileName As String) As Long
Private Function FixString(sInString As String) As String
Dim nPos As Integer
    On Error Resume Next
    nPos = InStr(sInString, Chr$(0))
    If nPos Then
        FixString = Left$(sInString, nPos - 1)
        Else
            FixString = sInString
    End If
End Function
Private Function GetSettingString(sSection As String, sKey As String, sDefault As String) As String
Const INI_BUF_SIZE = 255
Dim iReturn As Integer
Dim sBuffer As String
    On Error Resume Next
    sBuffer = String$(INI_BUF_SIZE + 1, 0)
    iReturn = GetPrivateProfileString(sSection, sKey, sDefault, sBuffer, INI_BUF_SIZE, gsIniFile)
    GetSettingString = FixString(sBuffer)
End Function
Private Function GetSettingInt(sSection As String, sKey As String, nDefault As Integer) As Integer
    On Error Resume Next
    GetSettingInt = GetPrivateProfileInt(sSection, sKey, nDefault, gsIniFile)
End Function
Private Function SaveSettingInt(sSection As String, sKey As String, nValue As Integer) As Boolean
    On Error Resume Next
    SaveSettingInt = IniPrivateWriteString(sSection, sKey, CStr(nValue), gsIniFile)
End Function
Private Function SaveSettingString(sSection As String, sKey As String, sValue As String) As Boolean
    On Error Resume Next
    SaveSettingString = IniPrivateWriteString(sSection, sKey, sValue, gsIniFile)
End Function
Private Function IniPrivateWriteString(sSection As String, sKey As String, 
sValue As String, sIniFile As String) As Boolean
    On Error Resume Next
    If (Len(sKey) > 0) Then
        IniPrivateWriteString = (WritePrivateProfileString(sSection, sKey, sValue, sIniFile) <> 0)
        Else
        '----- Delete all keys in this section
        IniPrivateWriteString = (WritePrivateProfileString(sSection, vbNullString, sValue, sIniFile) <> 0)
    End If
End Function

 

Tip Submitted By: Bob O`Bob


 
Categories: VB

I have developed a global subroutine that will highlight the text of the active control of the active form.

The routine is simple:

Sub Highlight()
    On Error Resume Next
    Dim FRM1 As Form
    Set FRM1 = Screen.ActiveForm
    FRM1.ActiveControl.SelStart = 0
    FRM1.ActiveControl.SelLength = Len(FRM1.ActiveControl)
End Sub

Create a form object by first dimensioning it and setting it to the active form. Next, select the text of the form's active control starting at the left most character to the end of the text.

Use this in the got_focus method of any control that allows text entry such as a text box or a combo box.

Private Sub Text1_GotFocus ()
    Call Highlight
End Sub

That's it! One subroutine call does it all. I put this routine in a global module so all my forms have access to it.

 

Tip Submitted By: Marc Mueller


 
Categories: VB

February 11, 2004
@ 06:05 PM

If you use a higher screen resolution than your users, your forms could be partially hidden or even completely off the screen.

 

There are a few different ways to center your Forms and this tip is by far the best one. It’s very useful because you can center your form over any other form. It’s good to center status Form over your applications mail form instead of the Screen. It just looks nicer. This object can be another Form or the Screen.

Code

Sub CenterForm(objChild As Object, objParent As _
           Object, Optional vLeftTopOffset As Variant, _
           Optional vTopOffset As Variant, Optional vMode _
           As Variant)
     Dim iLeft As Integer
     Dim iTop As Integer
     Dim iMode As Integer
     Dim iLOffset As Integer
     Dim iTOffset As Integer
     Dim I As Integer
     If TypeOf objParent Is SysInfo Then
           iLeft = objParent.WorkAreaLeft + _
                 (objParent.WorkAreaWidth - objChild.Width) / 2
           iTop = objParent.WorkAreaTop + _
                 (objParent.WorkAreaHeight - objChild.Height) / 2
     ElseIf TypeOf objParent Is MDIForm Then
           If objChild.MDIChild = True Then
                 iLeft = (objParent.ScaleWidth - _
                       objChild.Width) / 2
                 iTop = (objParent.ScaleHeight - _
                       objChild.Height) / 2
           Else
                 iLeft = objParent.Left + (objParent.Width - _
                       objChild.Width) / 2
                 iTop = objParent.Top + (objParent.Height - _
                       objChild.Height) / 2
           End If
     ElseIf TypeOf objParent Is Screen Then
           iLeft = (objParent.Width - objChild.Width) / 2
           iTop = (objParent.Height - objChild.Height) / 2
     ElseIf TypeOf objParent Is Form Then
           If objParent.MDIChild = True Then
                 iLeft = objParent.Left + (objParent.Width - _
                       objChild.Width) / 2
                 iTop = objParent.Top + (objParent.Height - _
                       objChild.Height) / 2
                 For I = 0 To Forms.Count - 1
                       If TypeOf Forms(I) Is MDIForm Then
                             iLeft = iLeft + (Forms(I).Width - _
                                   Forms(I).ScaleWidth) / 2 + _
                                   Forms(I).Left
                             iTop = iTop + (Forms(I).Height - _
                                   Forms(I).ScaleHeight) / 2 + _
                                   Forms(I).Top
                             Exit For
                       End If
                 Next I
           Else
                 iLeft = objParent.Left + (objParent.Width - _
                       objChild.Width) / 2
                 iTop = objParent.Top + (objParent.Height - _
                       objChild.Height) / 2
           End If
     Else
           Exit Sub
     End If
     If IsMissing(vMode) Or objChild.MDIChild = True Then
           iMode = vbModeless
     Else
           iMode = Int(vMode)
     End If
     If IsMissing(vLeftTopOffset) Then
           iLOffset = 0
     Else
           iLOffset = Int(vLeftTopOffset)
     End If
     If IsMissing(vTopOffset) Then
           iTOffset = 0
     Else
           iTOffset = Int(vTopOffset)
     End If
     objChild.Move iLeft + iLOffset, iTop + iTOffset
     objChild.Show iMode
End Sub

Examples

Example 1

Center the Form on the Screen.

CenterForm objChild:=Me, objParent:=Screen

Example 2

Center the Form as Modal on the Screen.

CenterForm objChild:=Me, objParent:=Screen, vMode:=vbModal

Example 3

Center the Form on the Windows 95 viewing area (takes into account the TaskBar). This requires that a SysInfo control (which comes with Visual Basic) be placed on the Form.

CenterForm objChild:=Me, objParent:=SysInfo

Example 4

Centers the Form on a Parent Form.

CenterForm objChild:=Me, objParent:=frmMain

You can also use the vTopOffset and vLeftOffset parameters to center the Form and then add or subtract from the X and Y coordinates.

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.

Compatible With Visual Basic 4.0
Parts of this tip were submitted by: C.G. Ouimet


 
Categories: VB

The Timer's "roll-over" point is 24 hours. Since Timer only returns seconds, using GetTickCount also gives you a much higher resolution.

Declare

Declare Function GetTickCount Lib "User"() As Long

Usage

Dim lTimer1 as Long
lTimer1 = GetTickCount()

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.

Compatible With: Visual Basic 3.0, Visual Basic 4.0 16-bit


 
Categories: VB

January 8, 2004
@ 01:21 AM
  • xFile - The filename (it copies from the application's own directory)
  • xDest - The destination directory

Declare

Declare Function GetVersion Lib "Kernel" () As Long
Declare Function GetFileVersionInfo% Lib "VER.DLL" (ByVal lpszFileName$, ByVal handle As Any, ByVal cbBuf&, ByVal lpvData$)

Code

Sub CheckFile(xFile As String, xDest As String)
On Error Resume Next
Dim retS%
Dim retD%
     If Right(xDest, 1) <> "\" Then xDest = xDest + "\"
     Form2.lblSource.Caption = App.Path + "\" + xFile
     Form2.lblDestination.Caption = xDest + xFile
     If Dir(xFile) = "" Then
           FileCopy App.Path + "\" + xFile, xDest + xFile
     Else
           'Check version
           retS% = GetFileVersionInfo(App.Path + "\" + xFile, 0&, 254, version)
           retD% = GetFileVersionInfo(xDest + xFile, 0&, 254, version)
           If retS% >= retD% Then
                 FileCopy App.Path + "\" + xFile, xDest + xFile
           End If
     End If
 
     'Just wait for a sec
     For i = 1 To 1000
           DoEvents
     Next i
 
End Sub

 

Tip Submitted By: Jeff Williams

 


 
Categories: VB

This value gets passed between the database and the application effortlessly. The problem arises when inevitably you want to export the tables into a flat file. It exports just fine except that the Chr$(13) & Chr$(10) get converted back to the effects of an enter keystroke and cause your export file to be out of whack. Then, when you want to import the file into the new (or old) tables, you get import errors galore and the import process halt's.

The work around is not pretty, but it is effective. This is a two stage process with the first stage looking similar to the above tip. First, we have to convert all the Chr$(13) & Chr$(10)'s into something that DOS won't treat any different than a regular character. We cannot use a keyboard character as our token as inevitably, no matter how obscure you make the symbol, someone will type it in. I chose Chr$(6) which is nothing in particular except an unprintable character.

MySet("Comments") = ReplaceEnter(txtComments.Text)
Function ReplaceEnter (ByVal ParseText As String) As String
Dim Offset as Integer, x as integer
    ParseText = LTrim$(Trim$(ParseText))
    x = InStr(ParseText, Chr$(13))
    If x = 0 Then
        ReplaceEnter = ParseText & " " ' Takes care of the Access zero length string problem
        Exit Function
    End If
    Offset = 1
    Do While x > 0
        ParseText = Left$(ParseText, x - 1) & Chr$(6) & Mid$(ParseText, x + 2)
        Offset = x + 1
        x = InStr(Offset, ParseText, Chr$(13))
    Loop
    ReplaceEnter = ParseText
End Function

So, we do the update on the database but there comes a time when you want to redisplay the contents of the field. Now, you have to reverse the process and convert the Chr$(6)'s into Chr$(13) & Chr$(10)'s:

txtComments.Text = ReplaceChr6(MySet("Comments") & "")
Function ReplaceChr6 (ByVal ParseText As String) As String
Dim Offset as Integer, x as integer
    x = InStr(ParseText, Chr$(6))
    If x = 0 Then
        ReplaceChr6 = ParseText
        Exit Function
    End If
    Offset = 1
    Do While x > 0
        ParseText = Left$(ParseText, x - 1) & Chr$(13) & Chr$(10) & Mid$(ParseText, x + 1)
        Offset = x
        x = InStr(Offset, ParseText, Chr$(6))
    Loop
    ReplaceChr6 = ParseText
End Function

As I said at the beginning, it isn't pretty, but it does get you around a problem you may not be aware of until your user decides to export the file so he/ she can do something with it.

 

Tip Submitted By: Paul A. Birkbeck


 
Categories: VB

January 8, 2004
@ 01:13 AM

The best way to deal with this problem is to use the built-in & operator to concatenate a blank string to each field as you read it. Concatenate 0 for numeric fields.

Sample Code

Dim dbBiblio As Database
Dim rsData As Recordset
Dim sYear As String
Dim sHireDate As Date
Dim lReports As Long
  Set dbBiblio = OpenDatabase("Northwind.mdb")
  Set rsData = dbBiblio.OpenRecordset("Employees")
  'Concatenate empty string ("") here with null values
  sYear = rsData![Title] & vbNullString
  'Concatenate zero so it does not error
  sHireDate = rsData![HireDate] & 0
  lReports = rsData![ReportsTo] & 0


 


 
Categories: VB

Although only one function is presented here, you may notice a gold mine of other associated and required functions that may be used for a multitude of purposes.

Code

Public Function GetUniqueFileName(ThisEXT As String, Optional ThisPath As String) As String
    Dim retval As String, varTmp As String
    varTmp = NormalizePath(GetTEMPdir(True))
    Do
        If LTrim(RTrim(ThisPath)) <> "" Then
            If DirExistCreate(ThisPath, False) Then
                retval = NormalizePath(ThisPath) & UniqueFileName & "." & ThisEXT
            ElseIf DirExistCreate(varTmp, True) Then
                retval = varTmp & UniqueFileName
            End If
        ElseIf DirExistCreate(varTmp, True) Then
            retval = varTmp & UniqueFileName
        End If
           DoEvents      'give someone else a chance...
    Loop While FindFile(retval)
    GetUniqueFileName = retval
End Function
Public Function UniqueFileName() As String
    On Local Error GoTo ufnError
    Dim retval As String
    
    'This example uses the Rnd function to generate a random integer value from 10000 to 32000.
    retval = "~" & Str(Int((32000 * Rnd) + 10000))
ufnOut
    UniqueFileName = retval
    Exit Function
ufnError
    retval = ""
    Resume ufnOut
End Function
Public Function GetTEMPdir(CreateOne As Boolean, Optional tVar As String) As String
    Dim wTmp As String
    On Local Error Resume Next
    
    wTmp = Environ$("TEMP")
    If wTmp = "" Then
        If CreateOne Then
            If LTrim(RTrim(tVar)) = "" Then tVar = "C\TEMP"
            MkDir tVar
            wTmp = tVar
        End If
    End If
    
    wTmp = NormalizePath(wTmp)
    GetTEMPdir = wTmp
 
End Function
Public Function FindFile(ThisFile As String, Optional SetAttribute As Variant) As Boolean
    On Local Error GoTo ffError
    Dim retval As Boolean, tAttr As Integer
    tAttr = vbNormal        'tattr=0
    If Trim(ThisFile) = "" Then
        Exit Function
    End If
    Do While tAttr <= 39
        If Len(Dir(ThisFile, tAttr)) > 0 Then
            If Not IsMissing(SetAttribute) Then
                SetAttr ThisFile, CInt(SetAttribute)
            End If
            retval = True
            Exit Do
        Else
            tAttr = tAttr + 1
            '1 -> 7 valid for files
            If tAttr = 8 Then tAttr = 32
            '32 -> 39 valid for files
            If tAttr = 40 Then
                retval = False
                Exit Do
            End If
        End If
    Loop
ffOut
    FindFile = retval
    Exit Function
ffError
    retval = False
    Msg = "Find File Error " & Error(Err) & vbCrLf
    Msg = Msg & ThisFile
    MsgBox Msg, vbExclamation, App.EXEName
    Err = 0
    Resume ffOut
End Function
Public Function DirExistCreate(ThisDir As String, Optional CreateIt As Variant) As Boolean
    On Local Error GoTo DEerror
    Dim Retval As Boolean, varCreateIt As Boolean
    Dim ThisTest As String, c As Integer, p As String, i As Integer
    Dim b As Integer
TestDiragain
    If Trim(ThisDir) <> "" Then
        If Not IsMissing(CreateIt) Then varCreateIt = CBool(CreateIt)
        
        If Len(Dir(ThisDir, 16)) > 0 Then
            Retval = True
        Else
            'does not exist so create it by parsing
            ThisDir = NormalizePath(ThisDir)
            c = InStr(ThisDir, "\")
            If c <= 0 Then b = 1 Else b = c + 2
            For i = b To Len(ThisDir)
                p = Mid(ThisDir, i, 1)
                If p = "\" Then
                    ThisTest = Left(ThisDir, i - 1)
                    If Len(Dir(ThisTest, 16)) <= 0 Then
                        MkDir ThisTest
                    End If
                End If
            Next
            GoTo TestDiragain
        End If
    End If
DEout
    DirExistCreate = Retval
    Exit Function
DEerror
    Retval = False
    LogError Err, "Unable to create directory " & ThisDir
    Err = 0
    Resume DEout
End Function
Public Function NormalizePath(ThisPath As String) As String
    If Right(ThisPath, 1) <> vbNullChar Then
        If Right(ThisPath, 1) <> "\" Then
            NormalizePath = ThisPath & "\"
        Else
            NormalizePath = ThisPath
        End If
    Else
        NormalizePath = ThisPath
    End If
End Function

 

Tip Submitted By: Dick Wilson


 
Categories: VB

January 8, 2004
@ 01:08 AM

Supposedly, RecordCount is set correctly when you first open a snapshot, but the ListBox test showed otherwise.
Try it yourself. Here is the solution code with my debug lines commented out.

Sub CopyRows () 
Dim i As Integer 
Dim db As Database
Dim snap As Snapshot
Dim tbl As Table
Dim wSQL As String
    Set db = OpenDatabase("MYDATA.MDB", False, False) 
    Set tbl = db.OpenTable("Table1")
    ' select the rows to be copied into a snapshot object 
    'List1.Clear 'Mark's debug code
    wSQL = "Select * from Table1 where Field1 = 'A'" 
    'I also changed your SQL statement a 
    'little, removed characters I don't use, but I don't
    'think it made any difference.
    Set snap = db.CreateSnapshot(wSQL) 
    snap.MoveLast '<===== MoveLast initializes RecordCount of snap
    snap.MoveFirst '<===== Need to MoveFirst
    'List1.AddItem snap.RecordCount 'Mark's debug code 
    'List1.AddItem "**" 'Mark's debug code
    ' loop through all rows in the snapshot 
    Do Until snap.EOF
        tbl.AddNew
        ' copy each field in the snapshot row to the table row
        For i = 0 To snap.Fields.Count - 1
            tbl.Fields(i).Value = snap.Fields(i).Value
        Next i
        ' change the value of the other field
        tbl.Fields("Field2").Value = "B"
        ' insert the new row into the table
        tbl.Update
        ' Ack! Here's the problem. This "tbl.Update" also is
        ' updating the contents of the snapshot. Meaning the
        ' "snap.MoveNext" will never get to EOF!
        'List1.AddItem snap.RecordCount 'Mark's debug code
        'List1.Refresh 'Mark's debug code
        'DoEvents 'Mark's debug code
        snap.MoveNext 
    Loop
    ' close everything 
    snap.Close 
    tbl.Close
    db.Close
End Sub

 

Tip By: Kyle Lutes


 
Categories: VB

January 8, 2004
@ 01:07 AM

This prompted me to do a little digging and I found out that it couldn't access the file to check because it was open in MS Access 2. As a result I rewrote my routine to take into account file sharing, but it struck me that I could use the old routine to check if a database file was in use.

Some routines that check for the existence of a file might not work with a Microsoft Access 2.0 database that is in use. To check for the file, you must open it as shared. This could be used to check a database file before it’s compacted or repaired.

Function FileExists(Filename As String) As Integer
     On Error Resume Next
     Open Filename For Input Access Read Shared As #1
     FileExists = (Err = 0)
     Close #1
End Function

Also, you can use the following code to check to see if a database file is in use.

Function DBFileInUse(Filename As String) As Integer
     On Error Resume Next
     Open Filename For Input As #1
     DBFileInUse = (Err <> 0)
     Close #1
End Function

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.
Parts of this tip was submitted by: Grahm Jones


 
Categories: VB

January 8, 2004
@ 01:04 AM

Rather than looping manually through every TextBox on the Form, I came up with the following: A function with the Form as a single argument. Loop through each control on the Form, (using "For Each Control etc") and if it's a TextBox which is empty, it returns Err.Number = 0. If this is true, I change the BackColor of the offending TextBox to light pink, and the function returns True. (If the TextBox is not empty, and it's BackColor is light pink, I return the BackColor to white. One can store the original color and restore it.) Then call Err. Clear, and continue in the loop. All TextBoxes which are empty will show up as light pink.

To test, create a Form with several TextBoxes on it; their names are immaterial, and they can even be in some container, like a Frame. Create a Command Button, named TestEmpty. Following is the code:

Private Sub TestEmpty_Click()
  If IsEmpty(Me) Then
    MsgBox "Some textboxes are still empty"
  End If
End Sub
Function IsEmpty(Frm As Form) As Boolean
Dim tmpControl As Control
  On Error Resume Next
  IsEmpty = False
  For Each tmpControl In Frm.Controls
    If Trim(tmpControl.Text) = "" Then
      If Err.Number = 0 Then
        IsEmpty = True
        tmpControl.BackColor = &HFFC0FF 'light pink
      End If
      Err.Clear
    Else
      If tmpControl.BackColor = &HFFC0FF Then
        tmpControl.BackColor = QBColor(15) 'White
      End If
    End If
  Next tmpControl
End Function

Run the program. Fill in some of the TextBoxes, and click on the Command Button, You will see the empty TextBoxes BackColor change to light pink. If you fill these in and click again, their BackColor will change to white.  Note: If the procedure is in a Module, then the argument is the Form name.

 

Tip Submitted By: Yehuda Hilewitz


 
Categories: VB

December 11, 2003
@ 03:15 AM

What happened was that I had objects pointing to other objects. To allow navigation back, I had also included pointers back to the 'owner' of the objects.

This last thing meant that the objects never got freed, because there was always something referencing them: the members were referenced by the parent, and the parents were referenced by the members. No matter if the caller set the pointer to the top-object in the hierarchy to nothing, the hierarchy remained in memory forever.

Another effect was, that the Class_Terminate event for the objects was never called, and that is were the objects' contents are written to the data base.

The tip is: be careful with references between objects. If you have references like the ones described above, ensure that you have a method in the class that frees all cross-references. Otherwise objects never get freed, and their Class_Terminate event will never be called.

This may sound like a trivial something, but it took me quite some time to figure out why my application was never releasing its memory.

 

Tip Submitted By: Marjo van Diem


 
Categories: VB

I have written a simple function called NeedsFiltering which I use to determine if a block of text contains one or more search characters. The function uses the Like operator to determine if one or more characters in the specified range exist in the input string. If the routine returns False, the text block can be "passed through" without the need for a more time-consuming search.

Function NeedsFiltering (szInput As String) As Integer
Dim szLikeExpr1 As String
Dim szLikeExpr2 As String
szLikeExpr1 = "*[" & Chr(0) & "-" & Chr(8) & "]*"
szLikeExpr2 = "*[" & Chr(128) & "-" & Chr(255) & "]*"
NeedsFiltering = szInput Like szLikeExpr1 Or szInput Like szLikeExpr2
End Function

The "*" in the pattern expressions means "zero or more characters." Therefore, the Like operator will return True if one or more characters in the specified range exist anywhere in the input string. I have used this routine quite successfully in a character filtering application which filters out control and extended ANSI characters (0-8,128-255) from an input file, and places the filtered text in a temporary file. The amount of savings depends upon the number and location of characters in the input string that one wishes to filter out.

 

Tip Submitted By: Barth Riley


 
Categories: VB

These files are used to register you program with the Registration Database. The problem is that the files are not needed! When you compile your OLE server, VB compiles code into it that will do this for you! The problem is that MS does not make this easy for you to find. Because the want you to use the Setup Wizard (anyone that knows me, knows how I feel about the Setup Wizard).

To register your program, simply run your server with the following command line parameter.

MYOLESVR.EXE /REGSERVER 

Your program won't start, it will just register itself. Just make sure you do this after all the runtime files have been installed. You can also un-register your server by using the /UNREGSERVER parameter.

 

Tip By: David McCarter


 
Categories: VB

December 11, 2003
@ 03:09 AM

Run Programs During Windows StartUp

Find the key:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run

Add a new String Value. Give the value any name, usually the name of the program. Then double-click on it and type in the path, file name and any command line parameters. For example:

Value Name = Notepad
Value Data = c:\windows\notepad.exe

Run Programs When Loading A User

Do the same as listed above, but use the key:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run 

 

Tip Submitted By: Yatir Halevi


 
Categories: VB

December 11, 2003
@ 02:57 AM

These properties are usually ones that cause the control to re-paint, like Enabled, Visible, Caption and Text. The flicker can be easily reduced by not setting a property when it is already set. For instance, if the Enabled property is set to True why set it to True again?

Enable/Disable Routine

Use this to enable or disable a control.

Sub SetEnabled (ctrlIn as Control, bSetting as Integer)
     If ctrlIn.Enabled <> bSetting Then
           ctrlIn.Enabled = bSetting
     End If
End Sub

Caption Routine

Use this to change a Caption property.

Sub SetLabel (ctrlIn as Control, sNewText as String)
     If ctrlIn.Caption <> sNewText Then
           ctrlIn.Caption = sNewText
     End If
End Sub

You can make as many of these types of routines as you like. Any property that affects a controls appearance, such as colors, fonts and text, would be a good prospect.

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.
Parts of this tip was submitted by: David McCarter


 
Categories: VB

In order to setup the camera, it is necessary to have the following:

  1. Not allow any other windows to be running on top of the application. (On Top is optional)
  2. Not allow the application to be re-sized.
  3. Not allow the application to be moved.
  4. Not have Minimize/Maximize buttons. (Minimize button is optional)
  5. Have a visible menu bar available.

Seems like Windows (VB?) allows you to either have a menu with a title bar that can be moved, or no menu with a title bar that does not move. I could not get a maximized window with a menu bar, that was not moveable. Selecting various combinations of the Maximize and Minimize buttons did not help. Usually, double-clicking on the title bar restored the window to its original size and you could then drag it around with the mouse.

The code below allows you to create a Window which is OnTop, or normal, depending on what your application is. It does not respond when the title bar is double clicked for maximize/restore. A visible menu bar is also available.

Form Properties necessary for this implementation:

---------------------------------------------------------------------------

MaxButton False Disabled in the code

Minbutton True/False Depending on the needs of the application

ControlBox True Needed for maximize/restore to work

WindowState Maximized To maximize the form on loading

BorderStyle 0-None Disables Alt+F4 for closing application

BorderStyle 1-Fixed Single Worked best for this application

---------------------------------------------------------------------------

BorderStyle of 2-Sizable is not a good choice, because the frame of the window shows up when you double-click on the title bar.

Declare Sub SetWindowPos Lib "User" (ByVal hWnd As Integer, ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wflags As Integer)
Declare Function GetSystemMenu Lib "User" (ByVal hWnd As Integer, ByVal bRevert As Integer) As Integer
Declare Function DeleteMenu Lib "User" (ByVal hMenu As Integer, ByVal iditem As Integer, ByVal wflags As Integer) As Integer
Const SC_SIZE = &HF000
Const SC_MOVE = &HF010
Const MF_BYCOMMAND = &H0
Sub Form_Load ()
Dim hMenu, iSuccess As Integer
'-------------------------------------------------------
' This will not allow the window to be moved or re-sized
'-------------------------------------------------------
hMenu = GetSystemMenu(Me.hWnd, 0)
iSuccess = DeleteMenu(hMenu, SC_SIZE, MF_BYCOMMAND)
iSuccess = DeleteMenu(hMenu, SC_MOVE, MF_BYCOMMAND)
'-----------------------------------------------------------------------
' This will set the Window to the size of the screen no matter what it 
' is. If the user tries to double click the window, it will appear to 
' not do anything, though it is in restored mode.
'-----------------------------------------------------------------------
Me.Height = Screen.Height + 45
Me.Width = Screen.Width + 60
Me.Left = -15
Me.Top = -15
'--------------------------------------------
' This will make the window always be visible
'--------------------------------------------
SetWindowPos Me.hWnd, -1, 0, 0, 0, 0, &H50
'----------------------------------------------------------------
' This will remove the always visible attribute, use where needed
'----------------------------------------------------------------
'SetWindowPos Me.hWnd, -2, 0, 0, 0, 0, &H50
End Sub

 

Tip Submitted By: Sunny Jamshedji


 
Categories: VB

December 11, 2003
@ 02:50 AM

declare the following in a BAS file:

Declare Function GETDRIVETYPE Lib "Kernel" (ByVal nDrive As Integer) As Integer

You must pass this function the drive number, not a drive letter. Drive numbers always start a 0. For instance, drive A: is drive #0, Drive C: is drive #2.

DRIVETYPE = GETDRIVETYPE(DRIVENUM)

This function returns a 2 for removable drives, 3 for fixed drives or 4 for remote drives. This function will return a 0 if it is passed a drive number that does not exist on the system.

 

Submitted By: David McCarter


 
Categories: VB

It relies on the fact that VB removes Debug.Print statements from the compiled EXE. Use Debug.Print to print something that will cause an error. Divide by zero is simple enough.

Public Function IsCodeCompiled() As Boolean
  On Error GoTo ErrorHandler
  Debug.Print 1 / 0
  IsCodeCompiled = True
  Exit Function
ErrorHandler:
  IsCodeCompiled = False
  Exit Function
End Function


Tip Submitted By: David Hay


 
Categories: VB

Microsoft in their invariable wisdom somehow chose to make the manual DRAG function operate rather counter-intuitively. That is, when an item is dropped, the Mouse_Up function for the initiating subroutine is NOT called! This makes it very difficult to detect unsuccessful drops. Detecting an unsuccessful drop can be of importance when you need to update animation that may be in progress to support the Drag-Drop Sequence. To this end, this application note will suggest a very simple method for detecting the End_Of_Drag sequence. This technique work whether the operation was successful or not. One of its major benefits of this technique is that it does not require any custom control programming!

The method involves generating the proper Mouse_Up event at the end of the drag operation. This can be accomplished using a single Windows API call and a normal Visual Basic Timer. The sequence is:

  1. Enable the timer in the Mouse_Down sequence after any animation steps but just before starting the manual Drag sequence.
  2. On each timer tick look at the mouse button to determine if the operator has released.

The steps are pretty simple:

'**** In a .BAS form (as you will probably use this elsewhere) 
Declare the API Function Declare Function GetKeyState Lib "User" (ByVal nKey As Integer) As Integer
'**** In the code sequence for the control of Interest 
Sub Text2_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
    FileCabinet = FileOpenIcon ' *** Animation, transfer image from one Box to another 
    Text2.DragIcon = AnyIcon ' *** Set up the Drag Icon
    Timer1.Enabled = True ' *** Enable the Timer (Put on the form at Design Time)
    Text2.Drag 1 '*** Start the manual Drag Operation
End Sub 
'***** In the form Timer Event Code Section 
Sub Timer1_Timer ()
    K% = 1 '*** Set the Virtual Scan code for the Mouse Left Button 
    I = GetKeyState(K%) '*** Get the Key state
    I = I And (Not 1) '*** Mask off the unimportant Bits
    If I = 0 Then '*** Check to see if the operator has released the button
        FileCabinet = FileClosed '*** Finish animation, by transferring images
        Timer1.Enabled = 0 '*** Turn off the timer so this event will not be triggered
    End If
End Sub

 

Tip Submitted By: Michael D. Strathman


 
Categories: VB

December 11, 2003
@ 02:18 AM

The CheckSum32 function I propose calculates the 32 bits checksum of a string, using a currency variable to avoid overflow errors.

Function CheckSum32(A$) As Long
'Calculates the 32bits checksum of a string
Const MAXULONG = 4294967295# 'Max unsigned long integer
Const MAXLONG = 2147483647 'Max signed long integer
Dim Sum As Currency 'Currency variable type to avoid overflow
Dim i As Integer 'Source string character counter
Dim j As Integer 'Checksum byte counter (byte # = 0..3)
    j = 0
    For i = 1 To Len(A$)
        'Add byte at relevant position in sum
        Sum = Sum + (Asc(Mid$(A$, i, 1)) * 256 ^ j)
        'remove 33d bit if set
        If Sum > MAXULONG Then Sum = Sum - (MAXULONG + 1)
            'skip to next byte in sum
        If j < 3 Then
            j = j + 1
            Else
              j = 0
        End If
    Next
    'Conversion for signed long integer result
    If Sum > MAXLONG Then Sum = Sum - (MAXULONG + 1)
    CheckSum32 = Sum
End Function

 

Tip Submitted By: Marc Lajus


 
Categories: VB

December 11, 2003
@ 02:15 AM

You can turn off the minimize and maximize menu options by changing properties, but what if you're doing something critical in your VB program that should not be interrupted and you need to remove the "close" option?

Make the following declares

Declare Function GetSystemMenu Lib "User" (ByVal hWnd As Integer, ByVal bRevert As Integer) As Integer
Declare Function RemoveMenu Lib "User" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
Global Const MF_BYPOSITION=&H400

Use the following in your code to remove the "close" option:

SystemMenu% = GetSystemMenu (hWnd, 0) 
Res% = RemoveMenu(SystemMenu%,6, MF_BYPOSITION)
Res% = RemoveMenu(SystemMenu%,6, MF_BYPOSITION) 'also remove the separator line

Check out the GetMenuID and InsertMenu API functions to do more complicated tasks.


 


 
Categories: VB

Also, if data is entered into a database that has errors, that data (and more) might be loss forever.

Below is a Function that can be used every time a program using an Access database is loaded. This code will not catch 100% of the errors -- I have yet to discover any methods that do. In fact, I've had corrupted databases and this code did not even tell me there was an error.

This Function returns a 0 if no errors were found, or, the error code if there were.

Function iCheckMDB (sDatabase As String) As Integer
     Dim bDidRetry As Integer
     Dim dbTest As Database
 
     On Error Resume Next
 
     bDidRetry = False
     iCheckMDB = 0
 
DoOpenDatabase:
     Err = 0
 
     Set dbTest = OpenDatabase(sDatabase)
 
     If Err = 3043 Then
           'Disk or Network Error
           iCheckMDB = Err
           Exit Function
     ElseIf Err = 3049 Then
           'Database corrupted
           If Not bDidRetry Then
                 'Try to repair database
                 RepairDatabase sDatabase
                 bDidRetry = True
                 GoTo DoOpenDatabase
           Else
                 iCheckMDB = Err
                 Exit Function
           End If
     End If
End Function

NOTE: Remember to run this code before you use the database or load any forms with data controls on them.

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.
Parts of this tip was submitted by: David McCarter


 
Categories: VB

August 30, 2003
@ 09:56 PM

Declare

Declare Function ExitWindows Lib "User" (ByVal RestartCode As Long, _
  ByVal DOSReturnCode As Integer) As Integer

Code

Sub ExitWin (ByVal nExitOption As Integer) Dim n As Integer 
n = MsgBox("Do you really want to exit Windows?", 36, "Exiting") 
     If n = 7 Then Exit Sub 'User chose NO 
     Select Case nExitOption 
           Case 1
                 n = ExitWindows(67, 0) 'reboot the computer
           Case 2
                 n = ExitWindows(66, 0) 'restart Windows
           Case 3
                 n = ExitWindows(0, 0) 'exit Windows
     End Select
End Sub

 

Tip By: Brian Simper


 
Categories: VB

August 30, 2003
@ 09:52 PM

Some might test for Null by using

If sSomeString <> "" Then

or

If Len(sSomeString) = 0 Then

While these might work, it’s 50% faster to use

If IsNull(sSomeString) Then

Check out the other "Is" operators, IsDate, IsEmpty and IsNumeric. Use the correct operator for the job you have to do.

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.
Part of this tip was submitted by: Bobby Holstein


 
Categories: VB

August 30, 2003
@ 09:50 PM

BitBlt API definitions

  • lFrmHwnd - window handle of the form
  • iCol - pixel column
  • iRow - pixel row
  • iPicWidth - width of picture control
  • iPicHeight - height of picture control
  • lPicHwnd - window handle of the picture control
  • 0, 0 - X and Y coordinates to start in upper left corner of the form
  • SRCCOPY - Copies the picture control rectangle directly to the form rectangle.

Declare

Public Const SRCCOPY = &HCC0020
Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, _
  ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, _
  ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

 

Create a form and name it frmTileBmp. Add a Command button and name it cmdSwitch. Add a Picture control and name it picTile. Be sure to insert a BMP into this picture box.

Paste the rest of this code into the declarations section of the Form.

Declare the following in the General section of your Form:

Private lMaxHeight As Long ' Maximum height of the form
Private lMaxWidth As Long ' Maximum width of the form
Private iPicHeight As Integer ' Maximum height of the picture box
Private iPicWidth As Integer ' Maximum width of the picture box
Private Complete As Boolean ' Completely cover the form
Private LeftSide As Boolean ' Tile down left side of form
Private AcrossTop As Boolean ' Tile across top of form

 

Code

Private Sub cmdSwitch_Click()
' ----------------------------------------------------------
' Define local variable. First time through VB initializes
' to zero.
' ----------------------------------------------------------
Static iCnt As Integer
' ----------------------------------------------------------
' Toggle between the way the form is painted
' ----------------------------------------------------------
If iCnt = 0 Then
cmdSwitch.Caption = "To tile down left side only, click here"
Complete = True
AcrossTop = False
LeftSide = False
ElseIf iCnt = 1 Then
cmdSwitch.Caption = "To tile across top of form, click here"
Complete = False
AcrossTop = False
LeftSide = True
ElseIf iCnt = 2 Then
cmdSwitch.Caption = "To tile across complete form, click here"
Complete = False
AcrossTop = True
LeftSide = False
End If
' ----------------------------------------------------------
' Increment the counter. Reset when we reach 3.
' ----------------------------------------------------------
iCnt = iCnt + 1
If iCnt = 3 Then iCnt = 0
' ----------------------------------------------------------
' By refreshing the form the Form_Paint event will be
' activated.
' ----------------------------------------------------------
frmTileBmp.Refresh
End Sub
 
Private Sub Form_Load()
' ----------------------------------------------------------
' Set the properties for the picture box
' Use the picture control properties window
' to set the following:
' .AutoRedraw = True ' Turn on the Redraw mode
' .Appearance = 0 ' Flat
' .BorderStyle = 0 ' No borders
' .ScaleMode = 3 ' Pixel mode
' ----------------------------------------------------------
With picTile
.AutoSize = True ' Autosize the box to the BMP
iPicWidth = .ScaleWidth ' Width of picture box
iPicHeight = .ScaleHeight ' Height of picture box
.Visible = False ' Start off invisible
End With
' ----------------------------------------------------------
' Set the toggle and update the caption on the command
' button.
' ----------------------------------------------------------
Complete = False
AcrossTop = False
LeftSide = False
cmdSwitch_Click
' ----------------------------------------------------------
' used for color when testing the tiling down the left side
' ----------------------------------------------------------
With frmTileBmp
.BackColor = &HFFFFC0 ' Light blue
.Show vbModeless
.Refresh
End With
End Sub
Private Sub Form_Paint()
' ----------------------------------------------------------
' This event is executed whenever the form is Refreshed
' moved, or Resized.
'
' BitBlt API definitions (Understandable terminology)
'
' lFrmHwnd - window handle of the form
' iCol - pixel column
' iRow - pixel row
' iPicWidth - width of picture control
' iPicHeight - height of picture control
' lPicHwnd - window handle of the picture control
' 0, 0 - X and Y coordinates to start in upper
' left corner of the form
' SRCCOPY - Copies the picture control rectangle
' directly to the form rectangle.
' ----------------------------------------------------------
' ----------------------------------------------------------
' Define local variables
' ----------------------------------------------------------
Dim lPicHwnd As Long ' picture box handle
Dim lFrmHwnd As Long ' form handle
Dim iCol As Integer ' Column on the form
Dim iRow As Integer ' Row on the form
Dim lRet As Long ' Return value from API call
' ----------------------------------------------------------
' Initialize the variables
' ----------------------------------------------------------
lPicHwnd = picTile.hDC
lFrmHwnd = hDC
' ----------------------------------------------------------
' Paint the screen. To paint just down the left side of the
' form, place a comment mark in front of "For iCol" and the
' corresponding "Next". Do not comment out the BitBlt call.
' in this demo, we use a switch.
' ----------------------------------------------------------
If Complete Then
For iRow = 0 To lMaxHeight Step iPicHeight
' paint each column in a row before going to the
' next row.
For iCol = 0 To lMaxWidth Step iPicWidth
' Returns non-zero if successful
lRet = BitBlt(lFrmHwnd, iCol, iRow, iPicWidth, iPicHeight, lPicHwnd, 0, 0, SRCCOPY)
Next
Next
ElseIf LeftSide Then
For iRow = 0 To lMaxHeight Step iPicHeight
' Returns non-zero if successful
lRet = BitBlt(lFrmHwnd, iCol, iRow, iPicWidth, iPicHeight, lPicHwnd, 0, 0, SRCCOPY)
Next
ElseIf AcrossTop Then
For iCol = 0 To lMaxWidth Step iPicWidth
' Returns non-zero if successful
lRet = BitBlt(lFrmHwnd, iCol, iRow, iPicWidth, iPicHeight, lPicHwnd, 0, 0, SRCCOPY)
Next
End If
End Sub
 
Private Sub Form_Resize()
' ----------------------------------------------------------
' If the form is resized, get the new measurements
' ----------------------------------------------------------
lMaxHeight = Height \ Screen.TwipsPerPixelY
lMaxWidth = Width \ Screen.TwipsPerPixelX
End Sub
 
Private Sub Form_Unload(Cancel As Integer)
' ----------------------------------------------------------
' unload the form completely and free up memory
' ----------------------------------------------------------
' Deactivates the form
Unload frmTileBmp
' Free memory by removing the form object from memory
Set frmTileBmp = Nothing
' empties all variables in memory and terminates application
End
End Sub

 

Tip Submitted By: Kenneth Ives

 

 

 

 

 

 

 

 


 
Categories: VB

This file is in the Windows NT directory for the emulator, not in the emulator file object store.

 

The empfile utility allows you to do several really neat things:

  • Synchronize a tree with the object store
  • Copy a file on the PC to a directory in the emulators file object store
  • Copy a file from the emulator file object store to the PC
  • Check to see if a file is in the emulators file object store
  • Delete a file from the emulator file object store
  • Run a file in the emulator object store

I recently found this very useful for installing a control into the emulator from my controls setup program. I also used it to register the control in the emulator by running the Windows CE RegSvrCe.exe.

The command line options for empfile are as follows:

-c SOURCE DEST ('put' or 'get' a file from object store)

-d FILE (delete a file on object store)

-e FILE (check to see if a file exists on object store)

-s (synchronize object store with wce\emul\PLATFORM\ tree)

-r MYAPP ARGS (run myapp.exe in the object store with

arguments ARGS)

Here are some examples of some uses for this:

EMPFILE -s

(Synchronize wce\emul\PLATFORM\ tree with object store)

EMPFILE -c c:\test.exe wce:windows\test.exe

(Copy c:\test.exe to object store's Windows\ directory)

EMPFILE -c wce:test.exe c:\test.exe

(Copy test.exe from object store to c:\)

EMPFILE -e windows\text.exe

(verify that test.exe Exists in object store's Windows\

directory)

EMPFILE -d test.txt

(Delete test.txt from object store root directory)

EMPFILE -r regsvrce.exe \windows\atlce.dll

(Run regsvrce.exe from object store with parameter

"\Windows\AtlCe.Dll" to register the DLL)

Notes:

1) "PLATFORM" is the platform selected in the Emulation Settings dialog.

2) Wildcards (eg. '*.EXE') are not supported.

3) Specify the fully qualified path name for the Copy command.

Some applications for this might be to copy data files to and from the emulator for use with an application that you might be programming. It is also useful for installing controls into the emulator so that you do not need to do so manually with the Control Manager.

 

Tip Submitted By: By: Mike Dixon


 
Categories: VB

August 30, 2003
@ 09:41 PM

This is not very secure... so we need to verify that the user sending the message is the one who logged into Win95 or WinNT.

I searched and searched on how to do this, with no luck. After posting this message on a new group, I was sent the answer and it's surprising easy! It's too bad that Microsoft has to make it so hard for use to find.

Win95

Private Declare Function WNetVerifyPassword Lib "mpr.dll" Alias _
"WNetVerifyPasswordA" (ByVal lpszPassword As String, _
ByRef pfMatch As Long) As Long
 
Function VerifyPassWin95(sPassword As String) As Boolean
Dim lRetVal As Long
  If (WNetVerifyPassword(sPassword, lRetVal)) <> 0 Then
    MsgBox "VerifyPassWin95: Application Error"
    Else
      If lRetVal <> 0 Then
        VerifyPassWin95 = True
        Else
          VerifyPassWin95 = False
      End If
  End If
End Function

 

Tip Submitted By: David McCarter
Code By: Jeff Hong YAN

 


 
Categories: VB

August 30, 2003
@ 09:37 PM

Below is a table that list the minimum files required for VB5 programs to operate correctly. You will need to add to this list if you use any add-on components, DLL's, database drivers etc. As you can see from the list, there are many OLE files required. I've also read many messages that stated "why do I need to distribute OLE files when my program does not use OLE". Your program does use OLE, because VB5 uses it internally.

VB5 Run Time Files

File Name

Date

Size

Source Directory

Install Settings

MSVBVM50.DLL 1/24/97 1,334,032 WINDOWS\SYSTEM Version Check
Win95 Shared DLL
Self Register
STDOLE2.TLB 9/30/96 16,896 VB\SETUPkKIT\KITFIL32\SYS32 Version Check
TLB Register
OLEAUT32.DLL 11/6/96 491,792 WINDOWS\SYSTEM Version Check
Win95 Shared DLL
Self Register
OLEPRO32.DLL 1/15/97 32,528 WINDOWS\SYSTEM Version Check
Win95 Shared DLL
Self Register
ASYCFILT.DLL 1/11/97 120,592 WINDOWS\SYSTEM Version Check
Win95 Shared DLL
Self Register
CTL3D32.DLL 5/7/96 26,624 WINDOWS\SYSTEM Version Check
COMCAT.DLL 10/31/96 22,288 WINDOWS\SYSTEM Version Check
Win95 Shared DLL
Self Register

Disk Space Required To Install Files: 2,165,344


 
Categories: VB

If App.PrevInstance Then
     sMsg = App.EXEName & " already running! "
     MsgBox sMsg, 4112
     End
End If

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.


 
Categories: VB

August 30, 2003
@ 09:21 PM

0      The operation completed successfully.

1      Incorrect function.

2      The system cannot find the file specified.

3      The system cannot find the path specified.

4      The system cannot open the file.

5      Access is denied.

6      The handle is invalid.

7      The storage control blocks were destroyed.

8      Not enough storage is available to process this command.

9      The storage control block address is invalid.

10      The environment is incorrect.

11      An attempt was made to load a program with an incorrect format.

12      The access code is invalid.

13      The data is invalid.

14      Not enough storage is available to complete this operation.

15      The system cannot find the drive specified.

16      The directory cannot be removed.

17      The system cannot move the file to a different disk drive.

18      There are no more files.

19      The media is write protected.

20      The system cannot find the device specified.

21      The device is not ready.

22      The device does not recognize the command.

23      Data error (cyclic redundancy check)

24      The program issued a command but the command length is incorrect.

25      The drive cannot locate a specific area or track on the disk.

26      The specified disk or diskette cannot be accessed.

27      The drive cannot find the sector requested.

28      The printer is out of paper.

29      The system cannot write to the specified device.

30      The system cannot read from the specified device.

31      A device attached to the system is not functioning.

32      The process cannot access the file because it is being used by another process.

33      The process cannot access the file because another process has locked a portion of the file.

34      The wrong diskette is in the drive. Insert %2 (Volume Serial Number: %3) into drive %1.

36      Too many files opened for sharing.

38      Reached end of file.

39      The disk is full.

50      The network request is not supported.

51      The remote computer is not available.

52      A duplicate name exists on the network.

53      The network path was not found.

54      The network is busy.

55      The specified network resource or device is no longer available.

56      The network BIOS command limit has been reached.

57      A network adapter hardware error occurred.

58      The specified server cannot perform the requested operation.

59      An unexpected network error occurred.

60      The remote adapter is not compatible.

61      The printer queue is full.

62      Space to store the file waiting to be printed is not available on the server.

63      Your file waiting to be printed was deleted.

64      The specified network name is no longer available.

65      Network access is denied.

66      The network resource type is not correct.

67      The network name cannot be found.

68      The name limit for the local computer network adapter card was exceeded.

69      The network BIOS session limit was exceeded.

70      The remote server has been paused or is in the process of being started.

71      No more connections can be made to this remote computer at this time because there are already as many connections as the computer can accept.

72      The specified printer or disk device has been paused.

80      The file exists.

82      The directory or file cannot be created.

83      Fail on INT 24

84      Storage to process this request is not available.

85      The local device name is already in use.

86      The specified network password is not correct.

87      The parameter is incorrect.

88      A write fault occurred on the network.

89      The system cannot start another process at this time.

100      Cannot create another system semaphore.

101      The exclusive semaphore is owned by another process.

102      The semaphore is set and cannot be closed.

103      The semaphore cannot be set again.

104      Cannot request exclusive semaphores at interrupt time.

105      The previous ownership of this semaphore has ended.

106      Insert the diskette for drive %1.

107      Program stopped because alternate diskette was not inserted.

108      The disk is in use or locked by another process.

109      The pipe has been ended.

110      The system cannot open the device or file specified.

111      The file name is too long.

112      There is not enough space on the disk.

113      No more internal file identifiers available.

114      The target internal file identifier is incorrect.

117      The IOCTL call made by the application program is not correct.

118      The verify-on-write switch parameter value is not correct.

119      The system does not support the command requested.

120      This function is only valid in Win32 mode.

121      The semaphore timeout period has expired.

122      The data area passed to a system call is too small.

123      The filename, directory name, or volume label syntax is incorrect.

124      The system call level is not correct.

125      The disk has no volume label.

126      The specified module could not be found.

127      The specified procedure could not be found.

128      There are no child processes to wait for.

129      The %1 application cannot be run in Win32 mode.

130      Attempt to use a file handle to an open disk partition for an operation other than raw disk I/O.

131      An attempt was made to move the file pointer before the beginning of the file.

132      The file pointer cannot be set on the specified device or file.

133      A JOIN or SUBST command cannot be used for a drive that contains previously joined drives.

134      An attempt was made to use a JOIN or SUBST command on a drive that has already been joined.

135      An attempt was made to use a JOIN or SUBST command on a drive that has already been substituted.

136      The system tried to delete the JOIN of a drive that is not joined.

137      The system tried to delete the substitution of a drive that is not substituted.

138      The system tried to join a drive to a directory on a joined drive.

139      The system tried to substitute a drive to a directory on a substituted drive.

140      The system tried to join a drive to a directory on a substituted drive.

141      The system tried to SUBST a drive to a directory on a joined drive.

142      The system cannot perform a JOIN or SUBST at this time.

143      The system cannot join or substitute a drive to or for a directory on the same drive.

144      The directory is not a subdirectory of the root directory.

145      The directory is not empty.

146      The path specified is being used in a substitute.

147      Not enough resources are available to process this command.

148      The path specified cannot be used at this time.

149      An attempt was made to join or substitute a drive for which a directory on the drive is the target of a previous substitute.

150      System trace information was not specified in your CONFIG.SYS file, or tracing is disallowed.

151      The number of specified semaphore events for DosMuxSemWait is not correct.

152      DosMuxSemWait did not execute; too many semaphores are already set.

153      The DosMuxSemWait list is not correct.

154      The volume label you entered exceeds the label character limit of the target file system.

155      Cannot create another thread.

156      The recipient process has refused the signal.

157      The segment is already discarded and cannot be locked.

158      The segment is already unlocked.

159      The address for the thread ID is not correct.

160      The argument string passed to DosExecPgm is not correct.

161      The specified path is invalid.

162      A signal is already pending.

164      No more threads can be created in the system.

167      Unable to lock a region of a file.

170      The requested resource is in use.

173      A lock request was not outstanding for the supplied cancel region.

174      The file system does not support atomic changes to the lock type.

180      The system detected a segment number that was not correct.

182      The operating system cannot run %1.

183      Cannot create a file when that file already exists.

186      The flag passed is not correct.

187      The specified system semaphore name was not found.

188      The operating system cannot run %1.

189      The operating system cannot run %1.

190      The operating system cannot run %1.

191      Cannot run %1 in Win32 mode.

192      The operating system cannot run %1.

193      %1 is not a valid Win32 application.

194      The operating system cannot run %1.

195      The operating system cannot run %1.

196      The operating system cannot run this application program.

197      The operating system is not presently configured to run this application.

198      The operating system cannot run %1.

199      The operating system cannot run this application program.

200      The code segment cannot be greater than or equal to 64KB.

201      The operating system cannot run %1.

202      The operating system cannot run %1.

203      The system could not find the environment option that was entered.

205      No process in the command subtree has a signal handler.

206      The filename or extension is too long.

207      The ring 2 stack is in use.

208      The global filename characters, * or ?, are entered incorrectly or too many global filename characters are specified.

209      The signal being posted is not correct.

210      The signal handler cannot be set.

212      The segment is locked and cannot be reallocated.

214      Too many dynamic link modules are attached to this program or dynamic link module.

215      Can't nest calls to LoadModule.

230      The pipe state is invalid.

231      All pipe instances are busy.

232      The pipe is being closed.

233      No process is on the other end of the pipe.

234      More data is available.

240      The session was cancelled.

254      The specified extended attribute name was invalid.

255      The extended attributes are inconsistent.

259      No more data is available.

266      The Copy API cannot be used.

267      The directory name is invalid.

275      The extended attributes did not fit in the buffer.

276      The extended attribute file on the mounted file system is corrupt.

277      The extended attribute table file is full.

278      The specified extended attribute handle is invalid.

282      The mounted file system does not support extended attributes.

288      Attempt to release mutex not owned by caller.

298      Too many posts were made to a semaphore.

299      Only part of a Read/WriteProcessMemory request was completed.

317      The system cannot find message for message number 0x%1 in message file for %2.

487      Attempt to access invalid address.

534      Arithmetic result exceeded 32 bits.

535      There is a process on other end of the pipe.

536      Waiting for a process to open the other end of the pipe.

994      Access to the extended attribute was denied.

995      The I/O operation has been aborted because of either a thread exit or an application request.

996      Overlapped I/O event is not in a signalled state.

997      Overlapped I/O operation is in progress.

998      Invalid access to memory location.

999      Error performing inpage operation.

1001      Recursion too deep, stack overflowed.

1002      The window cannot act on the sent message.

1003      Cannot complete this function.

1004      Invalid flags.

1005      The volume does not contain a recognized file system. Please make sure that all required file system drivers are loaded and that the volume is not corrupt.

1006      The volume for a file has been externally altered such that the opened file is no longer valid.

1007      The requested operation cannot be performed in full-screen mode.

1008      An attempt was made to reference a token that does not exist.

1009      The configuration registry database is corrupt.

1010      The configuration registry key is invalid.

1011      The configuration registry key could not be opened.

1012      The configuration registry key could not be read.

1013      The configuration registry key could not be written.

1014      One of the files in the Registry database had to be recovered by use of a log or alternate copy. The recovery was successful.

1015      The Registry is corrupt. The structure of one of the files that contains Registry data is corrupt, or the system's image of the file in memory is corrupt, or the file could not be recovered because the alternate copy or log was absent or corrupt.

1016      An I/O operation initiated by the Registry failed unrecoverably. The Registry could not read in, or write out, or flush, one of the files that contain the system's image of the Registry.

1017      The system has attempted to load or restore a file into the Registry, but the specified file is not in a Registry file format.

1018      Illegal operation attempted on a Registry key which has been marked for deletion.

1019      System could not allocate the required space in a Registry log.

1020      Cannot create a symbolic link in a Registry key that already has subkeys or values.

1021      Cannot create a stable subkey under a volatile parent key.

1022      A notify change request is being completed and the information is not being returned in the caller's buffer. The caller now needs to enumerate the files to find the changes.

1051      A stop control has been sent to a service which other running services are dependent on.

1052      The requested control is not valid for this service

1053      The service did not respond to the start or control request in a timely fashion.

1054      A thread could not be created for the service.

1055      The service database is locked.

1056      An instance of the service is already running.

1057      The account name is invalid or does not exist.

1058      The specified service is disabled and cannot be started.

1059      Circular service dependency was specified.

1060      The specified service does not exist as an installed service.

1061      The service cannot accept control messages at this time.

1062      The service has not been started.

1063      The service process could not connect to the service controller.

1064      An exception occurred in the service when handling the control request.

1065      The database specified does not exist.

1066      The service has returned a service-specific error code.

1067      The process terminated unexpectedly.

1068      The dependency service or group failed to start.

1069      The service did not start due to a logon failure.

1070      After starting, the service hung in a start-pending state.

1071      The specified service database lock is invalid.

1072      The specified service has been marked for deletion.

1073      The specified service already exists.

1074      The system is currently running with the last-known-good configuration.

1075      The dependency service does not exist or has been marked for deletion.

1076      The current boot has already been accepted for use as the last-known-good control set.

1077      No attempts to start the service have been made since the last boot.

1078      The name is already in use as either a service name or a service display name.

1100      The physical end of the tape has been reached.

1101      A tape access reached a filemark.

1102      Beginning of tape or partition was encountered.

1103      A tape access reached the end of a set of files.

1104      No more data is on the tape.

1105      Tape could not be partitioned.

1106      When accessing a new tape of a multivolume partition, the current blocksize is incorrect.

1107      Tape partition information could not be found when loading a tape.

1108      Unable to lock the media eject mechanism.

1109      Unable to unload the media.

1110      Media in drive may have changed.

1111      The I/O bus was reset.

1112      No media in drive.

1113      No mapping for the Unicode character exists in the target multi-byte code page.

1114      A dynamic link library (DLL) initialization routine failed.

1115      A system shutdown is in progress.

1116      Unable to abort the system shutdown because no shutdown was in progress.

1117      The request could not be performed because of an I/O device error.

1118      No serial device was successfully initialized. The serial driver will unload.

1119      Unable to open a device that was sharing an interrupt request (IRQ) with other devices. At least one other device that uses that IRQ was already opened.

1120      A serial I/O operation was completed by another write to the serial port. (The IOCTL_SERIAL_XOFF_COUNTER reached zero.)

1121      A serial I/O operation completed because the time-out period expired. (The IOCTL_SERIAL_XOFF_COUNTER did not reach zero.)

1122      No ID address mark was found on the floppy disk.

1123      Mismatch between the floppy disk sector ID field and the floppy disk controller track address.

1124      The floppy disk controller reported an error that is not recognized by the floppy disk driver.

1125      The floppy disk controller returned inconsistent results in its registers.

1126      While accessing the hard disk, a recalibrate operation failed, even after retries.

1127      While accessing the hard disk, a disk operation failed even after retries.

1128      While accessing the hard disk, a disk controller reset was needed, but even that failed.

1129      Physical end of tape encountered.

1130      Not enough server storage is available to process this command.

1131      A potential deadlock condition has been detected.

1132      The base address or the file offset specified does not have the proper alignment.

1140      An attempt to change the system power state was vetoed by another application or driver.

1141      The system BIOS failed an attempt to change the system power state.

1150      The specified program requires a newer version of Windows.

1151      The specified program is not a Windows or MS-DOS program.

1152      Cannot start more than one instance of the specified program.

1153      The specified program was written for an older version of Windows.

1154      One of the library files needed to run this application is damaged.

1155      No application is associated with the specified file for this operation.

1156      An error occurred in sending the command to the application.

1157      One of the library files needed to run this application cannot be found.

1200      The specified device name is invalid.

1201      The device is not currently connected but it is a remembered connection.

1202      An attempt was made to remember a device that had previously been remembered.

1203      No network provider accepted the given network path.

1204      The specified network provider name is invalid.

1205      Unable to open the network connection profile.

1206      The network connection profile is corrupt.

1207      Cannot enumerate a non-container.

1208      An extended error has occurred.

1209      The format of the specified group name is invalid.

1210      The format of the specified computer name is invalid.

1211      The format of the specified event name is invalid.

1212      The format of the specified domain name is invalid.

1213      The format of the specified service name is invalid.

1214      The format of the specified network name is invalid.

1215      The format of the specified share name is invalid.

1216      The format of the specified password is invalid.

1217      The format of the specified message name is invalid.

1218      The format of the specified message destination is invalid.

1219      The credentials supplied conflict with an existing set of credentials.

1220      An attempt was made to establish a session to a network server, but there are already too many sessions established to that server.

1221      The workgroup or domain name is already in use by another computer on the network.

1222      The network is not present or not started.

1223      The operation was cancelled by the user.

1224      The requested operation cannot be performed on a file with a user mapped section open.

1225      The remote system refused the network connection.

1226      The network connection was gracefully closed.

1227      The network transport endpoint already has an address associated with it.

1228      An address has not yet been associated with the network endpoint.

1229      An operation was attempted on a non-existent network connection.

1230      An invalid operation was attempted on an active network connection.

1231      The remote network is not reachable by the transport.

1232      The remote system is not reachable by the transport.

1233      The remote system does not support the transport protocol.

1234      No service is operating at the destination network endpoint on the remote system.

1235      The request was aborted.

1236      The network connection was aborted by the local system.

1237      The operation could not be completed. A retry should be performed.

1238      A connection to the server could not be made because the limit on the number of concurrent connections for this account has been reached.

1239      Attempting to login during an unauthorized time of day for this account.

1240      The account is not authorized to login from this station.

1241      The network address could not be used for the operation requested.

1242      The service is already registered.

1243      The specified service does not exist.

1244      The operation being requested was not performed because the user has not been authenticated.

1245      The operation being requested was not performed because the user has not logged on to the network. The specified service does not exist.

1246      Return that wants caller to continue with work in progress.

1247      An attempt was made to perform an initialization operation when initialization has already been completed.

1248      No more local devices.

1300      Not all privileges referenced are assigned to the caller.

1301      Some mapping between account names and security IDs was not done.

1302      No system quota limits are specifically set for this account.

1303      No encryption key is available. A well-known encryption key was returned.

1304      The NT password is too complex to be converted to a LAN Manager password. The LAN Manager password returned is a NULL string.

1305      The revision level is unknown.

1306      Indicates two revision levels are incompatible.

1307      This security ID may not be assigned as the owner of this object.

1308      This security ID may not be assigned as the primary group of an object.

1309      An attempt has been made to operate on an impersonation token by a thread that is not currently impersonating a client.

1310      The group may not be disabled.

1311      There are currently no logon servers available to service the logon request.

1312       A specified logon session does not exist. It may already have been terminated.

1313       A specified privilege does not exist.

1314       A required privilege is not held by the client.

1315      The name provided is not a properly formed account name.

1316      The specified user already exists.

1317      The specified user does not exist.

1318      The specified group already exists.

1319      The specified group does not exist.

1320      Either the specified user account is already a member of the specified group, or the specified group cannot be deleted because it contains a member.

1321      The specified user account is not a member of the specified group account.

1322      The last remaining administration account cannot be disabled or deleted.

1323      Unable to update the password. The value provided as the current password is incorrect.

1324      Unable to update the password. The value provided for the new password contains values that are not allowed in passwords.

1325      Unable to update the password because a password update rule has been violated.

1326      Logon failure: unknown user name or bad password.

1327      Logon failure: user account restriction.

1328      Logon failure: account logon time restriction violation.

1329      Logon failure: user not allowed to log on to this computer.

1330      Logon failure: the specified account password has expired.

1331      Logon failure: account currently disabled.

1332      No mapping between account names and security IDs was done.

1333      Too many local user identifiers (LUIDs) were requested at one time.

1334      No more local user identifiers (LUIDs) are available.

1335      The subauthority part of a security ID is invalid for this particular use.

1336      The access control list (ACL) structure is invalid.

1337      The security ID structure is invalid.

1338      The security descriptor structure is invalid.

1340      The inherited access control list (ACL) or access control entry (ACE) could not be built.

1341      The server is currently disabled.

1342      The server is currently enabled.

1343      The value provided was an invalid value for an identifier authority.

1344      No more memory is available for security information updates.

1345      The specified attributes are invalid, or incompatible with the attributes for the group as a whole.

1346      Either a required impersonation level was not provided, or the provided impersonation level is invalid.

1347      Cannot open an anonymous level security token.

1348      The validation information class requested was invalid.

1349      The type of the token is inappropriate for its attempted use.

1350      Unable to perform a security operation on an object which has no associated security.

1351      Indicates a Windows NT Server could not be contacted or that objects within the domain are protected such that necessary information could not be retrieved.

1352      The security account manager (SAM) or local security authority (LSA) server was in the wrong state to perform the security operation.

1353      The domain was in the wrong state to perform the security operation.

1354      This operation is only allowed for the Primary Domain Controller of the domain.

1355      The specified domain did not exist.

1356      The specified domain already exists.

1357      An attempt was made to exceed the limit on the number of domains per server.

1358      Unable to complete the requested operation because of either a catastrophic media failure or a data structure corruption on the disk.

1359      The security account database contains an internal inconsistency.

1360      Generic access types were contained in an access mask which should already be mapped to non-generic types.

1361      A security descriptor is not in the right format (absolute or self-relative).

1362      The requested action is restricted for use by logon processes only. The calling process has not registered as a logon process.

1363      Cannot start a new logon session with an ID that is already in use.

1364      A specified authentication package is unknown.

1365      The logon session is not in a state that is consistent with the requested operation.

1366      The logon session ID is already in use.

1367      A logon request contained an invalid logon type value.

1368      Unable to impersonate via a named pipe until data has been read from that pipe.

1369      The transaction state of a Registry subtree is incompatible with the requested operation.

1370      An internal security database corruption has been encountered.

1371      Cannot perform this operation on built-in accounts.

1372      Cannot perform this operation on this built-in special group.

1373      Cannot perform this operation on this built-in special user.

1374      The user cannot be removed from a group because the group is currently the user's primary group.

1375      The token is already in use as a primary token.

1376      The specified local group does not exist.

1377      The specified account name is not a member of the local group.

1378      The specified account name is already a member of the local group.

1379      The specified local group already exists.

1380      Logon failure: the user has not been granted the requested logon type at this computer.

1381      The maximum number of secrets that may be stored in a single system has been exceeded.

1382      The length of a secret exceeds the maximum length allowed.

1383      The local security authority database contains an internal inconsistency.

1384      During a logon attempt, the user's security context accumulated too many security IDs.

1385      Logon failure: the user has not been granted the requested logon type at this computer.

1386      A cross-encrypted password is necessary to change a user password.

1387      A new member could not be added to a local group because the member does not exist.

1388      A new member could not be added to a local group because the member has the wrong account type.

1389      Too many security IDs have been specified.

1390      A cross-encrypted password is necessary to change this user password.

1391      Indicates an ACL contains no inheritable components

1392      The file or directory is corrupt and non-readable.

1393      The disk structure is corrupt and non-readable.

1394      There is no user session key for the specified logon session.

1395      The service being accessed is licensed for a particular number of connections. No more connections can be made to the service at this time because there are already as many connections as the service can accept.

1400      Invalid window handle.

1401      Invalid menu handle.

1402      Invalid cursor handle.

1403      Invalid accelerator table handle.

1404      Invalid hook handle.

1405      Invalid handle to a multiple-window position structure.

1406      Cannot create a top-level child window.

1407      Cannot find window class.

1408      Invalid window, belongs to other thread.

1409      Hot key is already registered.

1410      Class already exists.

1411      Class does not exist.

1412      Class still has open windows.

1413      Invalid index.

1414      Invalid icon handle.

1415      Using private DIALOG window words.

1416      The listbox identifier was not found.

1417      No wildcards were found.

1418      Thread does not have a clipboard open.

1419      Hot key is not registered.

1420      The window is not a valid dialog window.

1421      Control ID not found.

1422      Invalid message for a combo box because it does not have an edit control.

1423      The window is not a combo box.

1424      Height must be less than 256.

1425      Invalid device context (DC) handle.

1426      Invalid hook procedure type.

1427      Invalid hook procedure.

1428      Cannot set non-local hook without a module handle.

1429      This hook procedure can only be set globally.

1430      The journal hook procedure is already installed.

1431      The hook procedure is not installed.

1432      Invalid message for single-selection listbox.

1433      LB_SETCOUNT sent to non-lazy listbox.

1434      This list box does not support tab stops.

1435      Cannot destroy object created by another thread.

1436      Child windows cannot have menus.

1437      The window does not have a system menu.

1438      Invalid message box style.

1439      Invalid system-wide (SPI_*) parameter.

1440      Screen already locked.

1441      All handles to windows in a multiple-window position structure must have the same parent.

1442      The window is not a child window.

1443      Invalid GW_* command.

1444      Invalid thread identifier.

1445      Cannot process a message from a window that is not a multiple document interface (MDI) window.

1446      Popup menu already active.

1447      The window does not have scroll bars.

1448      Scroll bar range cannot be greater than 0x7FFF.

1449      Cannot show or remove the window in the way specified.

1450      Insufficient system resources exist to complete the requested service.

1451      Insufficient system resources exist to complete the requested service.

1452      Insufficient system resources exist to complete the requested service.

1453      Insufficient quota to complete the requested service.

1454      Insufficient quota to complete the requested service.

1455      The paging file is too small for this operation to complete.

1456      A menu item was not found.

1500      The event log file is corrupt.

1501      No event log file could be opened, so the event logging service did not start.

1502      The event log file is full.

1503      The event log file has changed between reads.

1700      The string binding is invalid.

1701      The binding handle is not the correct type.

1702      The binding handle is invalid.

1703      The RPC protocol sequence is not supported.

1704      The RPC protocol sequence is invalid.

1705      The string universal unique identifier (UUID) is invalid.

1706      The endpoint format is invalid.

1707      The network address is invalid.

1708      No endpoint was found.

1709      The timeout value is invalid.

1710      The object universal unique identifier (UUID) was not found.

1711      The object universal unique identifier (UUID) has already been registered.

1712      The type universal unique identifier (UUID) has already been registered.

1713      The RPC server is already listening.

1714      No protocol sequences have been registered.

1715      The RPC server is not listening.

1716      The manager type is unknown.

1717      The interface is unknown.

1718      There are no bindings.

1719      There are no protocol sequences.

1720      The endpoint cannot be created.

1721      Not enough resources are available to complete this operation.

1722      The RPC server is unavailable.

1723      The RPC server is too busy to complete this operation.

1724      The network options are invalid.

1725      There is not a remote procedure call active in this thread.

1726      The remote procedure call failed.

1727      The remote procedure call failed and did not execute.

1728      A remote procedure call (RPC) protocol error occurred.

1730      The transfer syntax is not supported by the RPC server.

1732      The universal unique identifier (UUID) type is not supported.

1733      The tag is invalid.

1734      The array bounds are invalid.

1735      The binding does not contain an entry name.

1736      The name syntax is invalid.

1737      The name syntax is not supported.

1739      No network address is available to use to construct a universal unique identifier (UUID).

1740      The endpoint is a duplicate.

1741      The authentication type is unknown.

1742      The maximum number of calls is too small.

1743      The string is too long.

1744      The RPC protocol sequence was not found.

1745      The procedure number is out of range.

1746      The binding does not contain any authentication information.

1747      The authentication service is unknown.

1748      The authentication level is unknown.

1749      The security context is invalid.

1750      The authorization service is unknown.

1751      The entry is invalid.

1752      The server endpoint cannot perform the operation.

1753      There are no more endpoints available from the endpoint mapper.

1754      No interfaces have been exported.

1755      The entry name is incomplete.

1756      The version option is invalid.

1757      There are no more members.

1758      There is nothing to unexport.

1759      The interface was not found.

1760      The entry already exists.

1761      The entry is not found.

1762      The name service is unavailable.

1763      The network address family is invalid.

1764      The requested operation is not supported.

1765      No security context is available to allow impersonation.

1766      An internal error occurred in a remote procedure call (RPC).

1767      The RPC server attempted an integer division by zero.

1768      An addressing error occurred in the RPC server.

1769      A floating-point operation at the RPC server caused a division by zero.

1770      A floating-point underflow occurred at the RPC server.

1771      A floating-point overflow occurred at the RPC server.

1772      The list of RPC servers available for the binding of auto handles has been exhausted.

1773      Unable to open the character translation table file.

1774      The file containing the character translation table has fewer than 512 bytes.

1775      A null context handle was passed from the client to the host during a remote procedure call.

1777      The context handle changed during a remote procedure call.

1778      The binding handles passed to a remote procedure call do not match.

1779      The stub is unable to get the remote procedure call handle.

1780      A null reference pointer was passed to the stub.

1781      The enumeration value is out of range.

1782      The byte count is too small.

1783      The stub received bad data.

1784      The supplied user buffer is not valid for the requested operation.

1785      The disk media is not recognized. It may not be formatted.

1786      The workstation does not have a trust secret.

1787      The SAM database on the Windows NT Server does not have a computer account for this workstation trust relationship.

1788      The trust relationship between the primary domain and the trusted domain failed.

1789      The trust relationship between this workstation and the primary domain failed.

1790      The network logon failed.

1791      A remote procedure call is already in progress for this thread.

1792      An attempt was made to logon, but the network logon service was not started.

1793      The user's account has expired.

1794      The redirector is in use and cannot be unloaded.

1795      The specified printer driver is already installed.

1796      The specified port is unknown.

1797      The printer driver is unknown.

1798      The print processor is unknown.

1799      The specified separator file is invalid.

1800      The specified priority is invalid.

1801      The printer name is invalid.

1802      The printer already exists.

1803      The printer command is invalid.

1804      The specified datatype is invalid.

1805      The Environment specified is invalid.

1806      There are no more bindings.

1807      The account used is an interdomain trust account. Use your global user account or local user account to access this server.

1808      The account used is a Computer Account. Use your global user account or local user account to access this server.

1809      The account used is an server trust account. Use your global user account or local user account to access this server.

1810      The name or security ID (SID) of the domain specified is inconsistent with the trust information for that domain.

1811      The server is in use and cannot be unloaded.

1812      The specified image file did not contain a resource section.

1813      The specified resource type can not be found in the image file.

1814      The specified resource name can not be found in the image file.

1815      The specified resource language ID cannot be found in the image file.

1816      Not enough quota is available to process this command.

1817      No interfaces have been registered.

1818      The server was altered while processing this call.

1819      The binding handle does not contain all required information.

1820      Communications failure.

1821      The requested authentication level is not supported.

1822      No principal name registered.

1823      The error specified is not a valid Windows RPC error code.

1824      A UUID that is valid only on this computer has been allocated.

1825      A security package specific error occurred.

1826      Thread is not cancelled.

1827      Invalid operation on the encoding/decoding handle.

1828      Incompatible version of the serializing package.

1829      Incompatible version of the RPC stub.

1898      The group member was not found.

1899      The endpoint mapper database could not be created.

1900      The object universal unique identifier (UUID) is the nil UUID.

1901      The specified time is invalid.

1902      The specified Form name is invalid.

1903      The specified Form size is invalid

1904      The specified Printer handle is already being waited on

1905      The specified Printer has been deleted

1906      The state of the Printer is invalid

1907      The user must change his password before he logs on the first time.

1908      Could not find the domain controller for this domain.

1909      The referenced account is currently locked out and may not be logged on to.

2000      The pixel format is invalid.

2001      The specified driver is invalid.

2002      The window style or class attribute is invalid for this operation.

2003      The requested metafile operation is not supported.

2004      The requested transformation operation is not supported.

2005      The requested clipping operation is not supported.

2202      The specified username is invalid.

2250      This network connection does not exist.

2401      This network connection has files open or requests pending.

2402      Active connections still exist.

2404      The device is in use by an active process and cannot be disconnected.

3000      The specified print monitor is unknown.

3001      The specified printer driver is currently in use.

3002      The spool file was not found.

3003      A StartDocPrinter call was not issued.

3004      An AddJob call was not issued.

3005      The specified print processor has already been installed.

3006      The specified print monitor has already been installed.

4000      WINS encountered an error while processing the command.

4001      The local WINS can not be deleted.

4002      The importation from the file failed.

4003      The backup Failed. Was a full backup done before ?

4004      The backup Failed. Check the directory that you are backing the database to.

4005      The name does not exist in the WINS database.

4006      Replication with a non-configured partner is not allowed.

6118      The list of servers for this workgroup is not currently available

 

OLE Error Codes ...this could take a juuuuuust a little while ( 655,359 itins! )

&H80000001      Not implemented

&H80000002      Ran out of memory

&H80000003      One or more arguments are invalid

&H80000004      No such interface supported

&H80000005      Invalid pointer

&H80000006      Invalid handle

&H80000007      Operation aborted

&H80000008      Unspecified error

&H80000009      General access denied error

&H80004001      Not implemented

&H80004002      No such interface supported

&H80004003      Invalid pointer

&H80004004      Operation aborted

&H80004005      Unspecified error

&H80004006      Thread local storage failure

&H80004007      Get shared memory allocator failure

&H80004008      Get memory allocator failure

&H80004009      Unable to initialize class cache

&H8000400A      Unable to initialize RPC services

&H8000400B      Cannot set thread local storage channel control

&H8000400C      Could not allocate thread local storage channel control

&H8000400D      The user supplied memory allocator is unacceptable

&H8000400E      The OLE service mutex already exists

&H8000400F      The OLE service file mapping already exists

&H80004010      Unable to map view of file for OLE service

&H80004011      Failure attempting to launch OLE service

&H80004012      There was an attempt to call CoInitialize a second time while single threaded

&H8000FFFF      Unexpected failure

&H80010001      Call was rejected by callee.

&H80010002      Call was canceled by the message filter.

&H80010003      The caller is dispatching an intertask SendMessage call and cannot call out via PostMessage.

&H80010004      The caller is dispatching an asynchronous call and cannot make an outgoing call on behalf of this call.

&H80010005      It is illegal to call out while inside message filter.

&H80010006      The connection terminated or is in a bogus state and cannot be used any more. Other connections are still valid.

&H80010007      The callee (server [not server application]) is not available and disappeared; all connections are invalid. The call may have executed.

&H80010008      The caller (client) disappeared while the callee (server) was processing a call.

&H80010009      The data packet with the marshalled parameter data is incorrect.

&H8001000A      The call was not transmitted properly; the message queue was full and was not emptied after yielding.

&H8001000B      The client (caller) cannot marshall the parameter data - low memory, etc.

&H8001000C      The client (caller) cannot unmarshall the return data - low memory, etc.

&H8001000D      The server (callee) cannot marshall the return data - low memory, etc.

&H8001000E      The server (callee) cannot unmarshall the parameter data - low memory, etc.

&H8001000F      Received data is invalid; could be server or client data.

&H80010010      A particular parameter is invalid and cannot be (un)marshalled.

&H80010011      There is no second outgoing call on same channel in DDE conversation.

&H80010012      The callee (server [not server application]) is not available and disappeared; all connections are invalid. The call did not execute.

&H80010100      System call failed.

&H80010101      Could not allocate some required resource (memory, events, ...)

&H80010102      Attempted to make calls on more than one thread in single threaded mode.

&H80010103      The requested interface is not registered on the server object.

&H80010104      RPC could not call the server or could not return the results of calling the server.

&H80010105      The server threw an exception.

&H80010106      Cannot change thread mode after it is set.

&H80010107      The method called does not exist on the server.

&H80010108      The object invoked has disconnected from its clients.

&H80010109      The object invoked chose not to process the call now. Try again later.

&H8001010A      The message filter indicated that the application is busy.

&H8001010B      The message filter rejected the call.

&H8001010C      A call control interfaces was called with invalid data.

&H8001010D      An outgoing call cannot be made since the application is dispatching an input-synchronous call.

&H8001010E      The application called an interface that was marshalled for a different thread.

&H8001010F      CoInitialize has not been called on the current thread.

&H8001FFFF      An internal error occurred.

&H80020001      Unknown interface.

&H80020003      Member not found.

&H80020004      Parameter not found.

&H80020005      Type mismatch.

&H80020006      Unknown name.

&H80020007      No named arguments.

&H80020008      Bad variable type.

&H80020009      Exception occurred.

&H8002000A      Out of present range.

&H8002000B      Invalid index.

&H8002000C      Unknown language.

&H8002000D      Memory is locked.

&H8002000E      Invalid number of parameters.

&H8002000F      Parameter not optional.

&H80020010      Invalid callee.

&H80020011      Does not support a collection.

&H80028016      Buffer too small.

&H80028018      Old format or invalid type library.

&H80028019      Old format or invalid type library.

&H8002801C      Error accessing the OLE registry.

&H8002801D      Library not registered.

&H80028027      Bound to unknown type.

&H80028028      Qualified name disallowed.

&H80028029      Invalid forward reference, or reference to uncompiled type.

&H8002802A      Type mismatch.

&H8002802B      Element not found.

&H8002802C      Ambiguous name.

&H8002802D      Name already exists in the library.

&H8002802E      Unknown LCID.

&H8002802F      Function not defined in specified DLL.

&H800288BD      Wrong module kind for the operation.

&H800288C5      Size may not exceed 64K.

&H800288C6      Duplicate ID in inheritance hierarchy.

&H800288CF      Incorrect inheritance depth in standard OLE hmember.

&H80028CA0      Type mismatch.

&H80028CA1      Invalid number of arguments.

&H80028CA2      I/O Error.

&H80028CA3      Error creating unique tmp file.

&H80029C4A      Error loading type library/DLL.

&H80029C83      Inconsistent property functions.

&H80029C84      Circular dependency between types/modules.

&H80030001      Unable to perform requested operation.

&H80030002      %1 could not be found.

&H80030003      The path %1 could not be found.

&H80030004      There are insufficient resources to open another file.

&H80030005      Access Denied.

&H80030006      Attempted an operation on an invalid object.

&H80030008      There is insufficient memory available to complete operation.

&H80030009      Invalid pointer error.

&H80030012      There are no more entries to return.

&H80030013      Disk is write-protected.

&H80030019      An error occurred during a seek operation.

&H8003001D      A disk error occurred during a write operation.

&H8003001E      A disk error occurred during a read operation.

&H80030020      A share violation has occurred.

&H80030021      A lock violation has occurred.

&H80030050      %1 already exists.

&H80030057      Invalid parameter error.

&H80030070      There is insufficient disk space to complete operation.

&H800300FA      An API call exited abnormally.

&H800300FB      The file %1 is not a valid compound file.

&H800300FC      The name %1 is not valid.

&H800300FD      An unexpected error occurred.

&H800300FE      That function is not implemented.

&H800300FF      Invalid flag error.

&H80030100      Attempted to use an object that is busy.

&H80030101      The storage has been changed since the last commit.

&H80030102      Attempted to use an object that has ceased to exist.

&H80030103      Can't save.

&H80030104      The compound file %1 was produced with an incompatible version of storage.

&H80030105      The compound file %1 was produced with a newer version of storage.

&H80030106      Share.exe or equivalent is required for operation.

&H80030107      Illegal operation called on non-file based storage.

&H80030108      Illegal operation called on object with extant marshallings.

&H80040000      Invalid OLEVERB structure

&H80040001      Invalid advise flags

&H80040002      Can't enumerate any more, because the associated data is missing

&H80040003      This implementation doesn't take advises

&H80040004      There is no connection for this connection ID

&H80040005      Need to run the object to perform this operation

&H80040006      There is no cache to operate on

&H80040007      Uninitialized object

&H80040008      Linked object's source class has changed

&H80040009      Not able to get the moniker of the object

&H8004000A      Not able to bind to the source

&H8004000B      Object is static; operation not allowed

&H8004000C      User cancelled out of save dialog

&H8004000D      Invalid rectangle

&H8004000E      compobj.dll is too old for the ole2.dll initialized

&H8004000F      Invalid window handle

&H80040010      Object is not in any of the inplace active states

&H80040011      Not able to convert object

&H80040012      Not able to perform the operation because object is not given storage yet

&H80040064      Invalid FORMATETC structure

&H80040065      Invalid DVTARGETDEVICE structure

&H80040066      Invalid STDGMEDIUM structure

&H80040067      Invalid STATDATA structure

&H80040068      Invalid lindex

&H80040069      Invalid tymed

&H8004006A      Invalid clipboard format

&H8004006B      Invalid aspect(s)

&H8004006C      tdSize parameter of the DVTARGETDEVICE structure is invalid

&H8004006D      Object doesn't support IViewObject interface

&H80040100      Trying to revoke a drop target that has not been registered

&H80040101      This window has already been registered as a drop target

&H80040102      Invalid window handle

&H80040110      Class does not support aggregation (or class object is remote)

&H80040111      ClassFactory cannot supply requested class

&H80040140      Error drawing view

&H80040150      Could not read key from registry

&H80040151      Could not write key to registry

&H80040152      Could not find the key in the registry

&H80040153      Invalid value for registry

&H80040154      Class not registered

&H80040155      Interface not registered

&H80040170      Cache not updated

&H80040180      No verbs for OLE object

&H80040181      Invalid verb for OLE object

&H800401A0      Undo is not available

&H800401A1      Space for tools is not available

&H800401C0      OLESTREAM Get method failed

&H800401C1      OLESTREAM Put method failed

&H800401C2      Contents of the OLESTREAM not in correct format

&H800401C3      There was an error in a Windows GDI call while converting the bitmap to a DIB

&H800401C4      Contents of the IStorage not in correct format

&H800401C5      Contents of IStorage is missing one of the standard streams

&H800401C6      There was an error in a Windows GDI call while converting the DIB to a bitmap.

&H800401D0      OpenClipboard Failed

&H800401D1      EmptyClipboard Failed

&H800401D2      SetClipboard Failed

&H800401D3      Data on clipboard is invalid

&H800401D4      CloseClipboard Failed

&H800401E0      Moniker needs to be connected manually

&H800401E1      Operation exceeded deadline

&H800401E2      Moniker needs to be generic

&H800401E3      Operation unavailable

&H800401E4      Invalid syntax

&H800401E5      No object for moniker

&H800401E6      Bad extension for file

&H800401E7      Intermediate operation failed

&H800401E8      Moniker is not bindable

&H800401E9      Moniker is not bound

&H800401EA      Moniker cannot open file

&H800401EB      User input required for operation to succeed

&H800401EC      Moniker class has no inverse

&H800401ED      Moniker does not refer to storage

&H800401EE      No common prefix

&H800401EF      Moniker could not be enumerated

&H800401F0      CoInitialize has not been called.

&H800401F1      CoInitialize has already been called.

&H800401F2      Class of object cannot be determined

&H800401F3      Invalid class string

&H800401F4      Invalid interface string

&H800401F5      Application not found

&H800401F6      Application cannot be run more than once

&H800401F7      Some error in application program

&H800401F8      DLL for class not found

&H800401F9      Error in the DLL

&H800401FA      Wrong OS or OS version for application

&H800401FB      Object is not registered

&H800401FC      Object is already registered

&H800401FD      Object is not connected to server

&H800401FE      Application was launched but it didn't register a class factory

&H800401FF      Object has been released

&H80070000      The operation completed successfully.

&H80070001      Incorrect function.

&H80070002      The system cannot find the file specified.

&H80070003      The system cannot find the path specified.

&H80070004      The system cannot open the file.

&H80070005      Access is denied.

&H80070006      The handle is invalid.

&H80070007      The storage control blocks were destroyed.

&H80070008      Not enough storage is available to process this command.

&H80070009      The storage control block address is invalid.

&H8007000A      The environment is incorrect.

&H8007000B      An attempt was made to load a program with an incorrect format.

&H8007000C      The access code is invalid.

&H8007000D      The data is invalid.

&H8007000E      Not enough storage is available to complete this operation.

&H8007000F      The system cannot find the drive specified.

&H80070010      The directory cannot be removed.

&H80070011      The system cannot move the file to a different disk drive.

&H80070012      There are no more files.

&H80070013      The media is write protected.

&H80070014      The system cannot find the device specified.

&H80070015      The device is not ready.

&H80070016      The device does not recognize the command.

&H80070017      Data error (cyclic redundancy check)

&H80070018      The program issued a command but the command length is incorrect.

&H80070019      The drive cannot locate a specific area or track on the disk.

&H8007001A      The specified disk or diskette cannot be accessed.

&H8007001B      The drive cannot find the sector requested.

&H8007001C      The printer is out of paper.

&H8007001D      The system cannot write to the specified device.

&H8007001E      The system cannot read from the specified device.

&H8007001F      A device attached to the system is not functioning.

&H80070020      The process cannot access the file because it is being used by another process.

&H80070021      The process cannot access the file because another process has locked a portion of the file.

&H80070022      The wrong diskette is in the drive. Insert %2 (Volume Serial Number: %3) into drive %1.

&H80070024      Too many files opened for sharing.

&H80070026      Reached end of file.

&H80070027      The disk is full.

&H80070032      The network request is not supported.

&H80070033      The remote computer is not available.

&H80070034      A duplicate name exists on the network.

&H80070035      The network path was not found.

&H80070036      The network is busy.

&H80070037      The specified network resource or device is no longer available.

&H80070038      The network BIOS command limit has been reached.

&H80070039      A network adapter hardware error occurred.

&H8007003A      The specified server cannot perform the requested operation.

&H8007003B      An unexpected network error occurred.

&H8007003C      The remote adapter is not compatible.

&H8007003D      The printer queue is full.

&H8007003E      Space to store the file waiting to be printed is not available on the server.

&H8007003F      Your file waiting to be printed was deleted.

&H80070040      The specified network name is no longer available.

&H80070041      Network access is denied.

&H80070042      The network resource type is not correct.

&H80070043      The network name cannot be found.

&H80070044      The name limit for the local computer network adapter card was exceeded.

&H80070045      The network BIOS session limit was exceeded.

&H80070046      The remote server has been paused or is in the process of being started.

&H80070047      No more connections can be made to this remote computer at this time because there are already as many connections as the computer can accept.

&H80070048      The specified printer or disk device has been paused.

&H80070050      The file exists.

&H80070052      The directory or file cannot be created.

&H80070053      Fail on INT 24

&H80070054      Storage to process this request is not available.

&H80070055      The local device name is already in use.

&H80070056      The specified network password is not correct.

&H80070057      The parameter is incorrect.

&H80070058      A write fault occurred on the network.

&H80070059      The system cannot start another process at this time.

&H80070064      Cannot create another system semaphore.

&H80070065      The exclusive semaphore is owned by another process.

&H80070066      The semaphore is set and cannot be closed.

&H80070067      The semaphore cannot be set again.

&H80070068      Cannot request exclusive semaphores at interrupt time.

&H80070069      The previous ownership of this semaphore has ended.

&H8007006A      Insert the diskette for drive %1.

&H8007006B      Program stopped because alternate diskette was not inserted.

&H8007006C      The disk is in use or locked by another process.

&H8007006D      The pipe has been ended.

&H8007006E      The system cannot open the device or file specified.

&H8007006F      The file name is too long.

&H80070070      There is not enough space on the disk.

&H80070071      No more internal file identifiers available.

&H80070072      The target internal file identifier is incorrect.

&H80070075      The IOCTL call made by the application program is not correct.

&H80070076      The verify-on-write switch parameter value is not correct.

&H80070077      The system does not support the command requested.

&H80070078      This function is only valid in Win32 mode.

&H80070079      The semaphore timeout period has expired.

&H8007007A      The data area passed to a system call is too small.

&H8007007B      The filename, directory name, or volume label syntax is incorrect.

&H8007007C      The system call level is not correct.

&H8007007D      The disk has no volume label.

&H8007007E      The specified module could not be found.

&H8007007F      The specified procedure could not be found.

&H80070080      There are no child processes to wait for.

&H80070081      The %1 application cannot be run in Win32 mode.

&H80070082      Attempt to use a file handle to an open disk partition for an operation other than raw disk I/O.

&H80070083      An attempt was made to move the file pointer before the beginning of the file.

&H80070084      The file pointer cannot be set on the specified device or file.

&H80070085      A JOIN or SUBST command cannot be used for a drive that contains previously joined drives.

&H80070086      An attempt was made to use a JOIN or SUBST command on a drive that has already been joined.

&H80070087      An attempt was made to use a JOIN or SUBST command on a drive that has already been substituted.

&H80070088      The system tried to delete the JOIN of a drive that is not joined.

&H80070089      The system tried to delete the substitution of a drive that is not substituted.

&H8007008A      The system tried to join a drive to a directory on a joined drive.

&H8007008B      The system tried to substitute a drive to a directory on a substituted drive.

&H8007008C      The system tried to join a drive to a directory on a substituted drive.

&H8007008D      The system tried to SUBST a drive to a directory on a joined drive.

&H8007008E      The system cannot perform a JOIN or SUBST at this time.

&H8007008F      The system cannot join or substitute a drive to or for a directory on the same drive.

&H80070090      The directory is not a subdirectory of the root directory.

&H80070091      The directory is not empty.

&H80070092      The path specified is being used in a substitute.

&H80070093      Not enough resources are available to process this command.

&H80070094      The path specified cannot be used at this time.

&H80070095      An attempt was made to join or substitute a drive for which a directory on the drive is the target of a previous substitute.

&H80070096      System trace information was not specified in your CONFIG.SYS file, or tracing is disallowed.

&H80070097      The number of specified semaphore events for DosMuxSemWait is not correct.

&H80070098      DosMuxSemWait did not execute; too many semaphores are already set.

&H80070099      The DosMuxSemWait list is not correct.

&H8007009A      The volume label you entered exceeds the label character limit of the target file system.

&H8007009B      Cannot create another thread.

&H8007009C      The recipient process has refused the signal.

&H8007009D      The segment is already discarded and cannot be locked.

&H8007009E      The segment is already unlocked.

&H8007009F      The address for the thread ID is not correct.

&H800700A0      The argument string passed to DosExecPgm is not correct.

&H800700A1      The specified path is invalid.

&H800700A2      A signal is already pending.

&H800700A4      No more threads can be created in the system.

&H800700A7      Unable to lock a region of a file.

&H800700AA      The requested resource is in use.

&H800700AD      A lock request was not outstanding for the supplied cancel region.

&H800700AE      The file system does not support atomic changes to the lock type.

&H800700B4      The system detected a segment number that was not correct.

&H800700B6      The operating system cannot run %1.

&H800700B7      Cannot create a file when that file already exists.

&H800700BA      The flag passed is not correct.

&H800700BB      The specified system semaphore name was not found.

&H800700BC      The operating system cannot run %1.

&H800700BD      The operating system cannot run %1.

&H800700BE      The operating system cannot run %1.

&H800700BF      Cannot run %1 in Win32 mode.

&H800700C0      The operating system cannot run %1.

&H800700C1      %1 is not a valid Win32 application.

&H800700C2      The operating system cannot run %1.

&H800700C3      The operating system cannot run %1.

&H800700C4      The operating system cannot run this application program.

&H800700C5      The operating system is not presently configured to run this application.

&H800700C6      The operating system cannot run %1.

&H800700C7      The operating system cannot run this application program.

&H800700C8      The code segment cannot be greater than or equal to 64KB.

&H800700C9      The operating system cannot run %1.

&H800700CA      The operating system cannot run %1.

&H800700CB      The system could not find the environment option that was entered.

&H800700CD      No process in the command subtree has a signal handler.

&H800700CE      The filename or extension is too long.

&H800700CF      The ring 2 stack is in use.

&H800700D0      The global filename characters, * or ?, are entered incorrectly or too many global filename characters are specified.

&H800700D1      The signal being posted is not correct.

&H800700D2      The signal handler cannot be set.

&H800700D4      The segment is locked and cannot be reallocated.

&H800700D6      Too many dynamic link modules are attached to this program or dynamic link module.

&H800700D7      Can't nest calls to LoadModule.

&H800700E6      The pipe state is invalid.

&H800700E7      All pipe instances are busy.

&H800700E8      The pipe is being closed.

&H800700E9      No process is on the other end of the pipe.

&H800700EA      More data is available.

&H800700F0      The session was cancelled.

&H800700FE      The specified extended attribute name was invalid.

&H800700FF      The extended attributes are inconsistent.

&H80070103      No more data is available.

&H8007010A      The Copy API cannot be used.

&H8007010B      The directory name is invalid.

&H80070113      The extended attributes did not fit in the buffer.

&H80070114      The extended attribute file on the mounted file system is corrupt.

&H80070115      The extended attribute table file is full.

&H80070116      The specified extended attribute handle is invalid.

&H8007011A      The mounted file system does not support extended attributes.

&H80070120      Attempt to release mutex not owned by caller.

&H8007012A      Too many posts were made to a semaphore.

&H8007012B      Only part of a Read/WriteProcessMemory request was completed.

&H8007013D      The system cannot find message for message number 0x%1 in message file for %2.

&H800701E7      Attempt to access invalid address.

&H80070216      Arithmetic result exceeded 32 bits.

&H80070217      There is a process on other end of the pipe.

&H80070218      Waiting for a process to open the other end of the pipe.

&H800703E2      Access to the extended attribute was denied.

&H800703E3      The I/O operation has been aborted because of either a thread exit or an application request.

&H800703E4      Overlapped I/O event is not in a signalled state.

&H800703E5      Overlapped I/O operation is in progress.

&H800703E6      Invalid access to memory location.

&H800703E7      Error performing inpage operation.

&H800703E9      Recursion too deep, stack overflowed.

&H800703EA      The window cannot act on the sent message.

&H800703EB      Cannot complete this function.

&H800703EC      Invalid flags.

&H800703ED      The volume does not contain a recognized file system. Please make sure that all required file system drivers are loaded and that the volume is not corrupt.

&H800703EE      The volume for a file has been externally altered such that the opened file is no longer valid.

&H800703EF      The requested operation cannot be performed in full-screen mode.

&H800703F0      An attempt was made to reference a token that does not exist.

&H800703F1      The configuration registry database is corrupt.

&H800703F2      The configuration registry key is invalid.

&H800703F3      The configuration registry key could not be opened.

&H800703F4      The configuration registry key could not be read.

&H800703F5      The configuration registry key could not be written.

&H800703F6      One of the files in the Registry database had to be recovered by use of a log or alternate copy. The recovery was successful.

&H800703F7      The Registry is corrupt. The structure of one of the files that contains Registry data is corrupt, or the system's image of the file in memory is corrupt, or the file could not be recovered because the alternate copy or log was absent or corrupt.

&H800703F8      An I/O operation initiated by the Registry failed unrecoverably. The Registry could not read in, or write out, or flush, one of the files that contain the system's image of the Registry.

&H800703F9      The system has attempted to load or restore a file into the Registry, but the specified file is not in a Registry file format.

&H800703FA      Illegal operation attempted on a Registry key which has been marked for deletion.

&H800703FB      System could not allocate the required space in a Registry log.

&H800703FC      Cannot create a symbolic link in a Registry key that already has subkeys or values.

&H800703FD      Cannot create a stable subkey under a volatile parent key.

&H800703FE      A notify change request is being completed and the information is not being returned in the caller's buffer. The caller now needs to enumerate the files to find the changes.

&H8007041B      A stop control has been sent to a service which other running services are dependent on.

&H8007041C      The requested control is not valid for this service

&H8007041D      The service did not respond to the start or control request in a timely fashion.

&H8007041E      A thread could not be created for the service.

&H8007041F      The service database is locked.

&H80070420      An instance of the service is already running.

&H80070421      The account name is invalid or does not exist.

&H80070422      The specified service is disabled and cannot be started.

&H80070423      Circular service dependency was specified.

&H80070424      The specified service does not exist as an installed service.

&H80070425      The service cannot accept control messages at this time.

&H80070426      The service has not been started.

&H80070427      The service process could not connect to the service controller.

&H80070428      An exception occurred in the service when handling the control request.

&H80070429      The database specified does not exist.

&H8007042A      The service has returned a service-specific error code.

&H8007042B      The process terminated unexpectedly.

&H8007042C      The dependency service or group failed to start.

&H8007042D      The service did not start due to a logon failure.

&H8007042E      After starting, the service hung in a start-pending state.

&H8007042F      The specified service database lock is invalid.

&H80070430      The specified service has been marked for deletion.

&H80070431      The specified service already exists.

&H80070432      The system is currently running with the last-known-good configuration.

&H80070433      The dependency service does not exist or has been marked for deletion.

&H80070434      The current boot has already been accepted for use as the last-known-good control set.

&H80070435      No attempts to start the service have been made since the last boot.

&H80070436      The name is already in use as either a service name or a service display name.

&H8007044C      The physical end of the tape has been reached.

&H8007044D      A tape access reached a filemark.

&H8007044E      Beginning of tape or partition was encountered.

&H8007044F      A tape access reached the end of a set of files.

&H80070450      No more data is on the tape.

&H80070451      Tape could not be partitioned.

&H80070452      When accessing a new tape of a multivolume partition, the current blocksize is incorrect.

&H80070453      Tape partition information could not be found when loading a tape.

&H80070454      Unable to lock the media eject mechanism.

&H80070455      Unable to unload the media.

&H80070456      Media in drive may have changed.

&H80070457      The I/O bus was reset.

&H80070458      No media in drive.

&H80070459      No mapping for the Unicode character exists in the target multi-byte code page.

&H8007045A      A dynamic link library (DLL) initialization routine failed.

&H8007045B      A system shutdown is in progress.

&H8007045C      Unable to abort the system shutdown because no shutdown was in progress.

&H8007045D      The request could not be performed because of an I/O device error.

&H8007045E      No serial device was successfully initialized. The serial driver will unload.

&H8007045F      Unable to open a device that was sharing an interrupt request (IRQ) with other devices. At least one other device that uses that IRQ was already opened.

&H80070460      A serial I/O operation was completed by another write to the serial port. (The IOCTL_SERIAL_XOFF_COUNTER reached zero.)

&H80070461      A serial I/O operation completed because the time-out period expired. (The IOCTL_SERIAL_XOFF_COUNTER did not reach zero.)

&H80070462      No ID address mark was found on the floppy disk.

&H80070463      Mismatch between the floppy disk sector ID field and the floppy disk controller track address.

&H80070464      The floppy disk controller reported an error that is not recognized by the floppy disk driver.

&H80070465      The floppy disk controller returned inconsistent results in its registers.

&H80070466      While accessing the hard disk, a recalibrate operation failed, even after retries.

&H80070467      While accessing the hard disk, a disk operation failed even after retries.

&H80070468      While accessing the hard disk, a disk controller reset was needed, but even that failed.

&H80070469      Physical end of tape encountered.

&H8007046A      Not enough server storage is available to process this command.

&H8007046B      A potential deadlock condition has been detected.

&H8007046C      The base address or the file offset specified does not have the proper alignment.

&H80070474      An attempt to change the system power state was vetoed by another application or driver.

&H80070475      The system BIOS failed an attempt to change the system power state.

&H8007047E      The specified program requires a newer version of Windows.

&H8007047F      The specified program is not a Windows or MS-DOS program.

&H80070480      Cannot start more than one instance of the specified program.

&H80070481      The specified program was written for an older version of Windows.

&H80070482      One of the library files needed to run this application is damaged.

&H80070483      No application is associated with the specified file for this operation.

&H80070484      An error occurred in sending the command to the application.

&H80070485      One of the library files needed to run this application cannot be found.

&H800704B0      The specified device name is invalid.

&H800704B1      The device is not currently connected but it is a remembered connection.

&H800704B2      An attempt was made to remember a device that had previously been remembered.

&H800704B3      No network provider accepted the given network path.

&H800704B4      The specified network provider name is invalid.

&H800704B5      Unable to open the network connection profile.

&H800704B6      The network connection profile is corrupt.

&H800704B7      Cannot enumerate a non-container.

&H800704B8      An extended error has occurred.

&H800704B9      The format of the specified group name is invalid.

&H800704BA      The format of the specified computer name is invalid.

&H800704BB      The format of the specified event name is invalid.

&H800704BC      The format of the specified domain name is invalid.

&H800704BD      The format of the specified service name is invalid.

&H800704BE      The format of the specified network name is invalid.

&H800704BF      The format of the specified share name is invalid.

&H800704C0      The format of the specified password is invalid.

&H800704C1      The format of the specified message name is invalid.

&H800704C2      The format of the specified message destination is invalid.

&H800704C3      The credentials supplied conflict with an existing set of credentials.

&H800704C4      An attempt was made to establish a session to a network server, but there are already too many sessions established to that server.

&H800704C5      The workgroup or domain name is already in use by another computer on the network.

&H800704C6      The network is not present or not started.

&H800704C7      The operation was cancelled by the user.

&H800704C8      The requested operation cannot be performed on a file with a user mapped section open.

&H800704C9      The remote system refused the network connection.

&H800704CA      The network connection was gracefully closed.

&H800704CB      The network transport endpoint already has an address associated with it.

&H800704CC      An address has not yet been associated with the network endpoint.

&H800704CD      An operation was attempted on a non-existent network connection.

&H800704CE      An invalid operation was attempted on an active network connection.

&H800704CF      The remote network is not reachable by the transport.

&H800704D0      The remote system is not reachable by the transport.

&H800704D1      The remote system does not support the transport protocol.

&H800704D2      No service is operating at the destination network endpoint on the remote system.

&H800704D3      The request was aborted.

&H800704D4      The network connection was aborted by the local system.

&H800704D5      The operation could not be completed. A retry should be performed.

&H800704D6      A connection to the server could not be made because the limit on the number of concurrent connections for this account has been reached.

&H800704D7      Attempting to login during an unauthorized time of day for this account.

&H800704D8      The account is not authorized to login from this station.

&H800704D9      The network address could not be used for the operation requested.

&H800704DA      The service is already registered.

&H800704DB      The specified service does not exist.

&H800704DC      The operation being requested was not performed because the user has not been authenticated.

&H800704DD      The operation being requested was not performed because the user has not logged on to the network. The specified service does not exist.

&H800704DE      Return that wants caller to continue with work in progress.

&H800704DF      An attempt was made to perform an initialization operation when initialization has already been completed.

&H800704E0      No more local devices.

&H80070514      Not all privileges referenced are assigned to the caller.

&H80070515      Some mapping between account names and security IDs was not done.

&H80070516      No system quota limits are specifically set for this account.

&H80070517      No encryption key is available. A well-known encryption key was returned.

&H80070518      The NT password is too complex to be converted to a LAN Manager password. The LAN Manager password returned is a NULL string.

&H80070519      The revision level is unknown.

&H8007051A      Indicates two revision levels are incompatible.

&H8007051B      This security ID may not be assigned as the owner of this object.

&H8007051C      This security ID may not be assigned as the primary group of an object.

&H8007051D      An attempt has been made to operate on an impersonation token by a thread that is not currently impersonating a client.

&H8007051E      The group may not be disabled.

&H8007051F      There are currently no logon servers available to service the logon request.

&H80070520       A specified logon session does not exist. It may already have been terminated.

&H80070521       A specified privilege does not exist.

&H80070522       A required privilege is not held by the client.

&H80070523      The name provided is not a properly formed account name.

&H80070524      The specified user already exists.

&H80070525      The specified user does not exist.

&H80070526      The specified group already exists.

&H80070527      The specified group does not exist.

&H80070528      Either the specified user account is already a member of the specified group, or the specified group cannot be deleted because it contains a member.

&H80070529      The specified user account is not a member of the specified group account.

&H8007052A      The last remaining administration account cannot be disabled or deleted.

&H8007052B      Unable to update the password. The value provided as the current password is incorrect.

&H8007052C      Unable to update the password. The value provided for the new password contains values that are not allowed in passwords.

&H8007052D      Unable to update the password because a password update rule has been violated.

&H8007052E      Logon failure: unknown user name or bad password.

&H8007052F      Logon failure: user account restriction.

&H80070530      Logon failure: account logon time restriction violation.

&H80070531      Logon failure: user not allowed to log on to this computer.

&H80070532      Logon failure: the specified account password has expired.

&H80070533      Logon failure: account currently disabled.

&H80070534      No mapping between account names and security IDs was done.

&H80070535      Too many local user identifiers (LUIDs) were requested at one time.

&H80070536      No more local user identifiers (LUIDs) are available.

&H80070537      The subauthority part of a security ID is invalid for this particular use.

&H80070538      The access control list (ACL) structure is invalid.

&H80070539      The security ID structure is invalid.

&H8007053A      The security descriptor structure is invalid.

&H8007053C      The inherited access control list (ACL) or access control entry (ACE) could not be built.

&H8007053D      The server is currently disabled.

&H8007053E      The server is currently enabled.

&H8007053F      The value provided was an invalid value for an identifier authority.

&H80070540      No more memory is available for security information updates.

&H80070541      The specified attributes are invalid, or incompatible with the attributes for the group as a whole.

&H80070542      Either a required impersonation level was not provided, or the provided impersonation level is invalid.

&H80070543      Cannot open an anonymous level security token.

&H80070544      The validation information class requested was invalid.

&H80070545      The type of the token is inappropriate for its attempted use.

&H80070546      Unable to perform a security operation on an object which has no associated security.

&H80070547      Indicates a Windows NT Server could not be contacted or that objects within the domain are protected such that necessary information could not be retrieved.

&H80070548      The security account manager (SAM) or local security authority (LSA) server was in the wrong state to perform the security operation.

&H80070549      The domain was in the wrong state to perform the security operation.

&H8007054A      This operation is only allowed for the Primary Domain Controller of the domain.

&H8007054B      The specified domain did not exist.

&H8007054C      The specified domain already exists.

&H8007054D      An attempt was made to exceed the limit on the number of domains per server.

&H8007054E      Unable to complete the requested operation because of either a catastrophic media failure or a data structure corruption on the disk.

&H8007054F      The security account database contains an internal inconsistency.

&H80070550      Generic access types were contained in an access mask which should already be mapped to non-generic types.

&H80070551      A security descriptor is not in the right format (absolute or self-relative).

&H80070552      The requested action is restricted for use by logon processes only. The calling process has not registered as a logon process.

&H80070553      Cannot start a new logon session with an ID that is already in use.

&H80070554      A specified authentication package is unknown.

&H80070555      The logon session is not in a state that is consistent with the requested operation.

&H80070556      The logon session ID is already in use.

&H80070557      A logon request contained an invalid logon type value.

&H80070558      Unable to impersonate via a named pipe until data has been read from that pipe.

&H80070559      The transaction state of a Registry subtree is incompatible with the requested operation.

&H8007055A      An internal security database corruption has been encountered.

&H8007055B      Cannot perform this operation on built-in accounts.

&H8007055C      Cannot perform this operation on this built-in special group.

&H8007055D      Cannot perform this operation on this built-in special user.

&H8007055E      The user cannot be removed from a group because the group is currently the user's primary group.

&H8007055F      The token is already in use as a primary token.

&H80070560      The specified local group does not exist.

&H80070561      The specified account name is not a member of the local group.

&H80070562      The specified account name is already a member of the local group.

&H80070563      The specified local group already exists.

&H80070564      Logon failure: the user has not been granted the requested logon type at this computer.

&H80070565      The maximum number of secrets that may be stored in a single system has been exceeded.

&H80070566      The length of a secret exceeds the maximum length allowed.

&H80070567      The local security authority database contains an internal inconsistency.

&H80070568      During a logon attempt, the user's security context accumulated too many security IDs.

&H80070569      Logon failure: the user has not been granted the requested logon type at this computer.

&H8007056A      A cross-encrypted password is necessary to change a user password.

&H8007056B      A new member could not be added to a local group because the member does not exist.

&H8007056C      A new member could not be added to a local group because the member has the wrong account type.

&H8007056D      Too many security IDs have been specified.

&H8007056E      A cross-encrypted password is necessary to change this user password.

&H8007056F      Indicates an ACL contains no inheritable components

&H80070570      The file or directory is corrupt and non-readable.

&H80070571      The disk structure is corrupt and non-readable.

&H80070572      There is no user session key for the specified logon session.

&H80070573      The service being accessed is licensed for a particular number of connections. No more connections can be made to the service at this time because there are already as many connections as the service can accept.

&H80070578      Invalid window handle.

&H80070579      Invalid menu handle.

&H8007057A      Invalid cursor handle.

&H8007057B      Invalid accelerator table handle.

&H8007057C      Invalid hook handle.

&H8007057D      Invalid handle to a multiple-window position structure.

&H8007057E      Cannot create a top-level child window.

&H8007057F      Cannot find window class.

&H80070580      Invalid window, belongs to other thread.

&H80070581      Hot key is already registered.

&H80070582      Class already exists.

&H80070583      Class does not exist.

&H80070584      Class still has open windows.

&H80070585      Invalid index.

&H80070586      Invalid icon handle.

&H80070587      Using private DIALOG window words.

&H80070588      The listbox identifier was not found.

&H80070589      No wildcards were found.

&H8007058A      Thread does not have a clipboard open.

&H8007058B      Hot key is not registered.

&H8007058C      The window is not a valid dialog window.

&H8007058D      Control ID not found.

&H8007058E      Invalid message for a combo box because it does not have an edit control.

&H8007058F      The window is not a combo box.

&H80070590      Height must be less than 256.

&H80070591      Invalid device context (DC) handle.

&H80070592      Invalid hook procedure type.

&H80070593      Invalid hook procedure.

&H80070594      Cannot set non-local hook without a module handle.

&H80070595      This hook procedure can only be set globally.

&H80070596      The journal hook procedure is already installed.

&H80070597      The hook procedure is not installed.

&H80070598      Invalid message for single-selection listbox.

&H80070599      LB_SETCOUNT sent to non-lazy listbox.

&H8007059A      This list box does not support tab stops.

&H8007059B      Cannot destroy object created by another thread.

&H8007059C      Child windows cannot have menus.

&H8007059D      The window does not have a system menu.

&H8007059E      Invalid message box style.

&H8007059F      Invalid system-wide (SPI_*) parameter.

&H800705A0      Screen already locked.

&H800705A1      All handles to windows in a multiple-window position structure must have the same parent.

&H800705A2      The window is not a child window.

&H800705A3      Invalid GW_* command.

&H800705A4      Invalid thread identifier.

&H800705A5      Cannot process a message from a window that is not a multiple document interface (MDI) window.

&H800705A6      Popup menu already active.

&H800705A7      The window does not have scroll bars.

&H800705A8      Scroll bar range cannot be greater than 0x7FFF.

&H800705A9      Cannot show or remove the window in the way specified.

&H800705AA      Insufficient system resources exist to complete the requested service.

&H800705AB      Insufficient system resources exist to complete the requested service.

&H800705AC      Insufficient system resources exist to complete the requested service.

&H800705AD      Insufficient quota to complete the requested service.

&H800705AE      Insufficient quota to complete the requested service.

&H800705AF      The paging file is too small for this operation to complete.

&H800705B0      A menu item was not found.

&H800705DC      The event log file is corrupt.

&H800705DD      No event log file could be opened, so the event logging service did not start.

&H800705DE      The event log file is full.

&H800705DF      The event log file has changed between reads.

&H800706A4      The string binding is invalid.

&H800706A5      The binding handle is not the correct type.

&H800706A6      The binding handle is invalid.

&H800706A7      The RPC protocol sequence is not supported.

&H800706A8      The RPC protocol sequence is invalid.

&H800706A9      The string universal unique identifier (UUID) is invalid.

&H800706AA      The endpoint format is invalid.

&H800706AB      The network address is invalid.

&H800706AC      No endpoint was found.

&H800706AD      The timeout value is invalid.

&H800706AE      The object universal unique identifier (UUID) was not found.

&H800706AF      The object universal unique identifier (UUID) has already been registered.

&H800706B0      The type universal unique identifier (UUID) has already been registered.

&H800706B1      The RPC server is already listening.

&H800706B2      No protocol sequences have been registered.

&H800706B3      The RPC server is not listening.

&H800706B4      The manager type is unknown.

&H800706B5      The interface is unknown.

&H800706B6      There are no bindings.

&H800706B7      There are no protocol sequences.

&H800706B8      The endpoint cannot be created.

&H800706B9      Not enough resources are available to complete this operation.

&H800706BA      The RPC server is unavailable.

&H800706BB      The RPC server is too busy to complete this operation.

&H800706BC      The network options are invalid.

&H800706BD      There is not a remote procedure call active in this thread.

&H800706BE      The remote procedure call failed.

&H800706BF      The remote procedure call failed and did not execute.

&H800706C0      A remote procedure call (RPC) protocol error occurred.

&H800706C2      The transfer syntax is not supported by the RPC server.

&H800706C4      The universal unique identifier (UUID) type is not supported.

&H800706C5      The tag is invalid.

&H800706C6      The array bounds are invalid.

&H800706C7      The binding does not contain an entry name.

&H800706C8      The name syntax is invalid.

&H800706C9      The name syntax is not supported.

&H800706CB      No network address is available to use to construct a universal unique identifier (UUID).

&H800706CC      The endpoint is a duplicate.

&H800706CD      The authentication type is unknown.

&H800706CE      The maximum number of calls is too small.

&H800706CF      The string is too long.

&H800706D0      The RPC protocol sequence was not found.

&H800706D1      The procedure number is out of range.

&H800706D2      The binding does not contain any authentication information.

&H800706D3      The authentication service is unknown.

&H800706D4      The authentication level is unknown.

&H800706D5      The security context is invalid.

&H800706D6      The authorization service is unknown.

&H800706D7      The entry is invalid.

&H800706D8      The server endpoint cannot perform the operation.

&H800706D9      There are no more endpoints available from the endpoint mapper.

&H800706DA      No interfaces have been exported.

&H800706DB      The entry name is incomplete.

&H800706DC      The version option is invalid.

&H800706DD      There are no more members.

&H800706DE      There is nothing to unexport.

&H800706DF      The interface was not found.

&H800706E0      The entry already exists.

&H800706E1      The entry is not found.

&H800706E2      The name service is unavailable.

&H800706E3      The network address family is invalid.

&H800706E4      The requested operation is not supported.

&H800706E5      No security context is available to allow impersonation.

&H800706E6      An internal error occurred in a remote procedure call (RPC).

&H800706E7      The RPC server attempted an integer division by zero.

&H800706E8      An addressing error occurred in the RPC server.

&H800706E9      A floating-point operation at the RPC server caused a division by zero.

&H800706EA      A floating-point underflow occurred at the RPC server.

&H800706EB      A floating-point overflow occurred at the RPC server.

&H800706EC      The list of RPC servers available for the binding of auto handles has been exhausted.

&H800706ED      Unable to open the character translation table file.

&H800706EE      The file containing the character translation table has fewer than 512 bytes.

&H800706EF      A null context handle was passed from the client to the host during a remote procedure call.

&H800706F1      The context handle changed during a remote procedure call.

&H800706F2      The binding handles passed to a remote procedure call do not match.

&H800706F3      The stub is unable to get the remote procedure call handle.

&H800706F4      A null reference pointer was passed to the stub.

&H800706F5      The enumeration value is out of range.

&H800706F6      The byte count is too small.

&H800706F7      The stub received bad data.

&H800706F8      The supplied user buffer is not valid for the requested operation.

&H800706F9      The disk media is not recognized. It may not be formatted.

&H800706FA      The workstation does not have a trust secret.

&H800706FB      The SAM database on the Windows NT Server does not have a computer account for this workstation trust relationship.

&H800706FC      The trust relationship between the primary domain and the trusted domain failed.

&H800706FD      The trust relationship between this workstation and the primary domain failed.

&H800706FE      The network logon failed.

&H800706FF      A remote procedure call is already in progress for this thread.

&H80070700      An attempt was made to logon, but the network logon service was not started.

&H80070701      The user's account has expired.

&H80070702      The redirector is in use and cannot be unloaded.

&H80070703      The specified printer driver is already installed.

&H80070704      The specified port is unknown.

&H80070705      The printer driver is unknown.

&H80070706      The print processor is unknown.

&H80070707      The specified separator file is invalid.

&H80070708      The specified priority is invalid.

&H80070709      The printer name is invalid.

&H8007070A      The printer already exists.

&H8007070B      The printer command is invalid.

&H8007070C      The specified datatype is invalid.

&H8007070D      The Environment specified is invalid.

&H8007070E      There are no more bindings.

&H8007070F      The account used is an interdomain trust account. Use your global user account or local user account to access this server.

&H80070710      The account used is a Computer Account. Use your global user account or local user account to access this server.

&H80070711      The account used is an server trust account. Use your global user account or local user account to access this server.

&H80070712      The name or security ID (SID) of the domain specified is inconsistent with the trust information for that domain.

&H80070713      The server is in use and cannot be unloaded.

&H80070714      The specified image file did not contain a resource section.

&H80070715      The specified resource type can not be found in the image file.

&H80070716      The specified resource name can not be found in the image file.

&H80070717      The specified resource language ID cannot be found in the image file.

&H80070718      Not enough quota is available to process this command.

&H80070719      No interfaces have been registered.

&H8007071A      The server was altered while processing this call.

&H8007071B      The binding handle does not contain all required information.

&H8007071C      Communications failure.

&H8007071D      The requested authentication level is not supported.

&H8007071E      No principal name registered.

&H8007071F      The error specified is not a valid Windows RPC error code.

&H80070720      A UUID that is valid only on this computer has been allocated.

&H80070721      A security package specific error occurred.

&H80070722      Thread is not cancelled.

&H80070723      Invalid operation on the encoding/decoding handle.

&H80070724      Incompatible version of the serializing package.

&H80070725      Incompatible version of the RPC stub.

&H8007076A      The group member was not found.

&H8007076B      The endpoint mapper database could not be created.

&H8007076C      The object universal unique identifier (UUID) is the nil UUID.

&H8007076D      The specified time is invalid.

&H8007076E      The specified Form name is invalid.

&H8007076F      The specified Form size is invalid

&H80070770      The specified Printer handle is already being waited on

&H80070771      The specified Printer has been deleted

&H80070772      The state of the Printer is invalid

&H80070773      The user must change his password before he logs on the first time.

&H80070774      Could not find the domain controller for this domain.

&H80070775      The referenced account is currently locked out and may not be logged on to.

&H800707D0      The pixel format is invalid.

&H800707D1      The specified driver is invalid.

&H800707D2      The window style or class attribute is invalid for this operation.

&H800707D3      The requested metafile operation is not supported.

&H800707D4      The requested transformation operation is not supported.

&H800707D5      The requested clipping operation is not supported.

&H8007089A      The specified username is invalid.

&H800708CA      This network connection does not exist.

&H80070961      This network connection has files open or requests pending.

&H80070962      Active connections still exist.

&H80070964      The device is in use by an active process and cannot be disconnected.

&H80070BB8      The specified print monitor is unknown.

&H80070BB9      The specified printer driver is currently in use.

&H80070BBA      The spool file was not found.

&H80070BBB      A StartDocPrinter call was not issued.

&H80070BBC      An AddJob call was not issued.

&H80070BBD      The specified print processor has already been installed.

&H80070BBE      The specified print monitor has already been installed.

&H80070FA0      WINS encountered an error while processing the command.

&H80070FA1      The local WINS can not be deleted.

&H80070FA2      The importation from the file failed.

&H80070FA3      The backup Failed. Was a full backup done before ?

&H80070FA4      The backup Failed. Check the directory that you are backing the database to.

&H80070FA5      The name does not exist in the WINS database.

&H80070FA6      Replication with a non-configured partner is not allowed.

&H800717E6      The list of servers for this workgroup is not currently available

&H80080001      Attempt to create a class object failed

&H80080002      OLE service could not bind object

&H80080003      RPC communication failed with OLE service

&H80080004      Bad path to object

&H80080005      Server execution failed

&H80080006      OLE service could not communicate with the object server

&H80080007      Moniker path could not be normalized

&H80080008      Object server is stopping when OLE service contacts it

&H80080009      An invalid root block pointer was specified

&H80080010      An allocation chain contained an invalid link pointer

&H80080011      The requested allocation size was too large


 
Categories: VB

Why do I need SavePicture when I can’t change the picture loaded into the PictureBox anyways?

You can. Using Circle, Line, Pset and other drawing methods of the PictureBox control you can draw shapes to the client area of the PictureBox. You can also use PaintPicture to paint from another Form or PictureBox into another Form or PictureBox.

I used SavePicture and the image wasn’t saved with my additional changes (using the previous question’s methods).

Make sure AutoRedraw = True, and when you call SavePicture, pass the Image Property of the PictureBox like so:

SavePicture Picture1.Image, sFile

The Picture property used here will save the originally loaded picture (using LoadPicture method) but the Image property will include additional changes made through VB drawing methods etc.

 

Tip Submitted By: Michele Leroux


 
Categories: VB

Using the Shell method, in any version of Visual Basic, does not allow you to do this. You will need to use an API call and wait for the called program to end. We will discuss how to do this in 16-bit versions of Visual Basic and 32-bit versions.


Shelling From Visual Basic 16-bit

This code will work under any 16-bit version of Visual Basic. Waiting for a program to end is simple.


Declare

Declare Function GetModuleUsage Lib "Kernel" (ByVal _
     hModule As Integer) As Integer
Declare Function WinExec Lib "Kernel" (ByVal lpCmdLine _
     As String, ByVal nCmdShow As Integer) As Integer
Global Const SW_HIDE = 0
Global Const SW_SHOWNORMAL = 1
Global Const SW_NORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Global Const SW_SHOWMAXIMIZED = 3
Global Const SW_MAXIMIZE = 3
Global Const SW_SHOWNOACTIVATE = 4
Global Const SW_SHOW = 5
Global Const SW_MINIMIZE = 6
Global Const SW_SHOWMINNOACTIVE = 7
Global Const SW_SHOWNA = 8
Global Const SW_RESTORE = 9


Code

Sub DoShell (sShellString As String, iWinType As Integer)
     Dim iInstanceHandle As Integer
     Dim X As Integer
     iInstanceHandle = WinExec(sShellString, iWinType)
     Do While GetModuleUsage(iInstanceHandle) > 0
           X = DoEvents()
     Loop
End Sub


Usage

DoShell "C:\DOS\FORMAT.COM", SW_HIDE

This code uses the WinExec API call to start the program and return the instance handle. We simply sit in a DoEvents loop until GetModuleUsage (using the instance handle as the parameter) tells us that the instance of that called program is gone. You also can start the program in any of the SW_ modes you like, including hiding it!


Shelling From Visual Basic 32-bit

Shelling from a 16-bit version of Visual Basic is easy. Things are not so easy in 32-bit environments. With Windows 95 or Windows NT, every program runs its own distinct environment, which precludes polling if an instance of a program still exists. The following code will do the trick.


Declare

Declare Function OpenProcess Lib "kernel32" (ByVal _
     dwDesiredaccess&, ByVal bInherithandle&, _
     ByVal dwProcessid&) As Long
Declare Function GetExitCodeProcess Lib "kernel32" _
     (ByVal hProcess As Long, lpexitcode As Long) As Long
Const STILL_ACTIVE = &H103
Const PROCESS_QUERY_INFORMATION = &H400


Code

Sub ShellWait(sCommandLine As String)
     Dim hShell As Long
     Dim hProc As Long
     Dim lExit As Long
     hShell = Shell(sCommandLine, vbNormalFocus)
     hProc = OpenProcess(PROCESS_QUERY_INFORMATION, _
           False, hShell)
     Do
           GetExitCodeProcess hProc, lExit
           DoEvents
     Loop While lExit = STILL_ACTIVE
End Sub


Usage

ShellWait sCommandLine:="notepad.exe"

The trick with this code, as opposed to the method that the Microsoft KnowledgeBase has, is that it Shells the required program and then opens a process. It then waits for that process to finish. This way, if the program you Shelled calls other programs, you can continue on after the main (parent) program closes.

For example, if you Shelled the Internet Explorer, and the user started a download, you would not be able to continue until that download is done, even if the user closed Explorer. There might be times when you require this behavior (refer to article Q96844 of the Visual Basic KnowledgeBase). That code gives you an alternative.

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.


 
Categories: VB

This is a good idea when, for instance, you need a Form to re-paint.


Code

Sub FormWait (frmIn As Form)
     Do While frmIn Is Screen.ActiveForm
           DoEvents
     Loop
End Sub


Usage

FormWait frmMain

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.
Parts of this tip was submitted by: Barth Riely


 
Categories: VB

I found a way to open a database without using INI files at all.


Set dbMyDatabase = OpenDatabase(Name:=App.Path & _
     "\protected-database.mdb", Exclusive:=False, _
     ReadOnly:=False, Connect:=";PWD=marvin")

Just provide the password as part of the connect string.

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.
Parts of this tip was submitted by: David McCarter


 
Categories: VB

Wouldn't it be nice if you could also place the mouse cursor over that button? Unfortunately, Visual Basic does not have a built-in method to accomplish this. I have found that it is possible to move the mouse cursor by using a Windows API (Application Programmer's Interface) call. The instructions below illustrate how to use this method.

Start a new project which includes one form. Place two buttons on the form. Add a new module to the project (File, New Module). In the General, Declarations section of the module, place the following code, all on one line:

Declare Sub SetCursorPos Lib "User" (ByVal X As Integer, ByVal Y As Integer)

In the Click event for Command1, place the following code:

x% = (Form1.Left + Command2.Left + Command2.Width / 2 + 60) / Screen.TwipsPerPixelX 
y% = (Form1.Top + Command2.Top + Command2.Height / 2 + 360) / Screen.TwipsPerPixelY
SetCursorPos x%, y%

Press F5 to run the program. When you click on Command1 the mouse cursor will be placed approximately on the center of the Command2 button.

The calculation of the x and y coordinates for the SetCursorPos routine could use some explanation.

SetCursorPos expects these to be the pixel locations. In a 640 by 480 (standard VGA) screen, the command SetCursorPos 320, 240 would place the cursor in the center of the screen. Visual Basic, however, normally uses "twips" instead of pixels. The ratio of twips to pixels can vary depending on the screen mode. Fortunately, Visual Basic includes the TwipsPerPixelX and wipsPerPixelYproperties so that we can easily convert VB's twips to Windows pixels.

In our example we calculate the x coordinate by taking the left property of our form, adding the left property of Command2 and half of the width of the button to get the center of the button. The "60" that we added is to compensate for the form's border. The y coordinate is calculated in the same manner. The "360" is to compensate for the form's border and the form's title bar.

 

Tip Submitted By: Robert Wilcox


 
Categories: VB

Consider the following code:

Dim cnCollect As Collection
Dim sString As String
Dim sKey As String
Dim I As Integer
Dim vStart
Dim vFinish
     vStart = Timer
     Set cnCollect = New Collection
     sString = "test"
     For I = 1 To 1000
           sKey = sString & Trim$(Str(I))
           cnCollect.Add sString
     Next I
     vFinish = Timer
     txtElapsed.Text = vFinish - vStart

On my 486-66 running NT with 20 MB RAM, the above code will register a difference of about 0.25 in the elapsed text box.If you change the line adding the string to the collection as follows:

cnCollect.Add sString, sKey

the code now registers an average of 2.1 in the elapsed text box. That is almost a factor of 10!

The ability to key a collection of data or objects is very powerfull, but requires a significant amount of overhead to accomplish. Use it prudently!

 

Tip Submitted By: J. Boyd Nolan, PE


 
Categories: VB

August 15, 2003
@ 02:44 AM

Declare

Private Declare Function mciSendString Lib "winmm.dll" _
   Alias "mciSendStringA" (ByVal lpstrCommand As String, _
   ByVal lpstrReturnString As String, ByVal uReturnLength As Long, _
   ByVal hwndCallback As Long) As Long
Sample Code
Sub OpenCDDoor()
  mciSendString "Set CDAudio Door Open Wait", 0&, 0&, 0&
End Sub
Sub CloseCDDoor()
  mciSendString "Set CDAudio Door Closed Wait", 0&, 0&, 0&
End Sub

 

Tip Submitted By: Malcolm Hubert


 
Categories: VB

Pass it the handle of the window you want to make topmost (or for which you wish to end that condition) and a true/ false flag to indicate whether it should be topmost.

'Declares for FormStayOnTop
Declare Sub SetWindowPos Lib "User" (ByVal hWnd As Integer, _
ByVal hWndInsertAfter As Integer, ByVal X As Integer, _
ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, _
ByVal wFlags As Integer)
Sub FormStayOnTop (varForm as Form, OnTop%)
   Handle% = varForm.hwnd
   Const Swp_Nosize = &H1
   Const SWP_Nomove = &H2
   Const Swp_NoActivate = &H10
   Const Swp_ShowWindow = &H40
   Const Hwnd_TopMost = -1
   Const Hwnd_NoTopMost = -2
   wFlags = SWP_Nomove Or Swp_Nosize Or _
              Swp_ShowWindow Or Swp_NoActivate
   Select Case OnTop%
      Case True
         PosFlag = Hwnd_TopMost
      Case False
         PosFlag = Hwnd_NoTopMost
   End Select
   SetWindowPos Handle%, PosFlag, 0, 0, 0, 0, wFlags
End Sub
'Declares for FormStayOnTop 32 bit version
Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Integer, _
ByVal hWndInsertAfter As Integer, ByVal X As Integer, _
ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, _
ByVal wFlags As Integer)
Sub FormStayOnTop (varForm as Form, OnTop%)
   Handle% = varForm.hwnd
   Const Swp_Nosize = &H1
   Const SWP_Nomove = &H2
   Const Swp_NoActivate = &H10
   Const Swp_ShowWindow = &H40
   Const Hwnd_TopMost = -1
   Const Hwnd_NoTopMost = -2
   wFlags = SWP_Nomove Or Swp_Nosize Or _
               Swp_ShowWindow Or Swp_NoActivate
   Select Case OnTop%
      Case True
         PosFlag = Hwnd_TopMost
      Case False
         PosFlag = Hwnd_NoTopMost
   End Select
   SetWindowPos Handle%, PosFlag, 0, 0, 0, 0, wFlags
End Sub

 

Tip Submitted By: Jeff Williams


 
Categories: VB

The cool thing about this code is that if a file does not have an associated program, then it will run the "Open With" window that allows the user to pick the program they want to file opened with. If the ShellExecute fails, then the code generates a error message box letting the user know exactly what went wrong.


How To Use LaunchFile

With the code below, I have done all the hard work. All you need to do is call it. The parameters are:

  • File - Full path along with the program or document name.
  • Verb (optional) - With the ShellExecute you can either open the program or file or have it print. Use "Open" or "Print" to let ShellExecute what you want to do. Leaving it blank will open the program or file.
  • Parameters (optional) - You can define command line parameters here for the program you are running.
  • ParenthWnd (optional) - Here is where you set the hWnd handle of the Visual Basic Form or UserControl you are calling this from.

There are two other routines here to strip out the path and file name needed to run ShellExecute.


Declare

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


Code

 

Public Sub LaunchFile(File As String, Optional Verb As String, _
Optional Parameters As String, Optional ParenthWnd As Long)
Dim sFile As String
Dim sPath As String
Dim lReturn As Long
Dim sMessage As String
 
    'Test incomming values
    If Len(Verb) = 0 Then
        Verb = "Open"
    End If
    If Len(Parameters) = 0 Then
        Parameters = vbNullString
    End If
    'Strip out the componets of the file info we need
    sFile = StripPath(File)
    sPath = StripFile(File)
    lReturn = ShellExecute(ParenthWnd, Verb, sFile, Parameters, sPath, vbNormalFocus)
    'Check to make sure the shell went okay
    Select Case lReturn
        Case Is = 31
            'There is no associated program for the specified file type
            'Give the user the choice on how to open the file
            sFile = "rundll32.exe shell32.dll,OpenAs_RunDLL " & sPath & sFile
                        lReturn = Shell(sFile, vbNormalFocus)
        Case 0
            sMessage = "System is out of memory, executable file is corrupt, or relocations are invalid."
        Case 2
            sMessage = "File was not found."
                Case 3
            sMessage = "Path was not found."
        Case 5
            sMessage = "Attempt was made to dynamically link to a task, or there was a sharing or network-protection error."
        Case 6
            sMessage = "Library required separate data segments for each task."
        Case 8
            sMessage = "There was insufficient memory to start the application."
        Case 10
            sMessage = "Windows version was incorrect."
        Case 11
            sMessage = "Executable file was invalid. Either it was not a Windows application or there was an error in the .EXE image."
        Case 12
            sMessage = "Application was designed for a different operating system."
        Case 13
            sMessage = "Application was designed for MS-DOS 4.0."
        Case 14
            sMessage = "Type of executable file was unknown."
        Case 15
            sMessage = "Attempt was made to load a real-mode application (developed for an earlier version of Windows)."
        Case 16
            sMessage = "Attempt was made to load a second instance of an executable file containing multiple data segments that were not marked read-only."
        Case 19
            sMessage = "Attempt was made to load a compressed executable file. the file must be decompressed before it can be loaded."
        Case 20
            sMessage = "Dynamic-link library (DLL) file was invalid. One of the DLLs required to run this application was corrupt."
               Case 21
            sMessage = "Application requires Microsoft Windows 32-bit extensions."
        Case Else
    End Select
    If Len(sMessage) > 0 Then
        'Display Error
        MsgBox sMessage, vbOKOnly + vbInformation, "Motiva"
    End If
End Sub

Function removes path from fully-qualified file name, returns file name only.

Public Function StripPath(PathFile As String) As String
Dim iFind As Integer
Dim iStart As Integer

    StripPath = PathFile
    iFind = InStr(PathFile, "\")
    Do While iFind
        iStart = iFind
        iFind = InStr(iStart + 1, PathFile, "\")
    Loop
    If iStart > 0 Then
        StripPath = Mid(PathFile, iStart + 1)
    End If
End Function

Function removes file name from fully-qualified file name, returns path only.

Public Function StripFile(PathFile As String) As String
Dim lStart As Long
Dim lPos As Long
Dim lLastAt As Long
    'Look for the last "\"
    Do
        lStart = lPos + 1
        lPos = InStr(lStart, PathFile, "\")
    Loop While lPos
    lLastAt = lStart - 1
    'Get all to the left
    StripFile = Left(PathFile, lLastAt)
End Function


Sample Code

LaunchFile "c:\windows\notepad.exe", , , Me.hwnd

 

Tip By: David McCarter


 
Categories: VB

August 15, 2003
@ 02:37 AM

Try adding a line with Sleep 1 after DoEvents to your tight loops, this will only cost you 1 ms and if you just call the sleep command every 150 or 200 passes, it doesn't cost you much. On my PC the procedure below shows 1% or less change to my CPU usage. If you REM out the sleep line CPU usage hits 100% quick.


Declare

Private Declare Sub Sleep Lib "Kernel32" (ByVal dwmilliseconds As Long)


Sample Code

Private Sub Command1_Click()
Dim iCounter As Integer
    Do
        'Your Process
        For iCounter = 1 To 10000
            DoEvents
            ' 200 seems like a good value to ensure
            ' min. slow down with min. load on CPU usage
            ' according to NT 40's Task Manager
            ' the next line will cost you t ms for every
            ' 200 passes
            If iCounter Mod 200 = 0 Then
                Sleep 1
            End If
        Next
    Loop
End Sub

 

Tip Submitted By: Jim Lewey

 

Editors Note: On my NT machine, calling Sleep after every 200 loops put my CPU usage to about 92%. I dropped it to 10 and my usage went to 1%. Just beware of this... your mileage might vary.


 
Categories: VB

August 15, 2003
@ 02:35 AM

The way I work around this is to set the with of the rect (EM_SETRECT) to my desired width when the form loads. I don't use the scroll bars property in the textbox. Instead, I place a horizontal scrollbar control below my textbox. I create my own sub that scrolls the text left and right by moving the rect (not changing size). I monitor the KeyUp and MouseUp events using the GetCaretPos function: I call the sub when required or if the scrollbar is changed.

Sub Form1_load (...etc...) 
Dim rtn&
Dim Posn As Rect
   rtn& = SendMessage(Text1.hWnd, EM_GETRECT, 0, Posn)
   'get original rect
   Posn.right = NewWidth%
   'formatting width you require
   rtn& = SendMessage(Text1.hWnd, EM_SETRECT, 0, Posn)
   'set new rect width
End Sub
Sub ScrollRect (ByVal hWnd%, direction%) 
Dim rtn&
Dim Posn As Rect
   rtn& = Send Message (hWnd%, EM_GETRECT, 0, Posn)
   'get current rect
   'to move rect left direction% is a negative number
   'to move rect right direction% is a positive number
   Posn.left = Posn.left + direction%
   Posn.right = Posn.right + direction%
   rtn& = SendMessage(hWnd%, EM_SETRECT, 0, Posn)
   'move rect left or right
End Sub

 

Tip By: Douglas Marquardt


 
Categories: VB

August 15, 2003
@ 02:34 AM

The MSCOMM VBX is great for creating communication programs, but it's overkill for dialing a phone number. Try the following code:

PhoneNumber$ = "(123) 456-7890" 
Open "COM2" For Output As #1 'or COM1
Print #1, "ATDT" & PhoneNumber$ & Chr$(13)
Close #1

 


 
Categories: VB

What I did was simply map the bytes using LSet and user-defined types. I use these as the basic conversions. If I am dealing with Motorola numbers in byte-form I simple reverse the bytes as they're inserted into b1, b2, etc. These are also handy when you have 1, 2, or 3 bytes and need to make a long-- but don't forget to pre-set the appropriate unprovided bytes with -1 for sign extension.

Here's what I did for converting bytes to long, single and double:

'These are used to convert bytes to integer. Individual byte values are
'put into the various positions (byte1 in b1, etc) and LSet moves the
'byte 'groups' to the number type indicated where the numeric
'equivalent is then available. Note: I gathered these from different
'places so the parameters look different. The best 'model' would be
'FourBytesToLong.
Private Type EightBytes
    b1 As Byte
    b2 As Byte
    b3 As Byte
    b4 As Byte
    b5 As Byte
    b6 As Byte
    b7 As Byte
    b8 As Byte
End Type
Private Type FourBytes
    b1 As Byte
    b2 As Byte
    b3 As Byte
    b4 As Byte
End Type
Private Type OneDouble
    dD As Double
End Type
Private Type OneSingle
    sngS As Single
End Type
Private Type OneLong
    lL As Long
End Type
Public Function EightBytesToDouble(ByVal packetData, dataStart As Integer) As Double
'Given 64 bits of a float number (in eight bytes), returns those 64 bits
'as a double (float).
Dim EB As EightBytes
Dim OD As OneDouble
    ' Set the 8 input bytes into a user-defined-type 8-byte field.
    EB.b1 = packetData(dataStart)
    EB.b2 = packetData(dataStart + 1)
    EB.b3 = packetData(dataStart + 2)
    EB.b4 = packetData(dataStart + 3)
    EB.b5 = packetData(dataStart + 4)
    EB.b6 = packetData(dataStart + 5)
    EB.b7 = packetData(dataStart + 6)
    EB.b8 = packetData(dataStart + 7)
    ' Now move the 8 bytes to a user-defined-type double field.
    ' LSet and user-defined fields allow this bit-for-bit move
    LSet OD = EB
    'Now return the 8 bytes as a double.
    EightBytesToDouble = OD.dD
End Function
Private Function FourBytesToLong(ByVal bFour) As Long
'Given 32 bits (in four bytes), returns those 32 bits as a long integer.
Dim FB As FourBytes
Dim OL As OneLong
    ' Set the 4 input bytes into a user-defined 4-byte field.
    FB.b1 = bFour(0)
    FB.b2 = bFour(1)
    FB.b3 = bFour(2)
    FB.b4 = bFour(3)
        ' Now move the 4 bytes to a user-defined long number field.
    ' LSet and user-defined fields allow this bit-for-bit move
    LSet OL = FB
    'Now return the 4 bytes as a long number.
    FourBytesToLong = OL.lL
End Function
Public Function FourBytesToSingle(ByVal bFour) As Single
'Given 32 bits of a float (in four bytes), returns those 32
'bits as a single float.
Dim FB As FourBytes
Dim OS As OneSingle
    ' Set the 4 input bytes into a user-defined-type 4-byte field.
    FB.b1 = bFour(0)
    FB.b2 = bFour(1)
    FB.b3 = bFour(2)
    FB.b4 = bFour(3)
        ' Now move the 4 bytes to a user-defined-type single float field.
    ' LSet and user-defined-type fields allow this bit-for-bit move
    LSet OS = FB
    'Now return the 4 bytes as a single float number.
    FourBytesToSingle = OS.sngS
End Function
Public Function TwoBytesToLong(ByVal bTwo) As Long
'Given 16 bits (in two bytes, lo-value, then hi-value), returns those 
'16 bits as a long integer. Since VB does not allow unsigned integers,
'this takes the two bytes containing an unsigned integer value
'(0 - 65535) and creates a long integer that preserves the value.
Dim FB As FourBytes
Dim OL As OneLong
    ' Set the 2 input bytes into a user-defined 4-byte field.
    FB.b1 = bTwo(0)
    FB.b2 = bTwo(1)
    FB.b3 = 0
    FB.b4 = 0
    ' Now move the 4 bytes to a user-defined long number field.
    ' LSet and user-defined fields allow this bit-for-bit move
    LSet OL = FB
    'Now return the 4 bytes as a long number.
    TwoBytesToLong = OL.lL
End Function

 

Tip Submitted by: Dave Hunt


 
Categories: VB

The following sample code shows how to retrieve the system’s default background color. There are many other system colors you might like to know about. Here is a list of the Windows 3.1 system colors:

Global Const COLOR_SCROLLBAR = 0
Global Const COLOR_BACKGROUND = 1
Global Const COLOR_ACTIVECAPTION = 2
Global Const COLOR_INACTIVECAPTION = 3
Global Const COLOR_MENU = 4
Global Const COLOR_WINDOW = 5
Global Const COLOR_WINDOWFRAME = 6
Global Const COLOR_MENUTEXT = 7
Global Const COLOR_WINDOWTEXT = 8
Global Const COLOR_CAPTIONTEXT = 9
Global Const COLOR_ACTIVEBORDER = 10
Global Const COLOR_INACTIVEBORDER = 11
Global Const COLOR_APPWORKSPACE = 12
Global Const COLOR_HIGHLIGHT = 13
Global Const COLOR_HIGHLIGHTTEXT = 14
Global Const COLOR_BTNFACE = 15
Global Const COLOR_BTNSHADOW = 16
Global Const COLOR_GRAYTEXT = 17
Global Const COLOR_BTNTEXT = 18
Global Const COLOR_ENDCOLORS = COLOR_BTNTEXT


Declare The Following

Declare Function GetSysColor Lib "User" (ByVal nIndex%) As Long

Code

Sub ColorFormBackground(frmForm as Form)
     Const COLOR_BACKGROUND = 1 'Desktop
     frmForm.BackColor = GetSysColor(COLOR_BACKGROUND)
End Sub


Usage

Private Sub Form_Load()
     ColorFormBackground Me
End Sub

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.
Parts of this tip was submitted by: Jeff Williams
Compatible With Visual Basic 3.0, Visual Basic 4.0 16-bit
Applies To Forms


 
Categories: VB

August 15, 2003
@ 02:27 AM
Public Function LShift16(w As Integer, c As Integer) As Integer
    'Bitwise left shift for short integers.
    'Equal to C '<<' operator
    LShift16 = w * (2 ^ c)
End Function
Public Function RShift16(w As Integer, c As Integer) As Integer
    'Bitwise right shift for short integers.
    'Equal to C '>>' operator
    RShift16 = w \ (2 ^ c)
End Function


Usage example

Public Sub Foo()
Dim iVal as integer
    iVal = &HA0            '10100000
    iVal = RShift16(iVal, 4)
    Debug.Print iVal 'Now it's 00001010
End Sub

A word of caution: Right shifting minus one (-1) will always result in minus one. This is because the sign bit is not changed with bit-wise operations.

 

Tip Submitted By: Robert Stites


 
Categories: VB

August 15, 2003
@ 02:26 AM

This makes it easy to overwrite the text. You can do this easily by adding a couple of lines to the GotFocus event procedure:

Sub Text1_GotFocus ()
     Text1.SelStart = 0
     Text1.SelLength = 65535
End Sub

Notice that the length value for SelLength is 65535, the maximum length allowed in a Text Box. This forces Visual Basic to use the actual length of the text as the SelLength.

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.


 
Categories: VB

August 15, 2003
@ 02:24 AM

It first brakes the two numbers, the two numbers you want to add into hours, minutes and seconds. Then It adds them together (each part by its own), it makes sure that the result is two characters, because if you add 2 and 2 VB will consider it as 4 and not as 04. After that it makes sure that the seconds. and the hours are not more then 60 if they are it adds one to the hours or the minutes, depends on what it is, if it is seconds. then it adds one to the minutes if it is minutes it adds one to the hours. Then it puts the results in a time format (hh:mm:ss).

Code

Function MakeTotalTime(First, Second)
'Divides the two time format numbers into parts:
'Hours, Minutes And Seconds.
    Firsth = Left(First, 2)
    Firstm = Mid(First, 4, 2)
    Firsts = Right(First, 2)
    Secondh = Left(Second, 2)
    Secondm = Mid(Second, 4, 2)
    Seconds = Right(Second, 2)
'----------------------------
' Adds the numbers and makes sure that it will
' always be with two characters
    uth = Val(Firsth) + Val(Secondh)
    If Len(uth) = 1 Then uth = "0" & uth
    utm = Val(Firstm) + Val(Secondm)
    If Len(utm) = 1 Then utm = "0" & utm
    uts = Val(Firsts) + Val(Seconds)
    If Len(uts) = 1 Then uts = "0" & uts
'----------------------------
' If the Seconds are higher than 60 then add
' one to the Minutes and subtract from the seconds
' 60
    If uts > 59 Then
        Do
            uts = Val(uts) - 60
            If Len(uts) = 1 Then uts = "0" & uts
            utm = Val(utm) + 1
            If Len(utm) = 1 Then utm = "0" & utm
        Loop Until uts <= 59
    End If
'----------------------------
' If the Minutes are higher than 60 then add
' one to the Hours and subtract from the Minutes
' 60
    If utm > 59 Then
        Do
            utm = Val(utm) - 60
            If Len(utm) = 1 Then utm = "0" & utm
            uth = Val(uth) + 1
            If Len(uth) = 1 Then uth = "0" & uth
        Loop Until utm <= 59
    End If
'----------------------------
' Returns the Total Time
    newTotal = uth & ":" & utm & ":" & uts
    MakeTotalTime = newTotal
End Function

 

Tip Submitted By: Yatir Halevi


 
Categories: VB

The following code will add an "About" menu item.

Declare:

Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As String) As Long
Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const WM_SYSCOMMAND = &H112
Public Const MF_SEPARATOR = &H800&
Public Const MF_STRING = &H0&
Public Const GWL_WNDPROC = (-4)
Public Const IDM_ABOUT As Long = 1010
Public lProcOld As Long

Code:

In your module put:

Public Function SysMenuHandler(ByVal hWnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    If iMsg = WM_SYSCOMMAND Then
        If wParam = IDM_ABOUT Then
            MsgBox "Subclassing works"
            Exit Function
        End If
    End If
 
    'Important to call original message handler!
    'Your app may not be the only subclasser around...
    SysMenuHandler = CallWindowProc(lProcOld, hWnd, iMsg, wParam, lParam)
End Function

In your Form put:

Private Sub Form_Load()
Dim lSysMenu As Long
Dim lRet As Long
    lSysMenu = GetSystemMenu(hWnd, 0&)
    lRet = AppendMenu(lSysMenu, MF_SEPARATOR, 0&, vbNullString)
    lRet = AppendMenu(lSysMenu, MF_STRING, IDM_ABOUT, "About...")
    Me.Show
    lProcOld = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf SysMenuHandler)
End Sub
Private Sub Form_Unload(Cancel As Integer)
    'Set back control to original message handler, or you
    'will experience the mother of all crashes!
    SetWindowLong Me.hWnd, GWL_WNDPROC, lProcOld
End Sub

REMEMBER to not terminate your program with an End statement. You must unload it properly, like above.


 
Categories: VB

What each File type has, is some information in the 'HKEY_CLASSES_ROOT' Registry Root. This is where we will place our little file type. In this little document, we will call our file type *.hyp and the File Name will be Test_File_Hype (you can't have spaces).

Firstly you need to make an edit in the HKEY_CLASSES_ROOT under .hyp. So:

HKEY_CLASSES_ROOT\.hyp


In the [Default] part of the Key, you will need to place "Test_File_Hype". Then we need another edit and that is the Test_File_Hype under HKEY_CLASSES_ROOT. So:

HKEY_CLASSES_ROOT\Test_File_Hype


Under that we need another one:

HKEY_CLASSES_ROOT\Test_File_Hype\Shell


And another under that:

HKEY_CLASSES_ROOT\Test_File_Hype\Shell\Open


Under open goes Command. So:

HKEY_CLASSES_ROOT\Test_File_Hype\Shell\Open\Command


As the default value of the Command, place:

your application path.exe %1

(eg. C:\WINDOWS\HYP\HYP.EXE %1)

You must remember that you need to already expect the File to be opened that way in your application, checking the Command$() whenever your application is opened. That is important, otherwise your application will not open it.

You would probably like your file to carry your EXE's Icon as well. This is very simply done with the following Registry edit:

HKEY_CLASSES_ROOT\Test_File_Hype\DefaultIcon


As the Default Value place:

your application path.EXE,0

Pretty cool, huh?! The last part, the zero, means that the icon is the main icon as the program. You could place other numbers if your application contains multiple icons (For example an icon just for the file.).

 

Tip Submitted By: Semin Nurkic


 
Categories: VB

The problem is that the TreeView control does not support right click menus. There is no easy way to tell what mouse button was pushed to cause a NodeClick event.

The code below, when used in a TreeView MouseUp event, will capture the specific node that a right mouse button is clicked on, allowing you to popup a custom menu for that node.

Code:

Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim nod As Node
     If Button = vbRightButton Then
           Set nod = TreeView1.HitTest(x, y)
           On Error GoTo EmptyNode
           nod.Selected = True
           On Error GoTo 0
           '<<Customize menu here>>
           Me.PopupMenu mnuPopUp
EmptyNode:
           On Error GoTo 0
     End If
End Sub


 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.
Parts of this tip was submitted by: Scott D. Killen


 
Categories: VB

Where I work we designed our application (VB5 and C++) and used long file names for our DLL's and OCX's. For some unexplained reason we had trouble with the files after registering them in the Registration Database. We switched to the old 8.3 file names and the problem went away.

I could not find any official information about this in the Microsoft Knowledgebase. But if you notice, all OCX's and DLL's put out by Microsoft use 8.3 file names... go figure.

 

Tip Submitted By: David McCarter


 
Categories: VB

If App.PrevInstance Then
     AppActivate "MyApp Version 1.0"
     End
End If

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.


 
Categories: VB

In another article, Bradley S Murray detailed how to enter information into the Registration Database via a temporary file. While this method works, it does feel a little kludgy. I have written some demo code to show you how to add, query, amend and delete entries in the Registry via the API calls contained in SHELL.DLL

In the upcoming Windows 95, the Registry is used a lot more extensively than previously, with a good deal of the information that was once held in *.INI files now being stored in the Registry.

In addition, it is a good place to store information for your own programs, (within reason), as opposed to an *.ini file. There are certain rules for doing this, and as I understand it, they boil down to using either;

HKEY_LOCAL_MACHINE \ SOFTWARE \ CompanyName \ ProductName \ Version


or

HKEY_CURRENT_USER \ SOFTWARE \ CompanyName \ ProductName \ Version


Information in HKEY_LOCAL_MACHINE is specific to the local computer, whilst information about the configuration of the application is stored on a per-user basis under HKEY_CURRENT_USER.

Be aware that searching for the file REG.DAT will not work under Windows 95, as the file simply does not exist, so do not use this as a means of determining Registry availability.

For further reading on the Registration Database, I would suggest getting hold of Microsoft's Technical Note "Configuration Management and the Registry". This is an excellent help file, which tells you all you need to know about the Registry and is available at ftp://ftp.microsoft.com/developr/MSDN as REG.ZIP

 

Tip Submitted By: Stu Churchill

 


 
Categories: VB

Also, an apparent bug in the 16-bit Jet 2.5 database engine causes the DBEngine's CreateWorkspace method to fail unless the DefaultUser and DefaultPassword properties contain the values required by the secured database. And so, for your coding pleasure, I'm is pleased to present the following examples:

For 16-bit programs, you must first create an APPNAME.INI file (where APPNAME is the base name of your program's .EXE file) containing at least the following:

[Data] 
Database=D:\PATH\DBNAME.MDB 
[Options] 
SystemDB=D:\PATH\SYSTEM.MDA 

Then, to open the database, do this:

Dim sUserName As String 
Dim sPassword As String
Dim db As Database
Dim ws As Workspace
     sUserName = "Your Name Here" 
     sPassword = "Bite_Me" 
     ' Create secured workspace 
     With DBEngine
           .IniPath = "D:\PATH\APPNAME.INI" 
           .DefaultUser = sUserName 
           .DefaultPassword = sPassword 
     End With 
     ' Workspace name is arbitrary, 
     ' but must be unique 
     Set ws = DBEngine.CreateWorkspace("Name", sUserName, sPassword) 
     ' Open database via secured workspace 
     Set db = ws.OpenDatabase("D:\PATH\DBNAME.MDB"...)


32-bit programs do not require an .INI file, nor do they require you to set the DefaultUser and DefaultPassword properties. Simply set the DBEngine's SystemDB property to point to your system database:

Dim sUserName As String 
Dim sPassword As String
Dim db As Database
Dim ws As Workspace
     sUserName = "Your Name Here" 
     sPassword = "Bite_Me" 
     ' Create secured workspace 
     DBEngine.SystemDB = "D:\PATH\SYSTEM.MDW" 
     Set ws = DBEngine.CreateWorkspace("Name", sUserName, sPassword) 
     ' That's it! Open sesame... 
     Set db = ws.OpenDatabase("D:\PATH\DBNAME.MDB"...)


Note: These examples assume that you have properly secured the database using the Access Security Wizard. During that process, Access will create the SYSTEM.MDA or .MDW files mentioned above.

 

Tip Submitted By: Phil Weber


 
Categories: VB

Do you want to make your controls and forms have that 3D look without adding the overhead of a VBX? Well, it's easy to do with just Windows API calls. As a matter of fact, the VBX's you shell out money for are just "wrappers" to those same API calls. With the PAINT3D.BAS module that was written by George Walz, it's as easy as calling one function...


Sub Form_Paint ()
Call FormIn3D(Me, 1, False)
End Sub

The first parameter is the form, the second is the bevel width and the third is a setting if you are using the MessageBlaster VBX. You can find all the code in PAINT3D.BAS that comes with VB Tips & Tricks.

 

Tips Submitted By: David McCarter - Code Written By: George Walz


 
Categories: VB