Let’s say you want to give your class a boolean property named Error that gets turned on or off if something goes awry in your code. You would think that you can’t do this because the word “Error” is reserved by .NET. However, there is a way. All you have to do is put Square Brackets around the word! For instance:
Public Property [Error]() As Boolean
Do it .! and Enjoying Coding with Reserved Keywords...
Happy Coding..!
Thursday, July 24, 2008
Visual Studio.NET: How To Comment/Uncomment Large Blocks of Code
Hello .Net Coders,
This One is for you,
To comment a large block of code (VS.NET), highlight the area you want to comment out and hold Ctrl and press K and then C.
To uncomment, highlight the commented area and hit Ctrl + K + U.
The mass uncommenting merely removes the forward-most apostrophe, so if you have actual comments in your commented code that were included in your initial highlighted region, they will remain comments upon uncommenting.
This tips is using at debugging time is most used by me.
Happy Coding..!
This One is for you,
To comment a large block of code (VS.NET), highlight the area you want to comment out and hold Ctrl and press K and then C.
To uncomment, highlight the commented area and hit Ctrl + K + U.
The mass uncommenting merely removes the forward-most apostrophe, so if you have actual comments in your commented code that were included in your initial highlighted region, they will remain comments upon uncommenting.
This tips is using at debugging time is most used by me.
Happy Coding..!
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
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
screen keyword - vb.net, Centering a form in VB.NET
Try this one :
frm.Top = (Screen.PrimaryScreen.WorkingArea.Height - frm.Height) / 2
frm.Left = (Screen.PrimaryScreen.WorkingArea.Width - frm.Width) / 2
frm.Top = (Screen.PrimaryScreen.WorkingArea.Height - frm.Height) / 2
frm.Left = (Screen.PrimaryScreen.WorkingArea.Width - frm.Width) / 2
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
Dim intX As Integer = Screen.PrimaryScreen.Bounds.Width
Dim intY As Integer = Screen.PrimaryScreen.Bounds.Height
Return intX & " X " & intY
End Function
Thursday, July 10, 2008
How to get CAPS LOCK IS ON (VB.NET)
When User Type a Password, How to give a message CAPS LOCK is On or not.
Private Sub txtPassword_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPassword.TextChanged
If My.Computer.Keyboard.CapsLock = True Then
'MsgBox("CAPS LOCK is ON", MsgBoxStyle.Information, "Password")
End If
End Sub
Private Sub txtPassword_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPassword.TextChanged
If My.Computer.Keyboard.CapsLock = True Then
'MsgBox("CAPS LOCK is ON", MsgBoxStyle.Information, "Password")
End If
End Sub
Change password(VB.NET)
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
If txtretype.Text = "" And txtold.Text = txtnew.Text Then
Try
cmd = New SqlCommand("insert into login values(@a, @B)", con)
cmd.Parameters.Add("@a", txtname.Text)
cmd.Parameters.Add("@b", txtretype.Text)
cmd.ExecuteNonQuery()
MessageBox.Show("USER CREATED SUCCESSFULLY", "REGISTRATION", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
If txtretype.Text = "" And txtold.Text = txtnew.Text Then
Try
cmd = New SqlCommand("insert into login values(@a, @B)", con)
cmd.Parameters.Add("@a", txtname.Text)
cmd.Parameters.Add("@b", txtretype.Text)
cmd.ExecuteNonQuery()
MessageBox.Show("USER CREATED SUCCESSFULLY", "REGISTRATION", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
Wednesday, July 2, 2008
Zoom Text Javascript
Another great javascript that zooms text onto the page which can be used as an intro message. The zoom text script is fully configurable and as it utilizes layers, can be used anywhere on the page. Simply change the co-ordinates in the div tag.
You can add as many messages as you like and change the colors to suit.
STEP 1
Copy the code below and paste this into the section of your html document. Add your messages and change font type, size and colors, etc, where the comments are indicated.
STEP 2
Copy the event handler code and paste this into the body tag of your html document.
onLoad="start()" onUnload="stop()"
STEP 3
Copy the code below and place this directly below the tag of your html document. Change the position of the zoom text effect by altering the" left" and "top" co-ordinates.
That;s it .!
Ref : http://www.hypergurl.com/zoomintro.html
You can add as many messages as you like and change the colors to suit.
STEP 1
Copy the code below and paste this into the section of your html document. Add your messages and change font type, size and colors, etc, where the comments are indicated.
STEP 2
Copy the event handler code and paste this into the body tag of your html document.
onLoad="start()" onUnload="stop()"
STEP 3
Copy the code below and place this directly below the tag of your html document. Change the position of the zoom text effect by altering the" left" and "top" co-ordinates.
That;s it .!
Ref : http://www.hypergurl.com/zoomintro.html
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
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
Subscribe to:
Posts (Atom)