July 24, 1998

Play WAV Sounds from Resource Files

Everyone loves a good sound bite. You can use the PlaySound() function in the Windows Multimedia DLL (WINMM.DLL) to play a wave (WAV) file that is stored as a resource. Although you can do this using the sndPlaySound function, sndPlaySound requires you to find, load, lock, unlock, and free the

Display Tooltips

You can easily duplicate the tooltips that appear when you float the mouse over a button in Microsoft’s products. This code displays the tooltip in the lower right-hand corner of the control (normally a button): ‘ xTip: string to display as the tip’ xCtrl: control you want the tip to

Random Values Without Duplicates

This code produces a “random” sequence of integers between specified Lower and Upper values without duplication. On the first call to the Shuffle routine with new values for Upper and Lower, Shuffle performs an efficient prime factorization, computes the constants for a linear sequence generator, and uses Randomize to generate

Change Display Settings on the Fly

When writing a game for Windows 95, set the display resolution to 640-by-480, set the color palette to True Color when it runs, and restore it to its initial mode when it ends. Use this function to implement it: ‘- DeclaresPrivate Declare Function lstrcpy _ Lib “kernel32” Alias “lstrcpyA” _

Comment Multiple Lines

VB provides only single-line comment functions: “REM” and “‘”. If you’re looking for another way to comment out a block of code, use conditional compilation in VB4 instead. Define “COMMENT = 0” in the Conditional Compilation Arguments field on the Advanced tab in the Options dialog of the Tools menu:

Write Less CPU-Bound Animations

When doing animation, such as scrolling a label or using picture boxes, I first used the method described by Eric Bernatchez (“Smoother Control Animation,” “101 Tech Tips for VB Developers,” Supplement to the February 1997 issue of VBPJ, page 21). However, I found that while in the Do Loop, the

Use Subscripts and Superscripts

You can use subscripts and superscripts in a RichTextBox control. To prevent the control from truncating text that is raised or lowered too far, reduce the characters’ size accordingly: Private Sub Form_Load() RichTextBox1.Font.Name = “Times New Roman” RichTextBox1.Font.Size = 10 RichTextBox1.Text = “H2SO4″‘ Move the numbers down 2 points. MakeSubscript

Export Data to ISAM Databases

Use this code to get data out to different formats without requiring a complete copy of the DBMS on the user machine. Create a new project with a command button, and copy this code into the button’s Click event: Dim db As DatabaseSet db = Workspaces(0).OpenDatabase _ (App.Path & “iblio.mdb”)’

Highlight Text Automatically

When the focus of a graphical user interface shifts to an empty TextField, you type the desired input and step to the next one. But if the TextField is not empty, the input cursor appears at the position it had when the Component previously lost the focus, and the characters

No more posts to show