Monday, October 6, 2008

Syntax for a class

Class Statement [ Public | Private | Protected |
Friend | Protected Friend ]
[ Shadows ][ MustInherit | NotInheritable ] _
Class name [ Inherits classname ][ Implements interfacenames ]
[ statements ]
End Class

Modifiers Brief explanation

Public
There are no restrictions on the use of a class declared as Public.

Private
A Private class is accessible only within its "declaration context" including any nested entities. A nested procedure is an example of a nested entity. A Public variable in a Private class is accessible from inside the class, but not from outside that class.

Protected
Protected means that elements are accessible only from within their own class or from a derived class. Protected can also be used with the Friend keyword. When they're used together, elements are accessible from the same assembly, from their own class, and from any derived classes.

Protected, Friend and Protected Friend

[These Definitions may not be exact definitions but can give a brief
idea]
Protected --> Accessible ONLY by 1.Derived classes 2.Within
the same class
Or
1. Code within the class
2. Code in derived classes within the same assemblies
3. Code in derived classes in other assemblies

A Protected procedure may only be declared within a class.
Procedures declared within the same class can call it, as
can other methods in inherited classes.[From MSDN]

methods in inherited classes.
Protected variables can be used within the class as well as
the classes that inherites this class.

Friend --> Accessible ONLY by 1.Derived classes 2.Classes
in the same assembly 3.Within the same class
Or
1. Code within the class
2. Code in derived classes within the same assembly
3. Other code in the same assembly

Friends can be accessed by all classes within assembely but
not from outside the assembely.

A variable declared with the Friend access specifier can only
be seen by other classes within the same program. This means
that if a class has a Friend variable and that class resides
in a DLL, then only other classes within the same DLL can see
that Friend variable. Any other program that uses that DLL
cannot see that variable.[From MSDN]


Protected Friend --> Accessible ONLY by 1.Derived classes
2.Classes in the same assembly 3.Within the same class
Or
1. Code within the class
2. Code in derived classes within the same assembly
3. Other code in the same assembly
4. Code in derived classes in other assemblies

The Protected Friend can be accessed by Members of the
Assembely (Friend) or the inheriting Assembely class
(Protected).

Friday, September 26, 2008

Move/Rename File

 Dim fi As New FileInfo("myOldName.txt")
fi.MoveTo("myNewName.txt")

Calculate File Size

Imports System.IO

Private Function GetFileSize(ByVal MyFilePath As String) As Long
Dim MyFile As New FileInfo(MyFilePath)
Dim FileSize As Long = MyFile.Length
Return FileSize
End Function

DateTime Formats

d - Numeric day of the month without a leading zero.
dd - Numeric day of the month with a leading zero.
ddd - Abbreviated name of the day of the week.
dddd - Full name of the day of the week.

f,ff,fff,ffff,fffff,ffffff,fffffff - Fraction of a second. The more F's the higher the presision.

h - 12 Hour clock, no leading zero.
hh - 12 Hour clock with leading zero.
H - 24 Hour clock, no leading zero.
HH - 24 Hour clock with leading zero.

m - Minutes with no leading zero.
mm - Minutes with leading zero.

M - Numeric month with no leading zero.
MM - Numeric month with a leading zero.
MMM - Abbreviated name of month.
MMMM - Full month name.

s - Seconds with no leading zero.
ss - Seconds with leading zero.

t - AM/PM but only the first letter.
tt - AM/PM

y - Year with out century and leading zero.
yy - Year with out century, with leading zero.
yyyy - Year with century.

zz - Time zone off set with +/-.

String to DateTime conversion and Vice Versa

'String to DateTime

VB.Net
Dim dateString As String
dateString = "1999-09-01 21:34 PM"
Dim datetimeStamp As New DateTime
datetimeStamp = DateTime.ParseExact(dateString, "yyyy-MM-dd HH:mm tt", Nothing)

C#
//
String to DateTime
String
MyString;
MyString = "1999-09-01 21:34 PM";
DateTime MyDateTime;
MyDateTime = new DateTime();
MyDateTime = DateTime.ParseExact(MyString, "yyyy-MM-dd HH:mm tt", null);

VB.Net
'DateTime to String
datetimeStamp = New DateTime(1999, 9, 1, 21, 34, 0)
dateString = datetimeStamp.ToString("yyyy-MM-dd HH:mm tt")

C#
//
DateTime to String
MyDateTime = new DateTime(1999, 09, 01, 21, 34, 00);
String
MyString;
MyString = MyDateTime.ToString("yyyy-MM-dd HH:mm tt");

Thursday, August 21, 2008

VB.Net Usefull Code Snippets

From: http://www.dreamincode.net/code/snippet870.htm

Change bitmaps certain color transparency


  1. 'Written by Margus Martsepp AKA m2s87
  2. Private Function v2bista(ByRef OnPict As System.Drawing.Bitmap, _
  3. ByVal xColor As System.Drawing.Color, _
  4. ByVal How_Tr As Integer) As Boolean
  5. Dim x%, y%, R%, G%, B%
  6. v2bista = True
  7. With OnPict
  8. For x = 1 To .Width - 1
  9. For y = 1 To .Height - 1
  10. R = .GetPixel(x, y).R
  11. G = .GetPixel(x, y).G
  12. B = .GetPixel(x, y).B
  13. If xColor.R = R And xColor.G = G And xColor.B = B Then
  14. .SetPixel(x, y, System.Drawing.Color.FromArgb(How_Tr, R, G, B))
  15. End If
  16. Next
  17. Next
  18. End With
  19. End Function