|
Print a Picture to Fit a Page!
|
Total Hit (2872) |
Module
«Code LangId=1» Option Explicit
Public Sub PrintPictureToFitPage(Pic As Picture)
Dim PicRatio As Double
Dim printerWidth As Double
Dim printerHeight As Double
Dim printerRatio As Double
Dim printerPicWidth As Double
Dim printerPicHeight As Double
'
....Read More |
Rating
|
|
|
|
|
|
|
SplitWithQualifiers - An improved version of the Split function
|
Total Hit (2202) |
«Code LangId=1»' A variant of the Split function, that offers the following improvements
' You can pass text qualifier as the third argument and optionally specify
' to treat consecutive occurrences of delimiters as one
' For example, the following source text contains comma inside one of
....Read More |
Rating
|
|
|
|
FilterString - Remove invalid characters from a string
|
Total Hit (3136) |
«Code LangId=1»' Filter out all invalid characters in a string.
Function FilterString(text As String, ValidChars As String) As String
Dim i As Long, result As String
For i = 1 To Len(text)
If InStr(ValidChars, Mid$(text, i, 1)) Then
result = result & Mid$(text, i,
....Read More |
Rating
|
|
|
Setting authentication across different domains
|
Total Hit (1621) |
COM doesn't have a built in security mechanism, but relies on Windows authentication services (Security Service Providers). When you access a resource or invoke a method in a remote DCOM server (or MTS package / COM+ Application), security checks cannot be performed in the standard way if the client
....Read More |
Rating
|
|
|
Detect when the application gets or loses the input focus
|
Total Hit (3374) |
VB forms exposes the Activate and Deactivate events, which fire when the form gets and loses the focus because the user has clicked on another form of the same application. However, VB doesn't fire any event when the user clicks on a form that belongs to another Windows application. In some cases th
....Read More |
Rating
|
|
|
Always declare objects with full library name
|
Total Hit (2817) |
If your application uses objects from external components, either third-party or your own libraries, a good rule of thumb is to include the complete servername.classname string in the Dim statement, as in:
«Code LangId=1»
Dim word As Word.Application
«/Code»
This syntax ensures that if you th
....Read More |
Rating
|
|
|
Determine the number of visible items in a ListView control
|
Total Hit (4383) |
Microsoft "forgot" to provide the ListView control with the GetVisibleCount property, as it did, for example, with the TreeView control. However, getting this information is as easy as sending a message to the control:
«Code LangId=1»
Private Const LVM_FIRST = &H1000
Private Const LVM_GETCOUNT
....Read More |
Rating
|
|
|
Get full control on the text typed in a ListView's item
|
Total Hit (3419) |
The ListView control exposes the AfterLabelEdit event to let the programmer validate the text entered in a ListItem, but there is no way to trap keys as they are typed by the user. This prevents you from discarding unwanted characters while the user types them.
You can work around this problem by
....Read More |
Rating
|
|
|
Move focus with Up and Down keys
|
Total Hit (1780) |
In all standard controls, Up and Down arrow keys move the focus on the previous or next control in the TabIndex order, respectively. This contrasts with text boxes, where these keys move the caret on the adjacent character, which you can achieve in a more natural way using the Left and Right cursor
....Read More |
Rating
|
|
|
Optimized Paint procedures with subclassing
|
Total Hit (2494) |
The Paint event doesn't provide with information about which region of the form must be actually repainted, and therefore forces the programmer to repaint the entire client area, which in some cases can be a time-consuming operation.
You can determine the smallest rectangle that needs to be updat
....Read More |
Rating
|
|
|
Counting Bits
|
Total Hit (3194) |
It seems that the only way to count the number of 1's or 0's in a binary value is creating a loop that iterates on all the 16 or 32 bits of the number. There is, however, a faster algorithm:
«Code LangId=1»
Function BitCount (ByVal number As Long) As Integer
Dim bits As Integer, temp As Long
....Read More |
Rating
|
|
|
Extract all quoted strings with the RegExp object
|
Total Hit (3606) |
When parsing a text file that contains quoted strings - such as a VB source file - you might want to quickly locate and extract all the quoted strings. Thanks to regular expressions and the RegExp object in the Microsoft VBScript Regular Expression type library, this task is surprisingly easy:
«co
....Read More |
Rating
|
|
|
Process string characters using Byte arrays
|
Total Hit (2833) |
When you need to process each character in a string, you can assign the string to a byte array and iterate on its elements (remember: each Unicode character corresponds to two bytes). This approach is usually much faster because it saves a lot of Mid$ functions and, hence, a lot of temporary strings
....Read More |
Rating
|
|
|
How to load BMP file into memory and perform rotation on it ?
|
Total Hit (8714) |
Bitmap rotation is a graphic effect that Visual Basic does not natively offer. This article shows how to rotate a given image in 90-degree increments. It allows you to rotate any image 0, 90, 180 or 270 degrees. With a little work, the code can be modified to rotate to any angle, but that is beyond
....Read More |
Rating
|
|
|
|
How to use Named Pipes in a Visual Basic 32-bit Program ?
|
Total Hit (11435) |
Visual Basic can create applications that communicate to other processes by means of Named Pipes. The Named Pipe must be created on Windows 2000 or Windows NT; however, you can read from and write to that pipe from any 32-bit platform.
This article demonstrates Client/Server communication using a
....Read More |
Rating
|
|
|
How to retrive font name from font file.
|
Total Hit (2953) |
I tried so many places but never found any simple code which retrive font name. Because to set font for drawing/printing we have to set font name and ususally font name is different than file name.
|
Rating
|
|
|
|
|
Highlighting a Listview Report Column
|
Total Hit (1473) |
Just as the picture property was used in Creating a Ledger-Style Listview Report Background to simulate a ledger-style background for the listview, this code provides a means to highlight the data in a specific column in the control using the same technique.
To do this, the the default background c
....Read More |
Rating
|
|
|
Compact a Long Path Name to fit a given space
|
Total Hit (1827) |
Often there is not enough room to display all of a long path name. A neat way to format a path name in a given space is to show some of the beginning of the path and the filename itself, whilst missing out some of the central folders and replacing them with ellipses (..) This method is used in many
....Read More |
Rating
|
|
|
vbAccelerator IconMenu DLL
|
Total Hit (1751) |
There are various controls for drawing menus with icons in at this site (and some code for doing the same sort of thing elsewhere). But so far these objects and code have been quite difficult to implement. This happens because these objects provide support for creating arbitrary menus at runtime - s
....Read More |
Rating
|
|
|
|
Reading Data from Local or External Library Resources
|
Total Hit (2767) |
Often your application will have associated data, such as pictures, sounds, static data and so forth you need to ship with it. If you are localizing your application then you also need to be able to provide alternative text strings for menus, messages, labels on so forth. Resources are a great way t
....Read More |
Rating
|
|
|