The Function Junction

Welcome to the VBGumbo's Function Junction. Here will be listed some useful (at least the VBGumbo finds them useful) custom functions. If Any y'all have any functions you'd like to share please email the VBGumbo .

I will be adding and probably removing functions from this page on a regular basis. If you have questions or need a specific function let me know. I won't promise I'll get one for ya but if I can I will.


This first function I can't believe Microsoft left out. It's a File Exists function to determine if a file already exists in a given path. This is a real simple one.

Function FileExists (filename As String) As Integer  ' This function returns true or false 
    Dim i As Integer
    On Error Resume Next
    i = Len(Dir$(filename))
    If Err Or i = 0 Then
        FileExists = False
    Else
        FileExists = True
    End If
End Function


This Next function returns a string that contains the next available drive. This is useful when connecting network drives.

This Fuction uses the GetDriveType from the Kernal dll. The declaration for this function is as follows:

Declare Function GetDriveType% Lib "Kernel" (ByVal nDrive%)

Function NextFreeDrive () As String
Dim drivenum%
Dim nextdrive%
    For drivenum% = 3 To 25
       nextdrive% = GetDriveType(drivenum%)
       If nextdrive% = 0 Then
                nextfreedrive = Chr$(drivenum% + 65) + ":"
                Exit Function
       End If
    Next drivenum%
     MsgBox "No free drives are available. Increase Lastdrive statement or   disconnect network drive"
End Function



The last function being served today is one to determine if a program is running as an executable or is still in the VB environment. It requires two api declarations and one constant.

Declare Function GetModuleFileName Lib "Kernel" (ByVal hmodule As Integer, ByVal lpfilename As String, ByVal nsize As Integer) As Integer
Declare Function GetWindowWord Lib "User" (ByVal hWnd As Integer, ByVal nindex As Integer) As Integer
Const GWW_HINSTANCE = (-6)

The Code is as follows:
Function In_Ide ()
Dim ModName As String
Dim FileName As String
Dim hInst As Integer
Dim ret As Integer
ModName = String$(128, Chr$(0))
hInst = GetWindowWord(Me.hWnd, GWW_HINSTANCE)
ModName = Left$(ModName, GetModuleFileName(hInst, ModName, Len(ModName)))
If Len(ModName) > 0 Then
   FileName = Mid$(ModName, InStr(ModName, ".") - 3)
   If FileName = "\VB.EXE" Then
       In_Ide = True
   Else
       In_Ide = False
   End If
End If
End Function



Return to VBGumbo

1