|
FormatSize - Format a size expressed in bytes
|
Total Hit (2478) |
«Code LangId=2»
' Returns a formatted string that shows the size in Bytes, KBytes or MBytes
' according to the size
' Usage:
' Dim ProperSizeString As String = FormatSize("132100842")
' -> returns "125.98 MB"
Function FormatSize(ByVal SizeInBytes As Double) As String
If SizeInBytes
....Read More |
Rating
|
|
|
Singleton Design Patten in VB.NET
|
Total Hit (2798) |
The Singleton pattern ensures that only one instance of a class is created. All objects that use an instance of that class use the same instance. This is the most common design pattern, and easy to implement, but very powerful when used properly.
|
Rating
|
|
|
Adding an image as an embedded resource, and loading it from code
|
Total Hit (3634) |
To add an image as an embedded resource in a Windows Forms application, add the image file to the project with Project | Add Existing Item. Then select the file in the Solution Explorer, go to the Properties Window, and set its Build Action property to Embedded Resource. At this point the file will
....Read More |
Rating
|
|
|
Multi-column menus
|
Total Hit (3568) |
The new Break and BarBreak properties of the MenuItem object let you create menus with multiple columns. All you have to do is set either property to True for the MenuItem object that must become the first item of a new menu column. The only difference between these two properties is that BarBreak d
....Read More |
Rating
|
|
|
|
Take advantage of COM+ object pooling
|
Total Hit (2661) |
VB6 objects can't be pooled under COM+, because they are apartment threaded. This restriction is void with VB.NET objects (and all .NET objects in general), because they are free-threaded. To make an object poolable you just need to decorate the class with the ObjectPooling attribute:
«Code LangI
....Read More |
Rating
|
|
|
|
IsValidEmail - Validate an email address
|
Total Hit (2628) |
«Code LangId=2»
Function IsValidEmail(ByVal Value As String, Optional ByVal MaxLength As _
Integer = 255, Optional ByVal IsRequired As Boolean = True) As Boolean
If Value Is Nothing OrElse Value.Length = 0 Then
' rule out the null string case
Return Not IsRequired
....Read More |
Rating
|
|
|
FolderHasFiles - Returns whether the specified folder has files
|
Total Hit (2681) |
«Code LangId=2»
' Returns a boolean indicating whether the specified folder has files
Function FolderHasFiles(ByVal folderPath As String) As Boolean
Return System.IO.Directory.GetFiles(folderPath).Length > 0
End Function
«/Code»
|
Rating
|
|
|
App.Path in VB.NET
|
Total Hit (3138) |
The APP Object no longer exists in VB.NET, so calling App.Path to get the location of your application does not work. Thankfully there are many other ways to do this in VB.NET, here are a few.
NOTE: Some of these will only work for forms and not DLL's without any UI. The first two that reference
....Read More |
Rating
|
|
|
Write a console utility to kill a process
|
Total Hit (2924) |
The System.Diagnostics.Process class exposes two methods that let you kill a process: CloseMainWindow should be used with processes that have a graphical interface, whereas the Kill method should be used for apps without a user interface (or those whose main window is disable and can't process the W
....Read More |
Rating
|
|
|
Set up event handlers through reflection
|
Total Hit (2523) |
Reflection makes it easy to invoke a method (or assign a field or a property) by its name. For example, suppose you have the following classes:
«Code LangId=2»
Class Person
Event PropertyChanged(ByVal propertyName As String, ByVal newValue As Object)
Dim m_Name As String
Property
....Read More |
Rating
|
|
|
A macro to protect a code section with a Try...Catch block
|
Total Hit (2985) |
When you're working with the Visual Studio .NET code editor, typing a Try keyword plus the Enter key automatically creates the End Try statement. The following simple macro does something more interesting: it lets you select a portion of code and protect it with a Try...Catch...Finally...End Try blo
....Read More |
Rating
|
|
|
|
|
|
Reducing string memory usage with the Intern method
|
Total Hit (2971) |
A .NET application can optimize string management by maintaining an internal pool of string values known as intern pool. If the value being assigned to a string variable coincides with one of the strings already in the intern pool, no additional memory is created and the variable receives the addres
....Read More |
Rating
|
|
|
|
Highlighting and Shadowing Image List Images
|
Total Hit (1979) |
For some reason, the System.Windows.Forms.ImageList does not provide a Draw method that allows an image to be drawn highlighted or selected, even though this is part of the basic functionality of the underlying ComCtl32 ImageList. This article provides a method of drawing selected and lightened imag
....Read More |
Rating
|
|
|
|
ADO.NET: Connection Pooling
|
Total Hit (570) |
This sample illustrates how to construct a pool of connections to a datasource. You will want to do this to deploy high-performance applications. In this example the pool is established in the connection string and managed automatically by the SqlConnection.
....Read More |
Rating
|
|
|
Controlling scrolling with the API
|
Total Hit (2545) |
In certain circumstances, we need to be able to control the scroll bars from our code. This may seem like it should be easily done with standard methods when in fact they are buried in the API. I will tell you how I solved this problem in the application I am working on.
....Read More |
Rating
|
|
|
Validate What? Using Regular Expressions to Validate Input
|
Total Hit (1730) |
Validating user input is a basic but very necessary part of web development, especially when dealing with databases. Queries don't go too well when you have !@)#&#$*%?= in the search field. So we have to build a function that searches the input string for illegal characters (defined by you) and then
....Read More |
Rating
|
|
|
.NET Remoting - Part II
|
Total Hit (3510) |
Remoting provides a very flexible environment for distributed applications in the .NET arena. In part one of this series of four articles (note that this is an extension of the initially planned three as indicated in article I) I introduced the background to distributed applications and the .NET rem
....Read More |
Rating
|
|
|
How Do I...Read a text file?
|
Total Hit (1042) |
This sample retrieves information from a text file, and uses an ArrayList to display that information for the user.
Opening and reading files for read access is an important part of IO functionality, even if you do not need to write to the file in question. In this example, we open a file for read
....Read More |
Rating
|
|
|
How do I read/write objects into xml?
|
Total Hit (1037) |
This topic describes how to automatically map a particular XML stream into a set of objects designed to hold the XML using the XML Serialization classes.
|
Rating
|
|
|
|
Formatting with Regular Expressions
|
Total Hit (2846) |
If you're familiar with regular expressions, you know that they can be used for pattern matching and replacement in strings. (If you are not familiar with regular expressions, you're missing out on a powerful technology that has a myriad of applications. Read An Introduction to Regular Expressions t
....Read More |
Rating
|
|
|
Walkthrough: Loading SQL Server Data into a Word Table
|
Total Hit (994) |
Learn to programmatically load data into a Word table from a SQL Server database by taking advantage of ADO.NET to access data, and using Microsoft Visual Studio Tools for the Microsoft Office System to create your project.
|
Rating
|
|
|
How Do I...Read and write large files?
|
Total Hit (1386) |
This sample demonstrates how to write a large file and read it back in. This sample also shows how to time such operations. It accepts a file size (measured in kilobytes) from the user, indicating the size of the file to create. The larger the specified size, the longer the process will take to both
....Read More |
Rating
|
|