|
|
|
|
GetShortFileName - Convert a filename to 8.3 format
|
Total Hit (4352) |
«Code LangId=1»
Private Declare Function GetShortPathName Lib "kernel32" Alias _
"GetShortPathNameA" (ByVal lpszLongPath As String, _
ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
' Convert a long filename into the short 8.3 format
' if the file doesn't exist, retur
....Read More |
Rating
|
|
|
MakeFileName - Create a file name out of its parts
|
Total Hit (1888) |
«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
|
|
|
Log10 - Base-10 logarithm
|
Total Hit (1743) |
«Code LangId=1»
' Base 10 logarithm
Function Log10(number As Double) As Double
Log10 = Log(number) / 2.30258509299405
End Function
«/Code»
|
Rating
|
|
|
Listing all available SQL Server
|
Total Hit (2271) |
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 (4110) |
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
|
|
|
Return a Dos error code on exit
|
Total Hit (2251) |
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 (5944) |
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 (3874) |
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 (2939) |
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 (2096) |
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
|
|
|
Delete a folder and all its subfolders
|
Total Hit (3457) |
The RmDir command can delete a directory only if it doesn't contain files or sub-directories. If the directory you want to delete does contain other files or, worse, subdirectories it seems that you are forced to use a recursive routine that does the job.
A simpler solution is offered by the Dele
....Read More |
Rating
|
|
|
A simple expression evaluator
|
Total Hit (3476) |
While any Windows user could pop up the Calculator accessory to perform any type of math calculations, it would be great if you could offer him or her the capability to do simple math from within your application. This is a very simple expression evaluator function that does it:
This evaluator i
....Read More |
Rating
|
|
|
|
|
|
Check Access Rights to File/Directory on NTFS Volume
|
Total Hit (6900) |
Windows NT/2000/XP has API function AccessCheck, which in fact checks access rights to every operating system object, which supports access rights. This function is called implicitly by system every time user accesses such object. To call AccessCheck function explicitly it is necessary to carry out
....Read More |
Rating
|
|
|
|
Adding a VB Progress Bar to a VB StatusBar
|
Total Hit (1504) |
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
|
|
|
|
Restrict Mouse Movement to an Area of the Desktop
|
Total Hit (2053) |
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
|
|
|
A Fast Index-Based Collection
|
Total Hit (1747) |
VB provides a simple Collection for storing objects. However, this object is internally implemented as a hashed linked list, and as such provides good performance for access either by an item's key or through enumeration. If you want to access an object by its index, however, you need to enumerate t
....Read More |
Rating
|
|
|
Generating MouseLeave Events for a Window
|
Total Hit (2447) |
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
|
|
|
A window that's star-shaped, circular or tank-shaped
|
Total Hit (2649) |
Just for fun, its surprisingly easy now to create Windows or controls of any shape whatsoever under Visual Basic. This article demonstrates using SetWindowsRgn to create Windows with a variety of geometric shapes.
|
Rating
|
|
|
File Clipboard Enhancer
|
Total Hit (1870) |
Windows Explorer allows you to cut, copy and paste files. However, whilst it uses the clipboard to do this, the file information is not made generally accessible as a custom clipboard is used. Often it's useful to be able to paste a file name as text: for example, into a file name field in an applic
....Read More |
Rating
|
|
|
|
Sending Data using socket.
|
Total Hit (5304) |
In the previous article we learned the recv Winsock API function which is used to read incoming data from the Winsock buffer. Today we'll see how to write data to the Winsock buffer for sending that data to a remote host. That is, actually, the send Winsock API function is not to send data. It just
....Read More |
Rating
|
|