VB.NET SAMPLE CODING
How to empty a recycle bin - Introduction
Authorpeetah
Introduction
Usage:
Dim Action As New ShellActions
Action.EmptyRecycleBin()Public Class ShellActions
Shared Function _
SHEmptyRecycleBin(ByVal hWnd As Integer, ByVal pszRootPath As String, _
ByVal dwFlags As Integer) As Integer
End FunctionSub New()
EmptyRecycleBin()
End SubSub EmptyRecycleBin(Optional ByVal rootPath As String = "", _
Optional ByVal noConfirmation As Boolean = True, Optional ByVal NoProgress _
As Boolean = True, Optional ByVal NoSound As Boolean = True)Const SHERB_NOCONFIRMATION = &H1
Const SHERB_NOPROGRESSUI = &H2
Const SHERB_NOSOUND = &H4If rootPath.Length > 0 AndAlso rootPath.Substring(1, 2) <> ":\" Then
rootPath = rootPath.Substring(0, 1) & ":\"
End IfDim flags As Integer = (noConfirmation And SHERB_NOCONFIRMATION) Or _
(NoProgress And SHERB_NOPROGRESSUI) Or (NoSound And SHERB_NOSOUND)
SHEmptyRecycleBin(0, rootPath, flags)End Sub
VB Express Color Object to Hex String - Code
Authorckanoab
Code
This function takes a color object and returns the Hex value with a preceeding #.
Private Function ColorHex( ByVal color As Color) As String
Dim r As String = Hex(FColor.R), G As String = Hex(FColor.G), B As String = Hex(FColor.B)
If r.Length = 1 Then r = 0 & r : If G.Length = 1 Then G = 0 & G : If B.Length = 1 Then B = 0 & B
ColorHex = "#" & r & G & B
End Function
GDI+ Image Encoder and Decoder Info - Encoders and Decoders
AuthorNimpo
Encoders and Decoders
This piece of code enumerates every built in Encoder and Decoder that comes with GDI+. You would use the same concept to gain informartion about any other Encoder/Decoder.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ImageDecoders() As Imaging.ImageCodecInfo = Imaging.ImageCodecInfo.GetImageDecoders
Dim ImageEncoders() As Imaging.ImageCodecInfo = Imaging.ImageCodecInfo.GetImageEncoders
Dim strInfo As String
Dim i As IntegerstrInfo &= "Built-in GDI+ Image Decoders:" & ControlChars.NewLine & ControlChars.NewLine
For i = 0 To ImageDecoders.GetUpperBound(0)
With ImageDecoders(i)
strInfo &= "Codec Name: " & .CodecName & ControlChars.NewLine
strInfo &= "Dll Name: " & CType(IIf(.DllName <> String.Empty, .DllName, "N/A"), String) & _
ControlChars.NewLine
strInfo &= "File Extension(s): " & .FilenameExtension & ControlChars.NewLine
strInfo &= "Format Description: " & .FormatDescription & ControlChars.NewLine
strInfo &= "Mime Type: " & .MimeType & ControlChars.NewLine
strInfo &= "Version: " & .Version & ControlChars.NewLine & ControlChars.NewLine
End With
NextstrInfo = strInfo.Substring(0, strInfo.Length - 4)
txtDecoders.Text = strInfostrInfo = ""
strInfo &= "Built-in GDI+ Image Encoders:" & ControlChars.NewLine & ControlChars.NewLineFor i = 0 To ImageEncoders.GetUpperBound(0)
With ImageEncoders(i)
strInfo &= "Codec Name: " & .CodecName & ControlChars.NewLine
strInfo &= "Dll Name: " & CType(IIf(.DllName <> String.Empty, .DllName, "N/A"), String) & _
ControlChars.NewLine
strInfo &= "File Extension(s): " & .FilenameExtension & ControlChars.NewLine
strInfo &= "Format Description: " & .FormatDescription & ControlChars.NewLine
strInfo &= "Mime Type: " & .MimeType & ControlChars.NewLine
strInfo &= "Version: " & .Version & ControlChars.NewLine & ControlChars.NewLine
End With
NextstrInfo = strInfo.Substring(0, strInfo.Length - 4)
txtEncoders.Text = strInfo
End Sub
Date and Time Validate Funtion
Public
EnumOptFormat
DDMMYYYY = 1
DDMMMYYYY = 2
End
Enum
Public
Function
gfncIsDateValid(
ByVal
strDate
As
String
,
ByVal
strValidFormat
As
OptFormat,
Optional
ByVal
strDateOptional
As
Boolean
=
True
)
As
Boolean
'**********************************************************************************
'DESCRIPTION : This function is used to check if the Date passed is valid
' or not. It returns a Boolean Value. Two Type Format can be
' mentioned here. Format Type DDMMYYYY and Type DDMMMYYYY are
' available.
'INPUT PARAMETER : Date should be mentioned as string. Format should also be
' mentioned. True or False should also be passed. ' True should be mentioned
if Date can be empty. ' False should be mentioned if Date should not be empty.
'RETURN VALUE : Returns Boolean True or False [True- If Date is in Valid
' Format] [False- If the Date is in InValid Format]
'HOW TO USE [Ex] : gfncIsDateValid(TextBox1.Text, modGeneralFnc.OptFormat.DDMMMYYYY,)
'**********************************************************************************
Dim
strGetDate
As
String
Dim
strGetDay
As
String
, strGetMonth
As
String
, strGetYear
As
String
Dim
strDaysInMonth
As
String
strGetDate = Trim(strDate)
If
strGetDate ="" Then
If
strDateOptional =
True
Then
Return
True
Else
Return
False
End
If
End
If
Select
Case
strValidFormat
Case
OptFormat.DDMMYYYY
If
Not
Len(Trim(strGetDate)) = 10
Then
Return
False
End
If
If
InStr(strGetDate, pstrDateDelimiter, CompareMethod.Binary) = 0
Then
Return
False
End
If
If
((strGetDate.Substring(2, 1) <> pstrDateDelimiter)
Or
(strGetDate.Substring(5, 1) <> pstrDateDelimiter))
Then
Return
False
End
If
strGetDay = strGetDate.Substring(0, 2)strGetMonth = strGetDate.Substring(3,
2)strGetYear = strGetDate.Substring(6, 4)
If
Not
((IsNumeric(strGetDay))
And
(IsNumeric(strGetMonth))
And
(IsNumeric(strGetYear)))
Then
Return
False
End
If
If
((strGetDay < "0")
Or
(strGetMonth < "0")
Or
(strGetYear < "0"))
Then
Return
False
End
If
If
((strGetMonth = "01")
Or
(strGetMonth = "03")
Or
(strGetMonth = "05")
Or
(strGetMonth = "07")
Or
(strGetMonth = "08")
Or
(strGetMonth = "10")
Or
(strGetMonth = "12"))
Then
strDaysInMonth = "31" ElseIf
((strGetMonth = "04")
Or
(strGetMonth = "06")
Or
(strGetMonth = "09")
Or
(strGetMonth = "11"))
Then
strDaysInMonth = "30" ElseIf
(strGetMonth = "02")
Then
If
(
CInt
(strGetYear)
Mod
4) = 0
Then
''Leap year
strDaysInMonth = "29" Else
strDaysInMonth = "28" End
If
Else
Return
False
End
If
If
(strGetDay > strDaysInMonth)
Then
Return
False
Else
Return
True
End
If
Case
OptFormat.DDMMMYYYY
If
Not
Len(Trim(strGetDate)) = 11
Then
Return
False
End
If
If
InStr(strGetDate, pstrDateDelimiter, CompareMethod.Binary) = 0
Then
Return
False
End
If
If
((strGetDate.Substring(2, 1) <> pstrDateDelimiter)
Or
(strGetDate.Substring(6, 1) <> pstrDateDelimiter))
Then
Return
False
End
If
strGetDay = strGetDate.Substring(0, 2)strGetMonth = strGetDate.Substring(3,
3).ToUpper()strGetYear = strGetDate.Substring(7, 4)
If
Not
((IsNumeric(strGetDay))
And
(IsNumeric(strGetYear)))
Then
Return
False
End
If
If
((strGetDay < "0")
Or
(strGetYear < "0"))
Then
Return
False
End
If
If
((strGetMonth = "JAN")
Or
(strGetMonth = "MAR")
Or
(strGetMonth = "MAY")
Or
(strGetMonth = "JUL")
Or
(strGetMonth = "AUG")
Or
(strGetMonth = "OCT")
Or
(strGetMonth = "DEC"))
Then
strDaysInMonth = "31" ElseIf
((strGetMonth = "APR")
Or
(strGetMonth = "JUN")
Or
(strGetMonth = "SEP")
Or
(strGetMonth = "NOV"))
Then
strDaysInMonth = "30" ElseIf
(strGetMonth = "FEB")
Then
If
(
CInt
(strGetYear)
Mod
4) = 0
Then
''Leap year
strDaysInMonth = "29" Else
strDaysInMonth = "28" End
If
Else
Return
False
End
If
If
(strGetDay > strDaysInMonth)
Then
Return
False
Else
Return
True
End
If
End
Select
End
Function
Public
Function
gfncFormatedDate(
ByVal
strDate
As
String
,
ByVal
strValidFormat
As
OptFormat,
Optional
ByVal
strDateOptional
As
Boolean
=
True
)
As
String
'**********************************************************************************
'DESCRIPTION : This function is used to check if the Date passed is valid
' or not. It returns a Boolean Value. Two Type Format can be ' mentioned here.
Format Type DDMMYYYY and Type DDMMMYYYY are ' available.
'INPUT PARAMETER : Date should be mentioned as string. Format should also
be ' mentioned. True or False should also be passed.
' True should be mentioned if Date can be empty.
' False should be mentioned if Date should not be empty.
'RETURN VALUE : Returns String
'HOW TO USE [Ex] : gfncIsDateValid(TextBox1.Text, modGeneralFnc.OptFormat.DDMMMYYYY)
'**********************************************************************************
Dim strGetDate
As
String
Dim
strGetDay
As
String
, strGetMonth
As
String
, strGetYear
As
String
Dim
strDaysInMonth
As
String
strGetDate = Trim(strDate)
Select
Case
strValidFormat
Case
OptFormat.DDMMYYYYstrGetDay = strGetDate.Substring(0, 2)strGetMonth
= strGetDate.Substring(3, 2)strGetYear = strGetDate.Substring(6, 4)
Return
strGetDay & "/" & gfncGetMonth(strGetMonth) & "/" & strGetYear
Case
OptFormat.DDMMMYYYYstrGetDay = strGetDate.Substring(0, 2)strGetMonth
= strGetDate.Substring(3, 3).ToUpper()strGetYear = strGetDate.Substring(7,
4)
Return
strGetDay & "/" & strGetMonth & "/" & strGetYear
End
Select
End
Function
Private
Function
gfncGetMonth(
ByVal
strMonth
As
String
)
As
String
Select
Case
strMonth
Case"01"
Return"Jan"
Case"02"
Return"Feb"
Case"03"
Return"Mar"
Case"04"
Return"Apr"
Case"05"
Return"May"
Case"06"
Return"Jun"
Case"07"
Return"Jul"
Case"08"
Return"Aug"
Case"09"
Return"Sep"
Case"10"
Return"Oct"
Case"11"
Return"Nov"
Case"12"
Return"Dev"
End
Select
End
Function
Public
Function
gfncIsTimeValid(
ByVal
strTime
As
String
,
Optional
ByVal
strTimeOptional
As
Boolean
=
True
)
As
Boolean
'**********************************************************************************
'DESCRIPTION : This function is used to check if the time passed is a valid
' time or not. It returns a Boolean Value. 'INPUT PARAMETER : Time is passed
and True or False should be passed as 2nd param. ' True should be mentioned
if time can be empty. ' False should be mentioned if time should not be
empty. 'RETURN VALUE : Returns Boolean True or False [True- If Time is
in Valid ' Format] [False- If the Time is in InValid Format]
'HOW TO USE [Ex] : gfncIsTimeValid(Variable)
'**********************************************************************************
Dim strHour
As
String
Dim
strMinute
As
String
strTime = Replace(Trim(strTime), " ", "")
If
strTime ="" Then
If
strTimeOptional =
True
Then
Return
True
Else
Return
False
End
If
End
If
If
(Len(strTime) <> 5)
Then
Return
False
End
If
If
(strTime.Substring(2, 1) <> pstrTimeDelimiter)
Then
Return
False
End
If
strHour = strTime.Substring(0, 2)strMinute = strTime.Substring(3,
2)
If
Not
((IsNumeric(strHour))
And
(IsNumeric(strMinute)))
Then
Return
False
End
If
If
((strHour < "0")
Or
(strMinute < "0"))
Then
Return
False
End
If
If
((strHour < "0")
Or
(strHour < "23"))
Then
Return
False
End
If
If
((strMinute < "0")
Or
(strMinute > "59"))
Then
Return
False
End
If
Return
True
End
Function