|
Play an AVI movie
|
Total Hit (5239) |
If you want to play an AVI movie from VB you can use MCI functions. The main MCI function is mciSendString, that sends command strings to the system and execute them:
«Code LangId=1»
Declare Function mciSendString Lib "winmm" Alias "mciSendStringA" (ByVal _
lpstrCommand As String, ByVal lps
....Read More |
Rating
|
|
|
Play an AVI movie in a PictureBox control
|
Total Hit (5344) |
With MCI functions you can play an AVI movie into a PictureBox. All you need to do is open the file with a special procedure:
«Code LangId=1»
Declare Function mciSendString Lib "winmm" Alias "mciSendStringA" (ByVal _
lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uR
....Read More |
Rating
|
|
|
Record a WAV file
|
Total Hit (3740) |
You can use MCI functions if you want to record a WAV file. The main MCI function is mciSendString, that sends command strings to the system and execute them.
«Code LangId=1»
Declare Function mciSendString Lib "winmm" Alias "mciSendStringA" (ByVal _
lpstrCommand As String, ByVal lpstrReturn
....Read More |
Rating
|
|
|
Retrieve the length of a media file (WAV, AVI, MIDI)
|
Total Hit (5744) |
You can retrieve the length of a standard windows media file (WAV, AVI or MIDI) using simple MCI functions. First, you must open the file with:
«Code LangId=1»
Declare Function mciSendString Lib "winmm" Alias "mciSendStringA" (ByVal _
lpstrCommand As String, ByVal lpstrReturnString As Strin
....Read More |
Rating
|
|
|
Retrieve the size of an AVI movie
|
Total Hit (3958) |
To retrieve the original size of an AVI file that you've already opened with the mciSendString API function you can use this command
«Code LangId=1»
Dim RetString As String
RetString = Space$(256)
CommandString = "where AVIFile destination"
RetVal = mciSendString(CommandString, RetString, Len
....Read More |
Rating
|
|
|
Animated form icons
|
Total Hit (4019) |
You can add a professional touch to your apps by showing an animated icon when the main form is minimized. To achieve this effect, prepare an array of Image controls, each one containing the icons that make up the animation, then add a Timer control, with the Enabled property set to True and the Int
....Read More |
Rating
|
|
|
Build a simple browser for icons
|
Total Hit (3029) |
Winodws uses a special browser to show all icons contained in a file and offers the end user the possibility to choose an icon from it. You can add this functionallity to your applications through an undocumented API function, SHChangeIconDialog. Its Declare is:
«Code LangId=1»
Declare Function
....Read More |
Rating
|
|
|
Convert a color value to a gray scale
|
Total Hit (3319) |
When you have a 32-bit color value, you can convert it to a grey-scale - that is, you can determine how it would appear on a monochromatic display (more or less) using the following function:
«Code LangId=1»
Function GetGreyScale(ByVal lColor As Long)
lColor = 0.33 * (lColor Mod 256) + 0.59
....Read More |
Rating
|
|
|
Copy the contents of the screen or the active window
|
Total Hit (5508) |
The standard way to copy the contents of the screen or a window to a picture box requires you to use a lot of API functions, such as BitBlt. A simpler approach is possible, though: you just have to simulate the typing of the Print Screen key (or Alt+Print Screen if you want to copy the contents of t
....Read More |
Rating
|
|
|
Display an animated GIF using the WebBrowser control
|
Total Hit (4355) |
The standard PictureBox control doesn't support the Animated GIF graphic format. However, you can display these images by using a WebBrowser control:
«Code LangId=1»
WebBrowser1.Navigate "c:\Images\Animated.Gif"
«/Code»
The only problem of this technique is that the WebBrowser control also di
....Read More |
Rating
|
|
|
Extract Red,Green,Blue components of a color
|
Total Hit (3002) |
If you have a 32-bit color value in RGB format, you can extract its Red, Green and Blue components using the following routines:
«Code LangId=1»
Function GetRed(ByVal lColor As Long) As Long
GetRed = lColor Mod 256
End Function
Function GetGreen(ByVal lColor As Long) As Long
GetGre
....Read More |
Rating
|
|
|
Extract RGB components from a Long value
|
Total Hit (3078) |
You can extract RGB values out of a 32-bit color value by using the integer division and the MOD operators, but there is a much more effective way, based on the LSet. You can convert from a long to rgb bytes and vice versa with the following code:
«Code LangId=1»
Private Type RGBWrapper
Red
....Read More |
Rating
|
|
|
Close the DataReader before changing database
|
Total Hit (2754) |
The ChangeDatabase method of the ADO.NET Connection object requires an open connection to execute correctly. Even if the connection is open, you can still have an InvalidOperationException when invoking this method; this happens when you are reading data from the connection by means of a DataReader
....Read More |
Rating
|
|
|
Determine how many records the DataReader is about to return
|
Total Hit (2777) |
The DataReader is the ADO.NET counterpart of the forward-only, read-only recordset in classic ADO. For this reason you never know how many rows the DataReader is about to return. In most cases you don't need this information, because you tipically process each row as soon as it is being returned, an
....Read More |
Rating
|
|
|
Determine how many records the DataReader is about to return
|
Total Hit (3006) |
The DataReader is the ADO.NET counterpart of the forward-only, read-only recordset in classic ADO. For this reason you never know how many rows the DataReader is about to return. In most cases you don't need this information, because you tipically process each row as soon as it is being returned, an
....Read More |
Rating
|
|
|
Include schema information in a DataSet's DiffGram
|
Total Hit (2895) |
In the .NET Framework, the DataSet's WriteXml method when used to create a DiffGram does not provide the capability to include schema information along with the data. This is more of a design choice than an objective difficulty, though. When you return a DataSet object from a Web service method your
....Read More |
Rating
|
|
|
MDAC 2.6 is required for .NET applications
|
Total Hit (2776) |
All ADO.NET applications require MDAC 2.6 or later (MDAC 2.7 is recommended). MDAC 2.7 comes with Visual Studio .NET but no MDAC version is included in the Microsoft .NET Framework SDK and the .NET Framework redistributable package. If your .NET application attempts to open a connection without a va
....Read More |
Rating
|
|
|
Persist ADO.NET extended properties
|
Total Hit (3844) |
Many ADO.NET classes, including DataSet, DataTable, and DataColumn, use the ExtendedProperties property to enable users to add custom information. Think of the ExtendedProperties property as a kind of generic cargo variable similar to the Tag property of many ActiveX controls. You populate it with n
....Read More |
Rating
|
|
|
The DataTable's Compute method
|
Total Hit (3138) |
The DataTable class has a method, Compute, that executes SQL-like functions on the rows locally stored in the DataTable. It supports functions such as COUNT, SUM, MIN, MAX, AVG and others. Here's an example to calculate the average salary for the employees stored in the tableEmployees DataTable:
....Read More |
Rating
|
|
|
Determine whether the IDE is in design, break, or run mode
|
Total Hit (2257) |
The VBIDE object model doesn't offer any native property or method to determine whether the IDE is in design-time mode, run-time mode, or debug (break) mode. However, it's easy to deduct this information by looking at the Enabled property of the menu commands in the Run top-level menu:
«Code Lang
....Read More |
Rating
|
|
|
Determine the RecordCount of a forward-only Recordset
|
Total Hit (3172) |
When working with a forward-only, read-only Recordset - that is, the default ADO Recordset - the RecordCount property always returns -1. (This can also happen with other types of server-side cursors, depending on the specific OLEDB provider.) In general, you can determine how many records were retur
....Read More |
Rating
|
|
|
Saving and restoring all IDE settings
|
Total Hit (2349) |
At times you'd like to save all the current settings of the Visual Basic environment and restore them afterwards. For example, you may want to alternate between the MDI environment with the code editor using Courier New 12 and the SDI environment with Arial 14. Or you may want to dock a different se
....Read More |
Rating
|
|
|
Where on Earth is an Add-ins's Description
|
Total Hit (2215) |
Every now and then someone asks me "How can I modify the default description that is associated to an add-in I have written and that appears in the Add-In Manager? I tried to modify the Project's Description attribute, but it didn't work".
The answer is simple, even though this detail is not doc
....Read More |
Rating
|
|
|
Determine how many records the DataReader is about to return
|
Total Hit (2268) |
The DataReader is the ADO.NET counterpart of the forward-only, read-only recordset in classic ADO. For this reason you never know how many rows the DataReader is about to return. In most cases you don't need this information, because you tipically process each row as soon as it is being returned, an
....Read More |
Rating
|
|
|
A better beep
|
Total Hit (4037) |
If you aren't satisfied with the standard Beep command (who is?) you can use the Beep API function instead, that lets you control both the frequency (in Hertz) and the duration (in milliseconds) of the beep. Note that you need an aliased Declare to avoid a name conflict with the VB command:
«Code
....Read More |
Rating
|
|
|
Check whether a sound card exists
|
Total Hit (3411) |
If you are developing a game in VB or an application that plays sounds, you probably want to check that a sound card actually exists. There is an API function that does this, and returns the number of sound cards installed in the system. Therefore, a return value of zero means that no devices are pr
....Read More |
Rating
|
|
|
Determine the total playing time of an Audio CD
|
Total Hit (2696) |
The Microsoft Multimedia Control lets you easily determine the total playing time of an Audio CD: you only need to correctly initialize the control and then decipher the value returned by its Length property. Use the following code as a guideline for your routines:
«Code LangId=1»
Private Sub cm
....Read More |
Rating
|
|
|
Open and close the CD drive's door
|
Total Hit (3220) |
Here's a short code snippet that lets you programmatically open and close the CD door. Note that not all the CD drives support these functions:
«Code LangId=1»
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
(ByVal lpstrCommand As String, ByVal lpstrReturnStr
....Read More |
Rating
|
|
|
Play a CD Audio track
|
Total Hit (3656) |
If you want to play a track of an audio CD from VB you can use MCI functions. The main MCI function is mciSendString, that sends command strings to the system and execute them:
«Code LangId=1»
Declare Function mciSendString Lib "winmm" Alias "mciSendStringA" (ByVal _
lpstrCommand As String,
....Read More |
Rating
|
|
|
Play a MIDI file
|
Total Hit (4467) |
If you want to play a MIDI file from VB you have to use MCI functions. The main MCI function is mciSendString, that sends command strings to the system and execute them:
«Code LangId=1»
Declare Function mciSendString Lib "winmm" Alias "mciSendStringA" (ByVal _
lpstrCommand As String, ByVal
....Read More |
Rating
|
|