Thursday, June 6, 2013

DateTime.ToString() Patterns


All the patterns:
0
MM/dd/yyyy
08/22/2006
1
dddd, dd MMMM yyyy
Tuesday, 22 August 2006
2
dddd, dd MMMM yyyy
HH:mm Tuesday, 22 August 2006 06:30
3
dddd, dd MMMM yyyy
hh:mm tt Tuesday, 22 August 2006 06:30 AM
4
dddd, dd MMMM yyyy
H:mm Tuesday, 22 August 2006 6:30
5
dddd, dd MMMM yyyy
h:mm tt Tuesday, 22 August 2006 6:30 AM
6
dddd, dd MMMM yyyy HH:mm:ss
Tuesday, 22 August 2006 06:30:07
7
MM/dd/yyyy HH:mm
08/22/2006 06:30
8
MM/dd/yyyy hh:mm tt
08/22/2006 06:30 AM
9
MM/dd/yyyy H:mm
08/22/2006 6:30
10
MM/dd/yyyy h:mm tt
08/22/2006 6:30 AM
10
MM/dd/yyyy h:mm tt
08/22/2006 6:30 AM
10
MM/dd/yyyy h:mm tt
08/22/2006 6:30 AM
11
MM/dd/yyyy HH:mm:ss
08/22/2006 06:30:07
12
MMMM dd
August 22
13
MMMM dd
August 22
14
yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK
2006-08-22T06:30:07.7199222-04:00
15
yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK
2006-08-22T06:30:07.7199222-04:00
16
ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
Tue, 22 Aug 2006 06:30:07 GMT
17
ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
Tue, 22 Aug 2006 06:30:07 GMT
18
yyyy'-'MM'-'dd'T'HH':'mm':'ss
2006-08-22T06:30:07
19
HH:mm
06:30
20
hh:mm tt
06:30 AM
21
H:mm
6:30
22
h:mm tt
6:30 AM
23
HH:mm:ss
06:30:07
24
yyyy'-'MM'-'dd HH':'mm':'ss'Z'
2006-08-22 06:30:07Z
25
dddd, dd MMMM yyyy HH:mm:ss
Tuesday, 22 August 2006 06:30:07
26
yyyy MMMM
2006 August
27
yyyy MMMM
2006 August
The patterns for DateTime.ToString ( 'd' ) :
0
MM/dd/yyyy
08/22/2006
The patterns for DateTime.ToString ( 'D' ) :
0
dddd, dd MMMM yyyy
Tuesday, 22 August 2006
The patterns for DateTime.ToString ( 'f' ) :
0
dddd, dd MMMM yyyy HH:mm
Tuesday, 22 August 2006 06:30
1
dddd, dd MMMM yyyy hh:mm
tt Tuesday, 22 August 2006 06:30 AM
2
dddd, dd MMMM yyyy H:mm
Tuesday, 22 August 2006 6:30
3
dddd, dd MMMM yyyy h:mm
tt Tuesday, 22 August 2006 6:30 AM
The patterns for DateTime.ToString ( 'F' ) :
0
dddd, dd MMMM yyyy HH:mm:ss
Tuesday, 22 August 2006 06:30:07
The patterns for DateTime.ToString ( 'g' ) :
0
MM/dd/yyyy HH:mm
08/22/2006 06:30
1
MM/dd/yyyy hh:mm
tt 08/22/2006 06:30 AM
2
MM/dd/yyyy H:mm
08/22/2006 6:30
3
MM/dd/yyyy h:mm tt
08/22/2006 6:30 AM
The patterns for DateTime.ToString ( 'G' ) :
0
MM/dd/yyyy HH:mm:ss
08/22/2006 06:30:07
The patterns for DateTime.ToString ( 'm' ) :
0
MMMM dd
August 22
The patterns for DateTime.ToString ( 'r' ) :
0
ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
Tue, 22 Aug 2006 06:30:07 GMT
The patterns for DateTime.ToString ( 's' ) :
0
yyyy'-'MM'-'dd'T'HH':'mm':'ss
2006-08-22T06:30:07
The patterns for DateTime.ToString ( 'u' ) :
0
yyyy'-'MM'-'dd HH':'mm':'ss'Z'
2006-08-22 06:30:07Z
The patterns for DateTime.ToString ( 'U' ) :
0
dddd, dd MMMM yyyy HH:mm:ss
Tuesday, 22 August 2006 06:30:07
The patterns for DateTime.ToString ( 'y' ) :
0
yyyy MMMM 2006 August
Building a custom DateTime.ToString Patterns
The following details the meaning of each pattern character. Note the K and z character.
d
Represents the day of the month as a number from 1 through 31. A single-digit day is formatted without a leading zero
dd
Represents the day of the month as a number from 01 through 31. A single-digit day is formatted with a leading zero
ddd
Represents the abbreviated name of the day of the week (Mon, Tues, Wed etc)
dddd
Represents the full name of the day of the week (Monday, Tuesday etc)
h
12-hour clock hour (e.g. 7)
hh
12-hour clock, with a leading 0 (e.g. 07)
H
24-hour clock hour (e.g. 19)
HH
24-hour clock hour, with a leading 0 (e.g. 19)
m
Minutes
mm
Minutes with a leading zero
M
Month number
MM
Month number with leading zero
MMM
Abbreviated Month Name (e.g. Dec)
MMMM
Full month name (e.g. December)
s
Seconds
ss
Seconds with leading zero
t
Abbreviated AM / PM (e.g. A or P)
tt
AM / PM (e.g. AM or PM
y
Year, no leading zero (e.g. 2001 would be 1)
yy
Year, leadin zero (e.g. 2001 would be 01)
yyy
Year, (e.g. 2001 would be 2001)
yyyy
Year, (e.g. 2001 would be 2001)
K
Represents the time zone information of a date and time value (e.g. +05:00)
z
With DateTime values, represents the signed offset of the local operating system's   time zone from Coordinated Universal Time (UTC), measured in hours. (e.g. +6)
zz
As z but with leadin zero (e.g. +06)
zzz
With DateTime values, represents the signed offset of the local operating system's   time zone from UTC, measured in hours and minutes. (e.g. +06:00)
f
Represents the most significant digit of the seconds fraction; that is, it represents the tenths of a second in a date and time value.
ff
Represents the two most significant digits of the seconds fraction; that is, it represents the hundredths of a second in a date and time value.
fff
Represents the three most significant digits of the seconds fraction; that is, it represents the milliseconds in a date and time value.
ffff
Represents the four most significant digits of the seconds fraction; that is, it represents the ten thousandths of a second in a date and time value. While it is possible to display the ten thousandths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.
fffff
Represents the five most significant digits of the seconds fraction; that is, it represents the hundred thousandths of a second in a date and time value. While it is possible to display the hundred thousandths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.
ffffff
Represents the six most significant digits of the seconds fraction; that is, it represents the millionths of a second in a date and time value. While it is possible to display the millionths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.
fffffff
Represents the seven most significant digits of the seconds fraction; that is, it represents the ten millionths of a second in a date and time value. While it is possible to display the ten millionths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.
F
Represents the most significant digit of the seconds fraction; that is, it represents the tenths of a second in a date and time value. Nothing is displayed if the digit is zero.
:
Represents the time separator defined in the current DateTimeFormatInfo..::.TimeSeparator property. This separator is used to differentiate hours, minutes, and seconds.
/
Represents the date separator defined in the current DateTimeFormatInfo..::.DateSeparator property. This separator is used to differentiate years, months, and days.
"
Represents a quoted string (quotation mark). Displays the literal value of any string   between two quotation marks ("). Your application should precede each quotation mark with an escape character (\).
'
Represents a quoted string (apostrophe). Displays the literal value of any string between two apostrophe (') characters.
%c
Represents the result associated with a c custom format specifier, when the custom date and time format string consists solely of that custom format specifier. That is, to use the d, f, F, h, m, s, t, y, z, H, or M custom format specifier by itself, the application should specify %d, %f, %F, %h, %m, %s, %t, %y, %z, %H, or %M. For more information about using a single format specifier, see Using Single Custom Format Specifiers.
||\c || Represents the escape character, and displays the character "c" as a literal when that character is preceded by the escape character (\). To insert the backslash character itself in the result string, the application should use two escape characters ("\\").

Any other character copies any other character to the result string, without affecting formatting. ||


Saturday, June 1, 2013

What is the difference between convert.tostring and .tostring()

 Just to give an understanding of what the above question means seethe below code.
int i =0;
MessageBox.Show(i.ToString());
MessageBox.Show(Convert.ToString(i));
We can convert the integer “i” using “i.ToString()” or “Convert.ToString” so what’s the difference.
The basic difference between them is “Convert” function handles NULLS while “i.ToString()”
does not it will throw a NULL reference exception error. So as good coding practice using
“convert” is always safe.

Thursday, May 30, 2013

System.Data.SQLClient ,System.Data.OledbClient ,System.Data.ODBCClient

System.Data.SQLClient

Can only be used for connecting to SQL Server 2000 and later. But you will get optimal performance when connecting to those databases.

System.Data.OledbClient

Can be used to connected to SQL 6.5

OLEDBClient gives you ability to connect to other database like ORALCE or Access. But for working with SQL Server you will get better performance using SQLClient.

Note: For connecting to ORALCE Microsoft also has ORACLEClient.

System.Data.ODBCClient- provides connection to legacy databases ( e.g. MS Access 97) using ODBC drivers.

Wednesday, May 29, 2013

Read txt File in RichtextBox

 Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
        'Specify file
        Dim myfile As String = "C:\test.txt"
        'Check if file exists
        If System.IO.File.Exists(myfile) = True  Then
            'Read the file
            Dim objReader As New System.IO.StreamReader(myfile)
            'Save file contents to textbox
            RichTextBox1.Text = objReader.ReadToEnd
            objReader.Close()
        Else
            MsgBox("File not found!")
        End If
    End Sub

Monday, May 27, 2013

send mail in windows application using vb.net

Try
            Dim msg As New System.Net.Mail.MailMessage()
            'msg.[To].Add("vinay.shukla88@gmail.com")
            'msg.[Bcc].Add("jitendra.srivastava555@gmail.com")
            msg.[To].Add(TextBox3.Text)
            msg.[Bcc].Add(TextBox4.Text)
            msg.Subject = TextBox1.Text
            msg.Body = TextBox2.Text
            msg.IsBodyHtml = False
            Dim SMPclint As New SmtpClient()
            SMPclint.Host = "smtp.gmail.com"
            SMPclint.EnableSsl = True
            Dim NetCry As New NetworkCredential()
            NetCry.UserName = "sandeepyadav.bca@gmail.com"
            NetCry.Password = "pwd"
            SMPclint.UseDefaultCredentials = True
            SMPclint.Credentials = NetCry
            Dim fromMailAddr As New MailAddress("sandeepyadav.bca@gmail.com", "")
            msg.From = fromMailAddr
            SMPclint.Port = 587
            SMPclint.Send(msg)
            MessageBox.Show("Message Sent")
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

Monday, May 13, 2013

Multicolor RichTextBox


RichTextBox1.Text = "This is black "
        ' Move the insertion point to the end of the line
        RichTextBox1.Select(RichTextBox1.TextLength, 0)
        ' Set the formatting and insert the second snippet of text
        RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Bold)
        RichTextBox1.SelectionColor = Color.Green
        RichTextBox1.AppendText("BOLD GREEN")
        '' Revert the formatting back to the defaults, and add the third snippet of text
        RichTextBox1.SelectionFont = RichTextBox1.Font
        RichTextBox1.SelectionColor = RichTextBox1.ForeColor
        RichTextBox1.AppendText(" black again")

Sunday, May 12, 2013

Getting Button Name And Text on Mouse Click


Private Sub btnNon_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles Emergency.Click
Dim buttonName As String = ""
If TypeOf sender Is Button Then
buttonName = DirectCast(sender, Button).Name
MessageBox.Show(buttonName)
End If

For  Getting Text :-
 buttonName = (CType(sender, Button).Text)

Thursday, May 9, 2013

Open Word file on Button Click Vb.Net

Public Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
     Dim oWord As Word.Application
        Dim oDoc As Word.Document
        Dim oTable As Word.Table
        Dim oPara1 As Word.Paragraph, oPara2 As Word.Paragraph
        Dim oPara3 As Word.Paragraph, oPara4 As Word.Paragraph
        Dim oRng As Word.Range
        Dim oShape As Word.InlineShape
        Dim oChart As Object
        Dim Pos As Double
        'Start Word and open the document template.
        oWord = CreateObject("Word.Application")
        oWord.Visible = True
        oDoc = oWord.Documents.Add
        'Insert a paragraph at the beginning of the document.
        oPara1 = oDoc.Content.Paragraphs.Add
        oPara1.Range.Text = "Heading 1--Sandeep Kumar Yadav"
        oPara1.Range.Font.Bold = True
        oPara1.Format.SpaceAfter = 24    '24 pt spacing after paragraph.
        oPara1.Range.InsertParagraphAfter()
        'Insert a paragraph at the end of the document.
        '** \endofdoc is a predefined bookmark.
        oPara2 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
        oPara2.Range.Text = "Heading 2-- M.Tech"
        oPara2.Format.SpaceAfter = 6
        oPara2.Range.InsertParagraphAfter()
        'Insert another paragraph.
        oPara3 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
        oPara3.Range.Text = "This is a sentence of normal text. Now here is a table:"
        oPara3.Range.Font.Bold = False
        oPara3.Format.SpaceAfter = 24
        oPara3.Range.InsertParagraphAfter()
        'Insert a 3 x 5 table, fill it with data, and make the first row
        'bold and italic.
        Dim r As Integer, c As Integer
        oTable = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, 3, 5)
        oTable.Range.ParagraphFormat.SpaceAfter = 6
        For r = 1 To 3
            For c = 1 To 5
                oTable.Cell(r, c).Range.Text = "r" & r & "c" & c
            Next
        Next
        oTable.Rows.Item(1).Range.Font.Bold = True
        oTable.Rows.Item(1).Range.Font.Italic = True
        'Add some text after the table.
        'oTable.Range.InsertParagraphAfter()
        oPara4 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
        oPara4.Range.InsertParagraphBefore()
        oPara4.Range.Text = "And here's another table:"
        oPara4.Format.SpaceAfter = 24
        oPara4.Range.InsertParagraphAfter()
        'Insert a 5 x 2 table, fill it with data, and change the column widths.
        oTable = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, 5, 2)
        oTable.Range.ParagraphFormat.SpaceAfter = 6
        For r = 1 To 5
            For c = 1 To 2
                oTable.Cell(r, c).Range.Text = "r" & r & "c" & c
            Next
        Next
        oTable.Columns.Item(1).Width = oWord.InchesToPoints(2)   'Change width of columns 1 & 2
        oTable.Columns.Item(2).Width = oWord.InchesToPoints(3)
        'Keep inserting text. When you get to 7 inches from top of the
        'document, insert a hard page break.
        Pos = oWord.InchesToPoints(7)
        oDoc.Bookmarks.Item("\endofdoc").Range.InsertParagraphAfter()
        Do
            oRng = oDoc.Bookmarks.Item("\endofdoc").Range
            oRng.ParagraphFormat.SpaceAfter = 6
            oRng.InsertAfter("A line of text")
            oRng.InsertParagraphAfter()
        Loop While Pos >= oRng.Information(Word.WdInformation.wdVerticalPositionRelativeToPage)
        oRng.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
        oRng.InsertBreak(Word.WdBreakType.wdPageBreak)
        oRng.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
        oRng.InsertAfter("We're now on page 2. Here's my chart:")
        oRng.InsertParagraphAfter()
        'Insert a chart and change the chart.
        oShape = oDoc.Bookmarks.Item("\endofdoc").Range.InlineShapes.AddOLEObject( _
            ClassType:="MSGraph.Chart.8", FileName _
            :="", LinkToFile:=False, DisplayAsIcon:=False)
        oChart = oShape.OLEFormat.Object
        oChart.charttype = 4 'xlLine = 4
        oChart.Application.Update()
        oChart.Application.Quit()
        'If desired, you can proceed from here using the Microsoft Graph
        'Object model on the oChart object to make additional changes to the
        'chart.
        oShape.Width = oWord.InchesToPoints(6.25)
        oShape.Height = oWord.InchesToPoints(3.57)
        'Add text after the chart.
        oRng = oDoc.Bookmarks.Item("\endofdoc").Range
        oRng.InsertParagraphAfter()
        oRng.InsertAfter("THE END.")
        'All done. Close this form.
        oWord.ActiveDocument.SaveAs("C:\Documents and Settings\CLIENT4\My Documents\word\Log.doc")
        Me.Close()   

    End Sub

Tuesday, May 7, 2013

How to create a new folder in VB.net

microsoft scripting runtime 
'Import namespace so you can manipulate files and folders
Imports System.IO
 
Public Class Form1
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles Button1.Click
        ' Check if folder exists, if not: create it
        If Not Directory.Exists("C:\New Folder") Then
            Directory.CreateDirectory("C:\New Folder")
            ' Folder created message
            MessageBox.Show("Folder created!", "Info", MessageBoxButtons.OK, 
MessageBoxIcon.Information)
        Else
            ' Folder already exists
            MessageBox.Show("Folder already exists!", "Info", MessageBoxButtons.OK, 
MessageBoxIcon.Stop)
        End If
    End Sub
 
End Class