Category Archives: Microsoft

Run a Stored Procedure with ADO

Sometimes you have stored proc that takes 2,3 or 5 min to execute. Application that lock up frequently frustrates users and waste their time and resources. Solution use ADO ASYNCHROUS OPTION to get back CPU resorces. Public Sub ExecuteAsync()    Dim cmd As ADODB.Command        Set cmd = New ADODB.Command    cmd.ActiveConnection = “DSN=test”    cmd.CommandTimeout = 180    cmd.CommandText = “sp_name”    cmd.CommandType = adCmdStoredProc    cmd.EXECUTE , , adAsyncExecute ‘<—… Read More »

Internet Timer

Calculate the time that your internet connection is active. Module Private Declare Function RasEnumConnections Lib “rasapi32.dll” Alias “RasEnumConnectionsA” (lpRasConn As Any, lpcb As Long, lpcConnections As Long) As Long Public Const RAS_MAXENTRYNAME As Integer = 256Public Const RAS_MAXDEVICETYPE As Integer = 16Public Const RAS_MAXDEVICENAME As Integer = 128Public Const RAS_RASCONNSIZE As Integer = 412Public Const ERROR_SUCCESS = 0… Read More »

Using WinSock

This module will allow you to create a WinSock connection, as well as resolve computernames to IPs and vice-versa. Module Option Explicit Public Const SOCKET_ERROR = -1Public Const AF_INET = 2Public Const PF_INET = AF_INETPublic Const MAXGETHOSTSTRUCT = 1024Public Const SOCK_STREAM = 1Public Const MSG_PEEK = 2 Private Type SockAddr    sin_family As Integer    sin_port As Integer    sin_addr As String * 4    sin_zero… Read More »

Get Remote Time and Date

Say you to check the time and date of a remote computer, be it a server or workstation. Here is how you do it. Module Option Explicit ‘API StructuresType TIME_OF_DAY_INFO    tod_elapsed As Long    tod_msecs As Long    tod_hours As Long    tod_mins As Long    tod_secs As Long    tod_hunds As Long    tod_timezone As Long    tod_tinterval As Long    tod_day As Long    tod_month As Long    tod_year As Long    tod_weekday As LongEnd Type ‘NetAPI CallsPublic Declare… Read More »

Copy picture to Clipboard

Copy what you see in the Screen or in a Form into the clipboard. Module Option Explicit Private Const CCHDEVICENAME = 32Private Const CCHFORMNAME = 32Private Const SRCCOPY = &HCC0020 ‘ (DWORD) destination = source Private Type DEVMODE    dmDeviceName As String * CCHDEVICENAME    dmSpecVersion As Integer    dmDriverVersion As Integer    dmSize As Integer    dmDriverExtra As Integer    dmFields As Long    dmOrientation As Integer    dmPaperSize As Integer    dmPaperLength As Integer    dmPaperWidth… Read More »

Tunnel graphical effect

Create a Form and place this code inside. Sorry but the comments are in german. Code Option Explicit Dim offx%                 ‘ x-offset zur mitteDim offy%                 ‘ y-offset zur mitteDim anz%                 ‘ anzahl sterneDim bahnx%(100, 180)     ‘ x-tabDim bahny%(100, 180)     ‘ y-tabDim starwi%(500)            ‘ anz%Dim starba%(500)            ‘ anz%Dim cosi(360)             ‘ cos-tabDim sini(360)             ‘ sin-tabDim st%Dim wert                 ‘ rad in degDim x%                    … Read More »

Check and Change Resolution

With a little API magic, you can check the current screen resolution, and change it at runtime if needed. Module Option Explicit ‘Declares: Public Declare Function GetSystemMetrics Lib “user32.dll” (ByVal nIndex As Long) As LongPrivate Declare Function EnumDisplaySettings Lib “user32.dll” Alias “EnumDisplaySettingsA” (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As BooleanPublic Declare Function ChangeDisplaySettings… Read More »

Desktop Color Settings

Use this code to read or set the current desktop color settings. Module Option Explicit Private Declare Function GetSysColor Lib “user32.dll” (ByVal nindex As Long) As LongPrivate Declare Function SetSysColors Lib “user32.dll” (ByVal nChanges As Long, lpSysColor As Long, lpColorValues As Long) As Long Public Enum WindowsItem    COLOR_ACTIVEBORDER = 10    COLOR_ACTIVECAPTION = 2    COLOR_APPWORKSPACE = 12    COLOR_BACKGROUND = 1    COLOR_BTNFACE = 15    COLOR_BTNHIGHLIGHT =… Read More »

Print a Text File

Simple method to print a text file to the default printer. Module Option Explicit Public Sub PrintTXTFile(FileName As String)    Dim x As Integer    Dim s As String     x = FreeFile    On Error GoTo HandleError    Open FileName For Input As x    Do While Not EOF(x)        Line Input #x, s        Printer.Print s    Loop    Printer.EndDoc    Close #x    Exit SubHandleError:    MsgBox “Error :” & Err.Description, vbCritical, “Printing File…”End Sub Usage Create a Form with… Read More »

Play an AVI in a Picturebox

Just a little bit of code will allow you to play AVI files within your application. Great for media players, instructional apps, etc. Module Const WS_CHILD = &H40000000 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 Private Declare Function mciGetErrorString… Read More »