|
|
|
|
|
|
|
ArraySum - The sum of all the items in an array of any type
|
Total Hit (2417) |
«Code LangId=1»
' Return the sum of the values in an array of any type
' (for string arrays, it concatenates all its elements)
'
' FIRST and LAST indicate which portion of the array
' should be considered; they default to the first
' and last element, respectively
Function ArraySum(arr As
....Read More |
Rating
|
|
|
ReplicateString - Replicate a string a given number of times
|
Total Hit (2187) |
«Code LangId=1»' Replicate a string a given number of times
Function ReplicateString(Source As String, Times As Long) As String
Dim length As Long, index As Long
' Create the result buffer
length = Len(Source)
ReplicateString = Space$(length * Times)
' do the multiple co
....Read More |
Rating
|
|
|
InstrTblRev - The last occurrence of a char in a table
|
Total Hit (1822) |
«Code LangId=1»' If INCLUDE is True or is omitted, return the last occurrence of a character
' in a group
' or zero if SOURCE doesn't contain any character among those listed in TABLE.
' If INCLUDE is False, return the last occurrence of the character in SOURCE
' that does not appear in TABLE.
....Read More |
Rating
|
|
|
Display the "Shut down Windows" dialog
|
Total Hit (3266) |
To programmatically display the "Shut down Windows" standard dialog box you can use the SHShutDownDialog undocumented API function, whose declaration is:
«Code LangId=1»
Declare Function SHShutDownDialog Lib "shell32" Alias "#60" (ByVal lType As _
Long) As Long
Its only argument can be
....Read More |
Rating
|
|
|
Track changes in system time and display resolution
|
Total Hit (3429) |
Whenever the system time or the display resolution changes, Windows sends all the top-level windows (forms, in VB jargon) the WM_TIMECHANGE or WM_DISPLAYCHANGE message, respectively. Therefore, you can easily determine when these system-wide settings change by subclassing any form in your applicatio
....Read More |
Rating
|
|
|
Getting a pixel color
|
Total Hit (3852) |
The Point method returns the color value of a given pixel, but is rather slow because it has to convert its argument from twips (or whatever ScaleMode is currently active) to pixels, and also because its argument are treated as Single quantities, and must therefore converted. When you have to retrie
....Read More |
Rating
|
|
|
A better beep
|
Total Hit (3939) |
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
|
|
|
Quickly find which OptionButton is selected
|
Total Hit (1634) |
Often OptionButton controls are arranged in control arrays. To quickly find the index of the only selected OptionButton control you can use the following code:
«Code LangId=1»
' assumes that the control array contains three OptionButton controls
intSelected = Option(0).Value * 0 - Option(1).Va
....Read More |
Rating
|
|
|
Show a custom caret
|
Total Hit (2571) |
VB gives you no control on the size of the text caret. At times it can be necessary to change its size, however, for example when you want to signal that the TextBox is in overwrite mode. Here's a routine that does the trick:
«Code LangId=1»
Private Declare Function GetFocus Lib "user32" () As
....Read More |
Rating
|
|
|
Search a file in a directory tree using the Imagehlp DLL
|
Total Hit (3663) |
You can search a file in all the subdirectories of a given drive in VB using a recursive routine based on the Dir$ function, the FileSystemObject component, or the FindFirstFile/FindNextFile API functions. There is a fourth way you might want to try out, based on the SearchTreeForFile function embed
....Read More |
Rating
|
|
|
Quickly initialize Variant and String arrays
|
Total Hit (3390) |
Visual Basic doesn't provide any way to declare an array and initialize its elements at the same time. In most cases you end up with setting individual elements one by one, as in:
«Code LangId=1»
Dim strArray(0 To 3) As String
strArray(0) = "Spring"
strArray(1) = "Summer"
strArray(2) = "Fall"
....Read More |
Rating
|
|
|
Avoid append operations with the Replace function
|
Total Hit (2861) |
I find the Replace function very useful when I want to avoid too many append operations just to insert non-printable characters. For example, the following statement:
«Code LangId=1»
MsgBox "Disk not ready." & vbCr & vbCr & _
"Please check that the diskette is in the drive" & vbCr & _
....Read More |
Rating
|
|
|
How to start/stop and enum services using ADSI
|
Total Hit (4097) |
This article will show you sample code to use ADSI to manage services.
«b»Step-By-Step Example«/b»
- Create a new standard exe project
- Add reference to "Active Ds Type Library" (Project->Add Reference)
- Add windows common control 6.0 (Project->Controls)
- Add one listview, five command b
....Read More |
Rating
|
|
|
Appending One File to Another File
|
Total Hit (3863) |
The following example demonstrates opening and closing files, reading and writing files, and locking and unlocking files. The application appends one file to the end of another file. The application opens the file having the new data appended with permissions that allow only this application to writ
....Read More |
Rating
|
|
|
Create your own cursor at runtime
|
Total Hit (3246) |
Sometimes you might need to create your own cursor at runtime without using any image or resource. You can achive this functionality using CreateCursor API. Here is the basic guidelines for creating your own cursor.
When you call CreateCursor you have to pass Application handle, Cursor Width, Curso
....Read More |
Rating
|
|
|
Determining if a Floppy Drive is Ready
|
Total Hit (1183) |
Visual Basic provides a few ways to test for the readiness of a removable drive both with intrinsic methods and with the assistance of the API. Each method has its advantages.
Most developers are familiar with the first method around since VB1 - performing a simple Dir() against the drive, trappin
....Read More |
Rating
|
|
|
ListView Demo 2 - Populating the ListView
|
Total Hit (1590) |
This page details the code required to populate the listview control with files matching the selected file spec using the APIs FindFirstFile, FindNextFile and the WIN32_FIND_DATA type.
When the demo is completed, the final app will retrieve the users selection and populate the listview with selec
....Read More |
Rating
|
|
|
|
Moving, Clicking and Tracking the MousePointer in Code
|
Total Hit (2650) |
VB doesn't provide any way to determine where the mouse is regardless of which control its over. Neither does it allow you to move the cursor or emulate mouse clicks on objects. This tip provides a simple class which uses API functions to add this functionality.
....Read More |
Rating
|
|
|
How to Shutdown the System in Windows 9x and NT
|
Total Hit (2790) |
This tip demonstrates how to shutdown, logoff and/or reboot a system. Shutting down a Windows 9x system is very straightforward - just one API call to ExitWindowsEx is all that is required. However, under NT it is a little more tricky. By default, no application processes under Windows NT have the p
....Read More |
Rating
|
|
|
Colourisation
|
Total Hit (1556) |
Image colourisation is a widely-used technique in image processing which can be used to create sepia-toned effects as well as adjusting images so they can be used as watermarks and in the creation of layered background images. This article demonstrates how to use the Hue, Luminance and Saturation mo
....Read More |
Rating
|
|
|
Media Progress Bar Renderer
|
Total Hit (1785) |
Windows Media Player has a neat progress bar showing how its getting on whilst burning files to CD or other long operations. This article presents a reusable class which draws a progress bar in a similar presentation. The resulting bar can be drawn to anything that exposes an hDC, and therefore can
....Read More |
Rating
|
|
|
PopupMenu DLL - Create Unlimited Popup Menus
|
Total Hit (2314) |
The PopupMenu (cNewMenu.dll) ActiveX DLL is allows you to create completely new popup menus with icons for your application. Menus created using this control either can be used as normal Windows Context menus or can be attached to a vbAccelerator CoolMenu and ToolBar control to be used as a form men
....Read More |
Rating
|
|
|
How to use WinInet FTPCommand function from Visual Basic
|
Total Hit (3620) |
This article includes some background information on the Microsoft Win32 Internet Application Programming Interface (WinInet for short) and the File Transfer Protocol (FTP) and then moves into the use of FTPCommand function.
|
Rating
|
|