 |
Determine the size of a structure
|
| Total Hit (700) |
Unlike previous Visual Basic versions, under VB.NET you can't use the Len function to calculate the length of a Structure or a class. However, it is easy to get this information with the SizeOf static method of the System.Runtime.InteropServices.Mashal class, as in:
....Read More |
Rating
 |
|
 |
Convert a decimal value to binary, octal, or hexadecimal
|
| Total Hit (793) |
The ToString method of the Convert class lets you easily and quickly convert a decimal value into a string representation of that number to binary, octal, or hexadecimal base:
«Code LangId=2»' convert to binary
Console.WriteLine(Convert.ToString(11, 2)) ' => 1011
' convert to octal
Console.W
....Read More |
Rating
 |
|
 |
Faster string comparison with the Is operator
|
| Total Hit (588) |
.NET strings are objects, so what you store in a String variable is actually a reference to a String object allocated in the managed heap. Even though the VB.NET compiler attempts to hide the object nature of strings as much as it can - for example, you don't need to declare a String object with a N
....Read More |
Rating
 |
|
 |
Create directory paths
|
| Total Hit (693) |
Visual Basic 6's MkDir command, as well as the DOS MD command, can create only one subdirectory and fail if any subdirectory on the specified path doesn't exist:
«Code LangId=2»
' This VB6 statement fails if C:\MyApp doesn't exist
MKDIR "c:\MyApp\MyDir"
«/Code»
Conversely, the Directory.Crea
....Read More |
Rating
 |
|
 |
Exception debugging in Visual Studio .NET
|
| Total Hit (531) |
The Visual Studio debugger offers complete control on what happens when an application throws an exception, or calls a .NET method that throws an exception. You set all the relevant options from inside the Exceptions dialog box, which you bring up with the Debug | Exceptions menu command. This dialo
....Read More |
Rating
 |
|
 |
Adding events dynamically in a Windows Form
|
| Total Hit (679) |
The new AddHandler statement makes it possible to attach event dynamically, that is without having to bind them via static code based on the Handles keyword. This keyword is also useful to have all the controls on a form share the same event procedure.
For example, say that you want to change th
....Read More |
Rating
 |
|
 |
The DataTable's Compute method
|
| Total Hit (644) |
The DataTable class has a method, Compute, that executes SQL-like functions on the rows locally stored in the DataTable. It supports functions such as COUNT, SUM, MIN, MAX, AVG and others. Here's an example to calculate the average salary for the employees stored in the tableEmployees DataTable:
....Read More |
Rating
 |
|
 |
Determine whether an API function is available
|
| Total Hit (847) |
In many cases you may want to call an API function, but you aren't sure whether the Windows version the application is running on supports that particular function.
The easiest way to test whether a function exists and can be called is to replicate through VB code what Windows itself would do whe
....Read More |
Rating
 |
|
|
|
 |
Bin - Convert from decimal to binary
|
| Total Hit (878) |
«Code LangId=2»' convert from decimal to binary
' if you pass the Digits argument, the result is truncated to that number of
' digits
'
' you should always specify Digits if passing negative values
Function Bin(ByVal value As Long, Optional ByVal digits As Short = -1) As String
' conver
....Read More |
Rating
 |
|
 |
FormatMemorySize - Format a value in bytes
|
| Total Hit (501) |
«Code LangId=2»
Enum FormatMemorySizeUnits
BestGuess
Bytes
Kilobytes
Megabytes
Gigabytes
End Enum
' convert a number of bytes into Kbytes, Megabytes, or Gigabytes
Function FormatMemorySize(ByVal value As Long, _
ByVal unit As FormatMemorySizeUnits, Optional B
....Read More |
Rating
 |
|
 |
FilterDuplicates - Delete duplicate items in an array
|
| Total Hit (530) |
«Code LangId=2»
' Filter out duplicate values in an array and compact
' the array by moving items to "fill the gaps".
' Returns the number of duplicate values
'
' The array is not REDIMed, but you can do it easily using
' the following code:
' a() is a string array
' dups = FilterDu
....Read More |
Rating
 |
|
 |
CopyDirectory - Copy a directory
|
| Total Hit (559) |
«Code LangId=2»
' Copies a source directory to the destination directory.
' The last parameter specifies whether the files already present in the
' destination directory will be overwritten
' - Note: requires Imports System.IO
' - Usage: CopyDirectory("C:\Misc", "D:\MiscBackup")
Sub CopyDire
....Read More |
Rating
 |
|
|
|
|
|
|
|
|
|
|
|
 |
Convert DataReader to DataTable
|
| Total Hit (600) |
There is no direct way to convert dataraeader to datatable in ADO.net so I wrote this function which is really handy.
Happy Prpgramming...
|
Rating
 |
|
|
|
 |
Calling .Net Classes from Visual Basic 6
|
| Total Hit (416) |
Despite all the power and features of Visual Studio.Net, lots of developers are sticking with good old Visual Basic 6 for at least some of their development projects. There's good reason for this. Tens of thousands of developers know VB6 from the inside out, and can create applications quickly and e
....Read More |
Rating
 |
|
 |
Writing Provider-Independent Data Access Code with ADO.NET 2.0
|
| Total Hit (329) |
When you need to write an application that allows users to select the database provider, the application code itself needs to be completely provider-independent. ADO.NET 2.0 helps you create and deliver database applications even when you don't know what database your clients are using.
....Read More |
Rating
 |
|
 |
Life Without Control Arrays in Visual Basic .NET
|
| Total Hit (251) |
Control arrays were the best way to manage the controls on your Visual Basic forms, but there are no control arrays in Visual Basic .NET. Deborah Kurata describes how to use new Visual Basic .NET features to obtain control array functionality without the need for a control array.
....Read More |
Rating
 |
|
 |
Sophisticated Drag-Drop Images
|
| Total Hit (650) |
The standard .NET Framework drag-drop functionality provides a cursor to indicate that a drag-drop function is in progress. This article demonstrates how to add an image of the object being dragged to the drag-drop control, in the same way that Explorer does using the ImageList APIs.
....Read More |
Rating
 |
|
 |
Associations
|
| Total Hit (519) |
Applications such as WinZip add new items to Explorer's File and context menus for all files and folders on the system. Although WinZip uses Shell Extensions to achieve this, it is much easier to do using verbs. This article demonstrates how to use the .NET Registry classes to add new shortcut verbs
....Read More |
Rating
 |
|
 |
Typed DataSets in .NET by Ramaprasad Upadhyaya.
|
| Total Hit (152) |
As all of we know, we can specify the data type when we create a DataColumn for a DataTable. This is to enforce the runtime type-safety for the column so that only data of specified data type can be stored in the column.
|
Rating
 |
|
 |
How Do I...Encrypt and Decrypt a file?
|
| Total Hit (834) |
The CryptoStream class in the System.Security.Cryptography namespace is used to easily define cryptographic transforms on any data stream. The constructor is defined as the following: CryptoStream (Stream argument, ICryptoTransform transform, CryptoStreamMode mode).
....Read More |
Rating
 |
|
 |
How Do I...Catch an Exception?
|
| Total Hit (344) |
This sample illustrates how to catch an exception. A try...catch...finally block is used in this sample. Any code that might throw an exception is placed inside of the try block. If an exception is thrown, the catch block is entered and the program can perform the appropriate operation to recover or
....Read More |
Rating
 |
|
|
|
 |
Data Binding in Visual Basic .NET
|
| Total Hit (346) |
You might wonder why I didn't bind directly to the untyped DataSet. Well, the typed DataSet provides features such as early binding of fields. This enables you to use .CustomerName as a member of the DataSet instead of referencing the Items collection with the value "CustomerName," making the proces
....Read More |
Rating
 |
|