Dragging a form by a control

This code is reusable and small enough to paste into whatever you’re doing and instantly have a form that has no need for a title bar. Original Author: VB Pro API Declarations In the general declarations section, insert these lines: Declare Sub ReleaseCapture Lib “User” ()Declare Function SendMessage _Lib “User” (ByVal hWnd As Integer, _ByVal wMsg As Integer, _ByVal… Read More »

Avoiding use of null

How do you avoid the “Invalid use of null” error when reading null values from a database?If you try to retrieve a null value (empty field) from a database, you will get the error: “Invalid use of Null”. Here is one way to get around this problem: .. Original Author: VB FAQ Code TextBox.Text = MyTest.Fields(“TestFld”) & “”

Launch file and associated program

How do I launch a file in its associated program?The Shell statement unfortunately only supports launching an EXE file directly. If you want to be able to launch, i.e. Microsoft Word by calling a .DOC file only, you can make your VB application launch the associated program with the document using the following method: Original Author: VB FAQ API… Read More »

Changing Windows Printer w/o using priint dialog

How can I change the printer Windows uses in code without using the print common dialog? How can I change orientation?You can change the printer the VB 3.0 Printer object is pointing to programmatically (without using the common dialogs). Just use the WriteProfileString API call and rewrite the [WINDOWS], DEVICE entry in the WIN.INI file! VB will instantly… Read More »

AppOnTop

How do I get my application on top?To make your window truly topmost, use the SetWindowPos API call Original Author: VB FAQ Assumptions You can, to make the application stay on top, put the ZOrder method in a Timer event repeatedly called, say, every 1000 milliseconds. This makes a “softer” on-top than other methods, and allows the user to… Read More »

StopTextBoxFromBeeping

Show how to make a text box not beep but do something else when I hit the Enter key. This code example makes nothing happen, for an extended period of time: Original Author: VB FAQ Code Sub Text1_KeyPress (KeyAscii As Integer) If KeyAscii = 13 Then ’13 is Key_ReturnKeyAscii = 0End If End Sub

cmdFormatDrive

Format Floppy Disk using API:Here is the code on How to Format Floppy Disk using API. Note — This code can format your Hard Disk as well, so you should be careful!!!! Original Author: Duncan Diep API Declarations Private Declare Function SHFormatDrive Lib “shell32” _(ByVal hwnd As Long, ByVal Drive As Long, ByVal fmtID As Long, _ByVal options As… Read More »

Validate_Drive

Validates whether a given hard/floppy/network drive is valid Original Author: Ian Ippolito (psc) Inputs strDrive–drive to validate Returns i the dirve exists returns TRUE, otherwise FALSE Code Function Validate_Drive (ByVal strDrive As String)   On Error GoTo BAD2    ‘Dim strOldDrive As String    ‘strOldDrive = Get_Drive_Name(CurDir$)    ChDrive (strDrive)    ‘ChDrive (strOldDrive)  On Error GoTo 0  Validate_Drive = TrueExit FunctionBAD2:  Validate_Drive = False  Resume Exit2Exit2:  Exit Function End Function

Dump_String_To_File

Dumps a string to a file Original Author: Ian Ippolito (psc) Inputs strString–string to dumpstrFile–file to dump to Code Sub Dump_String_To_File (ByVal strString As String, ByVal strFile As String)  Dim fileFile As Integer  fileFile = FreeFile  Open strFile For Output As fileFile    Write #fileFile, strString  Close fileFile  Dim intReturn  On Error Resume Next  intReturn = Shell(“c:appsutility extpad xtpad16.exe ” & strFile, 1)  On Error GoTo 0End Sub

Center_Form

To center all of your forms nicely on the screen, use this as the first line in the Form_Load event–resolution independent.‘note:call this function like this:Center_Form Me Original Author: Ian Ippolito (psc) Inputs frmForm–form to center. Call this function like this:Center_Form Me Code Sub Center_Form (frmForm As Form)frmForm.Left = (Screen.Width – frmForm.Width) / 2frmForm.Top = (Screen.Height – frmForm.Height) / 2End… Read More »