Open/Close CD-ROM Door

DeclarePrivate 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 LongSample CodeSub OpenCDDoor()  mciSendString "Set CDAudio Door Open Wait", 0&, 0&, 0&End SubSub CloseCDDoor()  mciSendString "Set CDAudio Door Closed Wait", 0&, 0&, 0&End Sub   Tip Submitted … Continue reading Open/Close CD-ROM Door

Make A Form Stay On Top (16 bit and 32 bit)

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 FormStayOnTopDeclare Sub SetWindowPos Lib "User" (ByVal hWnd As Integer, _ByVal hWndInsertAfter As Integer, ByVal X As Integer, _ByVal Y As … Continue reading Make A Form Stay On Top (16 bit and 32 bit)

Launching Programs Or Files From Your Application

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 … Continue reading Launching Programs Or Files From Your Application

Improved DoEvents For NT Users

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 … Continue reading Improved DoEvents For NT Users

Horizontal Scrollbars

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 … Continue reading Horizontal Scrollbars

Dialing A Phone

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  

Converting Bytes To Various Numeric Formats

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 … Continue reading Converting Bytes To Various Numeric Formats

Change A Form Background Color To The Desktop Color

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 = 0Global Const COLOR_BACKGROUND = 1Global Const COLOR_ACTIVECAPTION = 2Global Const COLOR_INACTIVECAPTION = 3Global Const COLOR_MENU = … Continue reading Change A Form Background Color To The Desktop Color

Bit Shifting

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 FunctionPublic Function RShift16(w As Integer, c As Integer) As Integer    'Bitwise right shift for short integers.    'Equal to C '>>' operator    RShift16 = w \ (2 ^ … Continue reading Bit Shifting

Automatic Selection Of Text

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 = 65535End Sub Notice that the length value for SelLength is 65535, the maximum length allowed in a Text Box. This forces Visual Basic … Continue reading Automatic Selection Of Text