|
|
|
|
|
|
|
ReplicateString - Replicate a string a given number of times
|
Total Hit (2237) |
«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
|
|
|
CheckUSState - Validate a US state initial
|
Total Hit (2725) |
«Code LangId=1»Public Function CheckUSState(ByVal State As String) As Boolean
If Len(State) = 2 And InStr(",AL,AK,AZ,AR,CA,CO,CT,DE,DC,FL,GA,HI,ID,IL,IN,I" _
& "A,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,P" _
& "A,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY,",
....Read More |
Rating
|
|
|
InstrTblRev - The last occurrence of a char in a table
|
Total Hit (1880) |
«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 (3350) |
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
|
|
|
Getting a pixel color
|
Total Hit (3958) |
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 (4047) |
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
|
|
|
Limit the length of the text in a TreeView node
|
Total Hit (4417) |
The TreeView control doesn't expose any property that lets you limit the amount of text users can type when editing a Node's label. However, you can do the trick with a couple of SendMessage API calls from within the BeforeLabelEdit event: with the TVM_GETEDITCONTROL message you retrieve the handle
....Read More |
Rating
|
|
|
Quickly find which OptionButton is selected
|
Total Hit (1690) |
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 (2646) |
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
|
|
|
Avoid append operations with the Replace function
|
Total Hit (2947) |
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
|
|
|
Use ActiveControl to stop a loop
|
Total Hit (3110) |
Often your user interface includes fields whose contents mutually depends on other fields. A typical example is when you deal with conversions from one measurement unit to another. Let's say that you want to let your users enter a temperature either in Celsius or Fahrenheit degrees, so you provide t
....Read More |
Rating
|
|
|
Working with Arc API (Arc, ArcTo, AngleArc)
|
Total Hit (5078) |
In this article we will explore 3 APIs (Arc, ArcTo and AngleArc).
An arc is a portion or segment of an ellipse, meaning an arc is a non-complete ellipse. Because an arc must confirm to the shape of an ellipse, it is defined as it fits in a rectangle and can be illustrated as follows:
«BR»«P Al
....Read More |
Rating
|
|
|
|
|
|
Connection strings for various OLEDB Data Providers
|
Total Hit (2734) |
OLE DB Providers for Active Directory Service, Advantage, AS/400 (from IBM), AS/400 and VSAM (from Microsoft), Commerce Server, DB2, DTS Packages, Exchange, Excel, Internet Publishing, Index Server, Microsoft Jet, Microsoft Project, MySQL, ODBC Databases, OLAP Services, Oracle (from Microsoft), Orac
....Read More |
Rating
|
|
|
How to Show SubItem Icons in the ListView
|
Total Hit (854) |
In perhaps the strangest (and most useless) of extended example, this code adds to each subitem the same icon displayed as the main item icon. I have yet to determine how (or if) a subitem-specific icon can be shown instead of duplicating the main item icon, or frankly, why one would ever want this
....Read More |
Rating
|
|
|
Determining if a Floppy Drive is Ready
|
Total Hit (1266) |
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 (1712) |
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 (2715) |
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 (2869) |
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
|
|
|
|
vbAccelerator CommandBar Control
|
Total Hit (2085) |
The vbAccelerator CommandBar control is a full toolbar/menu control which currently offers configurable styles, colours and a full-object model for configuring the buttons and menus. The control can draw in Office 2003, Office XP, MS Money and System styles, supports icons with alpha-channels and ru
....Read More |
Rating
|
|