|
|
|
|
|
|
|
|
ShiftLeft - Shift a Long to the left
|
Total Hit (1549) |
«Code LangId=1»' Shift to the left of the specified number of times
'
' NOTE: requires Power2()
Function ShiftLeft(ByVal value As Long, ByVal times As Long) As Long
' we need to create a mask of 1's corresponding to the
' times in VALUE that will be retained in the result
Dim mas
....Read More |
Rating
|
|
|
ConvertCamelCase - Convert from a string in camel case
|
Total Hit (3375) |
«Code LangId=1»' change a sentence in CamelCase to a sentence with spaces
' for example ConvertCamelCase("FileExchange") => "File Exchange"
Public Function ConvertCamelCase(ByVal Value As String) As String
Dim i As Long
For i = 1 To Len(Trim$(Value))
' If the character is up
....Read More |
Rating
|
|
|
Never use New to create MTS/COM+ objects
|
Total Hit (1816) |
A common question among VB developers is: Why is it dangerous the use of the New keyword in VB to create COM objects registered under MTS/COM+?
The New keyword is the only way to go when you want to create objects that are defined as PublicNotCreatable or Private (CreateObject doesn't work) insid
....Read More |
Rating
|
|
|
Connect a stand-alone Recordset to a database using XML
|
Total Hit (3351) |
If you are familiar with the ADO capability to create stand-alone Recordsets from the thin air, that is by adding items to their Fields collection, you're also probably aware that this feature has a serious shortcoming: you can't then connect to a database and perform any batch updates. The problem
....Read More |
Rating
|
|
|
Determine whether the IDE is in design, break, or run mode
|
Total Hit (2194) |
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
|
|
|
Overwrite mode for textbox controls
|
Total Hit (2334) |
By default, textbox controls work in insert mode, where each new character never overwrites existing ones. If you wish to implement overwrite mode you can take advantage of the fact that characters pressed by the user replace the currently selected text, if any.
You need to declare a form-level
....Read More |
Rating
|
|
|
Hide and Show a control's scrollbars
|
Total Hit (3235) |
Most VB controls don't let you determine whether they should display a scrollbar or not. For example, a VB ListBox control displays a vertical scrollbar only when the number of its items is larger than the number of visible items. If you want to directly control individual scrollbars, you can use th
....Read More |
Rating
|
|
|
Quick comparison among UDTs
|
Total Hit (4149) |
When you need to compare two User Defined Type (UDT) variables to check whether they are equal, the only approach that you can follow in plain VB is to compare each individual element of the UDT. For example, say that you have the following Type declaration:
«Code LangId=1»
Private Type MyUDT
....Read More |
Rating
|
|
|
Use function name as a local variable
|
Total Hit (3231) |
Many programmers don't realize that it is perfectly legal to use the name of a function inside the Function itself, as if it were a local variable. This trick often lets you avoid the declaration of a temporary variable, and sometimes can speed up the code. Take for example the following code:
«
....Read More |
Rating
|
|
|
Mapping network share as a mapped drive using API
|
Total Hit (3790) |
«code LangId=1»Option Explicit
Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" ( _
ByVal lpszNetPath As String, _
ByVal lpszPassword As String, _
ByVal lpszLocalName As String) As Long
Private Sub MapDrive(share_name As String, Optional drive_
....Read More |
Rating
|
|
|
Move Form without title bar (2 different methods)
|
Total Hit (3889) |
You can move a form which has no titlebar by 2 different methods. First method will not show any drag border while second method will show drag borders.
«code LangId=1»'//////////////////////////////////////////////////////////
'// Move Form Without Title bar (Method-1: Without drag border)
'////
....Read More |
Rating
|
|
|
|
How to set default printer programatically on Win 9x/NT ?
|
Total Hit (4445) |
This article shows how to programmatically set which printer is the system default printer. Not all applications or components can select a specific printer to use. This often makes it necessary to change the default printer for the system so that the application or component will use the desired pr
....Read More |
Rating
|
|
|
|
|
Introduction to the Winsock API Test Bench sample application : Winsock API - Step by step tutorial for the Visual Basic developers
|
Total Hit (4099) |
The second part of the Winsock API tutorial is to introduce the following functions: accept, bind, closesocket, connect, getpeername, getsockname, getsockopt, listen, recv, select, send, setsockopt, socket. We'll learn these functions by creating the Winsock API Test Bench sample application.
....Read More |
Rating
|
|
|
Enumerating Windows Fonts by Type
|
Total Hit (886) |
This page shows the code required to add to a listbox only the specifictypes of fonts desired. Windows supports four font type - Vector (such as Modern), Raster (MS Sans Serif), Device-Specific (such as PostScript), and TrueType
|
Rating
|
|
|
|
Create an API hFont from a VB StdFont object
|
Total Hit (2300) |
If you are working with API based controls you will find that to set fonts you need a GDI hFont handle to the font. The StdFont object does not directly supply you with this handle. Although it is possible to cast the StdFont object as an IFont object, which does have a hFont handle property, you st
....Read More |
Rating
|
|
|
|
Saving Pictures to JPG Files Using GDI+
|
Total Hit (728) |
Although unfortunately Intel have discontinued support of their IJL library, Microsoft's GDI+ redistributable provides a way for VB coders to work with other file formats fully legitimately; and as a bonus you can also support PNG, TIF and GIF files too. This link redirects you to the new GDI+ file
....Read More |
Rating
|
|
|
Creating drop-down tool windows
|
Total Hit (1944) |
One feature I've been trying to achieve since I first discovered you could write API declares in VB3 (oops, showing my age here...) is a drop-down tool window you can show in response to a button or tool bar button click. These windows have been increasing in number in the Office series of tools and
....Read More |
Rating
|
|
|
WinZip UI Style Sample
|
Total Hit (1381) |
This sample demonstrates using the CommandBar controls to create a WinZip-style user interface. It shows how to set up an Image List to read images from a resource-only DLL and picking icons with the correct colour depth for the host system. It also demonstrates using a context menu to customise the
....Read More |
Rating
|
|