Keep in touch

you can keep in touch with my all blogs and sites by install this Toolbar...
http://rworldtoolbar.ourtoolbar.com/

Showing posts with label vb.net 2005. Show all posts
Showing posts with label vb.net 2005. Show all posts

Monday, July 21, 2008

Get Total and Free Disk Space

Declarations:
Private Declare Function GetDiskFreeSpaceEx _
Lib "kernel32" _
Alias "GetDiskFreeSpaceExA" _
(ByVal lpDirectoryName As String, _
ByRef lpFreeBytesAvailableToCaller As Long, _
ByRef lpTotalNumberOfBytes As Long, _
ByRef lpTotalNumberOfFreeBytes As Long) As Long


Code:
Public Function GetFreeSpace(ByVal Drive As String) As Long
'returns free space in MB, formatted to two decimal places
'e.g., msgbox("Free Space on C: "& GetFreeSpace("C:\") & "MB")

Dim lBytesTotal, lFreeBytes, lFreeBytesAvailable As Long

Dim iAns As Long

iAns = GetDiskFreeSpaceEx(Drive, lFreeBytesAvailable, _
lBytesTotal, lFreeBytes)
If ians > 0 Then

Return BytesToMegabytes(lFreeBytes)
Else
Throw New Exception("Invalid or unreadable drive")
End If


End Function


Public Function GetTotalSpace(ByVal Drive As String) As String
'returns total space in MB, formatted to two decimal places
'e.g., msgbox("Free Space on C: "& GetTotalSpace("C:\") & "MB")

Dim lBytesTotal, lFreeBytes, lFreeBytesAvailable As Long

Dim iAns As Long

iAns = GetDiskFreeSpaceEx(Drive, lFreeBytesAvailable, _
lBytesTotal, lFreeBytes)
If iAns > 0 Then

Return BytesToMegabytes(lBytesTotal)
Else
Throw New Exception("Invalid or unreadable drive")
End If
End Function

Private Function BytesToMegabytes(ByVal Bytes As Long) _
As Long


Dim dblAns As Double
dblAns = (Bytes / 1024) / 1024
BytesToMegabytes = Format(dblAns, "###,###,##0.00")

End Function

Wednesday, July 16, 2008

Get the Current Screen Resolution (VB.NET)

Public Function ScreenResolution() As String
Dim intX As Integer = Screen.PrimaryScreen.Bounds.Width
Dim intY As Integer = Screen.PrimaryScreen.Bounds.Height
Return intX & " X " & intY
End Function

Tuesday, July 1, 2008

Check Existing Duplicate Process

Imports System.Threading
Module Module1
Sub Main()
Dim MatchingNames As System.Diagnostics.Process()
Dim TargetName As String

TargetName = System.Diagnostics.Process.GetCurrentProcess.ProcessName
MatchingNames = System.Diagnostics.Process.GetProcessesByName(TargetName)

If (MatchingNames.Length = 1) Then
Console.WriteLine("Started...")
Else
Console.WriteLine("Process already running")
End If
End Sub
End Module

Friday, June 27, 2008

URL validation in vb.net 2005

' URL validation
Public Function UrlIsValid(ByVal url As String) As Boolean
If url.ToLower().StartsWith("www.") Then url = "http://" & url
Dim webResponse As Net.HttpWebResponse = Nothing
Try
Dim webRequest As Net.HttpWebRequest = Net.HttpWebRequest.Create(url)
webResponse = DirectCast(webRequest.GetResponse(), Net.HttpWebResponse)
Return True
Catch
Return False
Finally
If webResponse IsNot Nothing Then webResponse.Close()
End Try
End Function

Email validation in vb.net 2005

' Email validation
Public Function EmailValid(ByVal email As String) As Boolean
' The regular expression rule
Dim Expression As New System.Text.RegularExpressions.Regex("\S+@\S+\.\S+")
' If the email matches the regular expression
If Expression.IsMatch(email) Then
' MessageBox.Show("The email address is valid.")
Return True
Else
' MessageBox.Show("The email address is NOT valid.")
Return False
End If
End Function

Numeric Validation in vb.net 2005

Public Function NumValid(ByVal key_char As String) As Int32
If (Microsoft.VisualBasic.Asc(key_char) <> 57) Then
'e.Handled = True
handel1 = True
End If
If (Microsoft.VisualBasic.Asc(key_char) = 8) Then
'e.Handled = False
handel1 = False
End If
If handel1 = True Then
Return 1
Else
Return 0
End If
End Function

Character Validation in vb.net 2005 without using control

' Text validator
Public Function CharValid(ByVal key_char As String) As Int32
If (Microsoft.VisualBasic.Asc(key_char) <> 90) _
And (Microsoft.VisualBasic.Asc(key_char) <> 122) Then
'Allowed space
If (Microsoft.VisualBasic.Asc(key_char) <> 32) Then
'e.Handled = True
handel1 = True
End If
End If
' Allowed backspace
If (Microsoft.VisualBasic.Asc(key_char) = 8) Then
'e.Handled = False
handel1 = False
End If
If handel1 = True Then
Return 1
Else
Return 0
End If
End Function