|
AddBackslash - Append a backslash to a path if needed
|
Total Hit (4095) |
«Code LangId=2»
' Append a backslash (or any character) at the end of a path
' if it isn't there already
Function AddBackslash(ByVal Path As String, Optional ByVal ch As Char = "\"c) _
As String
If Not Path.EndsWith(ch) Then
AddBackslash = Path & ch
Else
AddBack
....Read More |
Rating
|
|
|
ChangeFileExtension - Modify the extension in a file name
|
Total Hit (2929) |
«Code LangId=2»
' Change the extension of a file name
' if the last argument is True, it adds the extension even if the file doesn't
' have one
Function ChangeFileExtension(ByVal FileName As String, _
ByVal Extension As String, Optional ByVal AddIfMissing As Boolean = False) _
As St
....Read More |
Rating
|
|
|
CompareFiles - Comparing two binary/text files
|
Total Hit (2746) |
«Code LangId=2»' Returns a boolean indicating whether two files are equal
' Example: Debug.WriteLine(CompareFiles("D:\File1.mdb", "D:\File2.mdb"))
Function CompareFiles(ByVal path1 As String, ByVal path2 As String) As Boolean
Dim file1 As New System.IO.FileInfo(path1)
Dim file2 As New
....Read More |
Rating
|
|
|
ConcatenateFiles - Concatenating multiple text files
|
Total Hit (2835) |
«Code LangId=2»
' Concatenate a variable number of text files into a single result file
'
' Params:
' - resultFile: the complete path of the result file you want to create
' - header: a string that is written when a file is added to the result file.
' Note: this string can contain the #Fi
....Read More |
Rating
|
|
|
CopyDirectory - Copy a directory
|
Total Hit (3044) |
«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
|
|
|
FolderHasFiles - Returns whether the specified folder has files
|
Total Hit (2690) |
«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
|
|
|
|
GetDirectorySize - Calculate the size of a directory
|
Total Hit (2782) |
«Code LangId=2»
' Returns the size of the specified directory
' - Note: requires Imports System.IO
' - Usage: Dim DirSize As Long = GetDirectorySize("D:\Projects")
Function GetDirectorySize(ByVal DirPath As String) As Long
Dim DirSize As Long
Dim Dir As DirectoryInfo = New DirectoryInfo(
....Read More |
Rating
|
|
|
|
IsDriveReady - Returns whether a drive is ready
|
Total Hit (3132) |
«Code LangId=2»
' Returns a boolean indicating whether a given drive is ready
' Example: check if the floppy disk drive is ready
' Debug.WriteLine(IsDriveReady("a"))
Function IsDriveReady(ByVal driveLetter As String) As Boolean
If driveLetter.Length = 1 Then driveLetter &= ":\"
Dim
....Read More |
Rating
|
|
|
IsExecutableFile - Returns whether the file is an executable
|
Total Hit (2681) |
«Code LangId=2»
' Returns a boolean indicating whether the file is an executable
Function IsExecutableFile(ByVal filePath As String) As Boolean
' add more extensions if you wish
Dim extensions() As String = New String() {".exe", ".bat", ".com", ".pif"}
' return true if the extension
....Read More |
Rating
|
|
|
IsImageFile - Returns whether the file is an image
|
Total Hit (3673) |
«Code LangId=2»
' Returns a boolean indicating whether the file is an image
Function IsImageFile(ByVal filePath As String) As Boolean
' add more extensions if you wish
Dim extensions() As String = New String() {".bmp", ".jpg", ".jpeg", ".gif", _
".tif", ".tiff", ".png", ".tga",
....Read More |
Rating
|
|
|
IsValidPath - Validating a system path
|
Total Hit (4596) |
«Code LangId=2»' Validate a system path
' Example:
' MessageBox.Show(IsValidPath("C:\Test\Memo.txt")) ' => True
' MessageBox.Show(IsValidPath("\\RemotePC\Test\Memo.txt")) ' => True
' MessageBox.Show(IsValidPath("C:\Test\Mem|o.txt")) ' => False
Function IsValidPath(ByVal p
....Read More |
Rating
|
|
|
LoadTextFile - Load the contents of a text file
|
Total Hit (2809) |
«Code LangId=2»
' Returns the content of the specified text file
' Note: it can throw an exception
' Usage: Dim FileContent As String = LoadTextFile("C:\Autoexec.bat")
Function LoadTextFile(ByVal FilePath As String) As String
Dim sr As System.IO.StreamReader
Try
sr = New
....Read More |
Rating
|
|
|
SaveTextFile - Save or append text to a file
|
Total Hit (3662) |
«Code LangId=2»
' Saves a text file. If the destination file already exists,
' its content can be replaced, or the new content can be appended
' at the end of the file, according to the last parameter
' Note: the destination directory must exist, otherwise the file is not
' saved and th
....Read More |
Rating
|
|
|
ArrayDeleteElement - Deleting an element in any type of array
|
Total Hit (2571) |
«Code LangId=2»' A generic routine that deletes an element in any type of array.
' Example: deleting the 2nd element of the array arr
' ArrayDeleteElement(arr, 1)
Sub ArrayDeleteElement(ByVal arr As Array, ByVal index As Integer)
' Shift elements from arr(index+1) to arr(index).
....Read More |
Rating
|
|
|
ArrayInsertElement - Inserting an element in any type of array
|
Total Hit (2620) |
«Code LangId=2»' A generic routine that inserts an element in any type of array.
' Example: inserting an entry of value 5 between the 1st and 2nd entry of the
' array arr
' ArrayInsertElement(arr, 1, 5)
Sub ArrayInsertElement(ByVal arr As Array, ByVal index As Integer, _
Optional By
....Read More |
Rating
|
|
|
ArrayListJoin - Merging two ArrayList objects
|
Total Hit (2875) |
«Code LangId=2»' A reusable function that merges two ArrayList objects
' Example:
' Dim al As New ArrayList()
' al.Add("Jack")
' al.Add("Mary")
' val.Add("Bob")
' al.Add("Tom")
'
' Dim al2 As New ArrayList()
' al2.Add("Frank")
' al2.Add("Lee")
' a
....Read More |
Rating
|
|
|
FilterDuplicates - Delete duplicate items in an array
|
Total Hit (3198) |
«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
|
|
|
|
StripControlChars - Delete control characters in a string
|
Total Hit (4283) |
«Code LangId=2»
' Strip all control characters (ASCII code < 32)
'
' If the second argument is True or omitted,
' CR-LF pairs are preserved
Function StripControlChars(ByVal source As String, Optional ByVal KeepCRLF As _
Boolean = True) As String
' we use this to build the result
....Read More |
Rating
|
|
|
Age - Evaluating the age of a person, given his/her birth date
|
Total Hit (2090) |
«Code LangId=2»' Evaluate the age of a person, given his/her birth date
' Example: Debug.WriteLine(Age(#9/28/1980#)) ' => 22
Function Age(ByVal birthDate As Date, Optional ByVal currentDate As Date = #1/1/ _
1900#, Optional ByVal exactAge As Boolean = True) As Integer
If currentDate
....Read More |
Rating
|
|
|
|
|
EasterDate - Evaluating the Easter date for a given year
|
Total Hit (2716) |
«Code LangId=2»' Evaluate the Easter date for a given year
' Example: MessageBox.Show(EasterDate(2003).ToLongDateString())
Function EasterDate(ByVal year As Integer) As DateTime
Dim g, c, h, i, j, l, month, day As Integer
g = year Mod 19
c = year \ 100
h = ((c - (c \ 4) -
....Read More |
Rating
|
|
|
|
BinarySearch - Fast search in a sorted array
|
Total Hit (3310) |
«Code LangId=2»
' Binary search in an array of any type
' Returns the index of the matching item, or -1 if the search fails
'
' The arrays *must* be sorted, in ascending or descending
' order (the routines finds out the sort direction).
' LASTEL is the index of the last item to be searched, a
....Read More |
Rating
|
|
|
|
|