|
|
|
|
|
MakeFileName - Create a file name out of its parts
|
Total Hit (1803) |
«Code LangId=1»
' Make a complete file name by assemblying its individual parts
' if Extension isn't omitted, it overwrites any extension held in BaseName
Function MakeFileName(Drive As String, Path As String, BaseName As String, _
Optional Extension As String)
' add a trailing col
....Read More |
Rating
|
|
|
CBitArray - a class for dealing with large arrays of Boolean
|
Total Hit (2299) |
«Code LangId=1»
' ------------------------------------------------------------------------
' The CBITARRAY class
'
' simiulates an array of Boolean values
' saves memory by packing one element in one bit
'
' IMPORTANT: you make make ITEM the default member for this class
' do
....Read More |
Rating
|
|
|
HasDuplicateValues - Check if an array has duplicate values
|
Total Hit (2499) |
«Code LangId=1»' Returns True if an array contains duplicate values
' it works with arrays of any type
Function HasDuplicateValues(arr As Variant) As Boolean
Dim col As Collection, index As Long
Set col = New Collection
' assume that the array contains duplicates
HasDu
....Read More |
Rating
|
|
|
Log10 - Base-10 logarithm
|
Total Hit (1645) |
«Code LangId=1»
' Base 10 logarithm
Function Log10(number As Double) As Double
Log10 = Log(number) / 2.30258509299405
End Function
«/Code»
|
Rating
|
|
|
NZ - Check whether a value is Null
|
Total Hit (1689) |
«Code LangId=1»' Check if a value is Null. If not it returns the value,
' otherwise it returns the ValIfNull argument, or zero/null string
' if the second argument is omitted
'
' This function is patterned after the Access function with the same name.
Public Function NZ(CheckVar As Varian
....Read More |
Rating
|
|
|
Listing all available SQL Server
|
Total Hit (2176) |
Thanks to the SQL-DMO object model, it's very easy to list all the available SQL Server 7.0 installations. For example, this code loads all the SQL Servers registered on the local machine into a ComboBox control:
«Code LangId=1»
' NOTE: this code assumes that you've added a reference to the
'
....Read More |
Rating
|
|
|
Launch the default browser on a given URL
|
Total Hit (3942) |
The following routine launches the default browser and loads the specified URL in it. The argument doesn't have to include the HTTP:// prefix. If the operation is successful it returns True.
«Code LangId=1»
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(B
....Read More |
Rating
|
|
|
Implement password-protected TextBox that are really secure
|
Total Hit (2906) |
As explained in another tip in this TipBank, users can peek at the contents of password-protected TextBox controls with a simple Spy-like program, or even with a VB program plus some API functions. The problem is that such TextBox controls react to the WM_GETTEXT message and the GetWindowText API fu
....Read More |
Rating
|
|
|
Return a Dos error code on exit
|
Total Hit (2164) |
At times you may want to return a Dos ErrorLevel when closing your VB application. This can be necessary, for example, if the EXE is meant to be called from a batch file. Exiting the program with an error code is really simple, and requires only a call to the ExitProcess API function:
«Code Lang
....Read More |
Rating
|
|
|
Saving a MSChart image to file
|
Total Hit (5797) |
To save to file the graph generated by a MSChart control, you must use the control’s EditCopy method to copy the image into the clipboard, and then paste it into a PictureBox control. Then, just use the SavePicture function to save the PictureBox’s content to file. Here’s an example:
«Code LangId
....Read More |
Rating
|
|
|
Count number of words with the RegExp object
|
Total Hit (3772) |
A Visual Basic function that counts the number of words in a sentence or text file can become quickly very complex, and usually doesn't execute fast enough for most purposes. Thanks to the RegEx object that comes with the Microsoft VBScript Regular Expression type library, this task becomes trivial.
....Read More |
Rating
|
|
|
Download and save an HTML page with the Internet Transfer control
|
Total Hit (2799) |
You can easily download an HTML page by using the Internet Transfer Control (INet). Here's a reusable routine that uses this control to download the HTML page at the specified URL and optionally save it to a local file. In either case the routine returns the contents of the page as a string:
«Code
....Read More |
Rating
|
|
|
Show a custom popup menu for a TextBox without subclassing
|
Total Hit (2013) |
Elsewhere in the TipBank we show how you can display a custom popup menu on a TextBox control by subclassing the WM_CONTEXTMENU message that Windows sends the control when the user right-clicks on it. If you don't like to resort to subclassing for such an easy job, you can use the following tip, tak
....Read More |
Rating
|
|
|
How to Convert Long File Name to Short File Name...
|
Total Hit (2841) |
API Declarations
«Code LangId=1» ' API Declare
Private Declare Function GetShortPathName Lib "kernel32.dll" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
«/Code»
Module
«Code LangId=1» Public Function ShortName
....Read More |
Rating
|
|
|
|
|
|
Determines the file version number of an executable file
|
Total Hit (2764) |
API Declarations
Option Explicit
'Declarations:
Private Declare Function GetLocaleInfoA Lib "kernel32.dll" (ByVal lLCID As Long, ByVal lLCTYPE As Long, ByVal strLCData As String, ByVal lDataLen As Long) As Long
Private Declare Sub lstrcpyn Lib "kernel32.dll" (ByVal strDest As String, ByVa
....Read More |
Rating
|
|
|
|
Changing a VB Toolbar to a Rebar-Style Toolbar
|
Total Hit (906) |
Here's a quick routine to set a standard VB toolbar to a IE-style Rebar style control (aka 'coolbar') for IE4 Active Desktop users. The illustration shows the original and flattened style for the same toolbar.
Place a toolbar with images (and optionally text), and add a placeholder. Set the place
....Read More |
Rating
|
|
|
|
Adding a VB Progress Bar to a VB StatusBar
|
Total Hit (1355) |
Normally, to calculate the position the progress bar should occupy in the status bar panel, one would calculate the panel position relative to the top left corner of the form, and adjust the coordinates appropriately. However, I found this can be circumvented by temporarily changing the status bar
....Read More |
Rating
|
|
|
Displaying Bitmaps as Icons in Windows' Explorer View
|
Total Hit (637) |
As the Visual Basic developer designs more and more apps that utilize tiny bitmaps for toolbars and other things, it quickly becomes apparent that keeping track of exactly what each bitmap looks like is a task in itself.
|
Rating
|
|
|
Restrict Mouse Movement to an Area of the Desktop
|
Total Hit (1968) |
This tip shows you how to ensure a cursor remains within a certain rectangle on the screen. Note that if the user uses Alt-Tab to switch to another application, the clipping cursor is cleared.
|
Rating
|
|
|
Generating MouseLeave Events for a Window
|
Total Hit (2367) |
Almost all of the more recent windows control support a feature known as "Hot-Tracking" - that is, when the control appears to highlight when the mouse moves over it, then returns to normal when the mouse leaves. Common examples include the flat toolbar buttons provided with the Windows Commmon cont
....Read More |
Rating
|
|
|
Multi-Threaded VB Using ActiveX EXEs
|
Total Hit (2578) |
Ever since VB5 service pack 2, there has been the possibility of running VB applications multi-threaded by using ActiveX EXEs. However, if you try and research this you will find it is fiddly to get working. This article presents a method which makes running operations asynchronously really easy.
....Read More |
Rating
|
|