Tuesday, 5 February 2013

Begining With vb.net


Module Module1
    Sub Main()
	' Create List.
	Dim list As List(Of String) = New List(Of String)'list is a data type Of 'string means the list ois of type String
	list.Add("dot")
	list.Add("perls")
	list.Add("net")
	' Sort List.
	list.Sort()'inbuilt sort method will sort elements
	' Display sorted List contents.
	Console.WriteLine(String.Join(" ", list))
    End Sub
End Module
---------------------------------------------------------
Module Module1
    Sub Main()
	' Create Dictionary.
	Dim dict As Dictionary(Of String, Integer) =
	    New Dictionary(Of String, Integer)
	dict.Add("dot", 1)
	dict.Add("net", 2)
	dict.Add("perls", 3)
	' Lookups.
	Console.WriteLine(dict("dot"))
	Console.WriteLine(dict("net"))
	Console.WriteLine(dict("perls"))
    End Sub
End Module
--------------------------------------------------------------------
'Stack implementaion in vb.net.
'he khup simple ahe
Module Module1
    Sub Main()'just like main() in the c language
	Dim stack As Stack(Of Integer) = New Stack(Of Integer)
	stack.Push(10)
	stack.Push(100)
	stack.Push(1000)

	' Display stack elements.
	For Each value As Integer In stack 
'for each mean every element will be iterated for all stack elements .
'just like for in C,but with small diffrrence
	    Console.WriteLine(value)
	Next
    End Sub
End Module
-----------------------------
'The StringBuilder class is used to append the strings
Imports System.Text

Module Module1
    Sub Main()
	' Declare new StringBuilder Dim
	Dim builder As New StringBuilder

	' Append a string to the StringBuilder
	builder.Append("Here is the list:")

	' Append a line break
	builder.AppendLine()

	' Append a string and then another line break
	builder.Append("1 dog").AppendLine()

	' Get internal String value from StringBuilder
	Dim s As String = builder.ToString

	' Write output
	Console.WriteLine(s)
	Console.ReadLine()
    End Sub
End Module
------------------------------------
'buider replace()
Imports System.Text

Module Module1
    Sub Main()
	Dim builder As New StringBuilder("Initialize the StringBuilder.")
	builder.Replace("the", "my")

	Console.WriteLine(builder.ToString)
	Console.ReadLine()
    End Sub
End Module
-----------------------------------------------------
'The Html file writen at runtime through this
Imports System.IO
Imports System.Web.UI
Imports System.IO
Imports System.Web.UI

Module Module1
    Dim _words As String() = {"dot", "net", "perls"}

    Function GetDivElements() As String
	Using sw As StringWriter = New StringWriter
	    Using ht As HtmlTextWriter = New HtmlTextWriter(sw)
		For Each word As String In _words

		    ' Create the div.
		    ht.AddAttribute(HtmlTextWriterAttribute.Class, "c")
		    ht.RenderBeginTag(HtmlTextWriterTag.Div)

		    ' Create the a.
		    ht.AddAttribute(HtmlTextWriterAttribute.Href, word)
		    ht.RenderBeginTag(HtmlTextWriterTag.A)

		    ' Create the img.
		    ht.AddAttribute(HtmlTextWriterAttribute.Src, word + ".png")
		    ht.AddAttribute(HtmlTextWriterAttribute.Width, "200")
		    ht.AddAttribute(HtmlTextWriterAttribute.Height, "150")
		    ht.RenderBeginTag(HtmlTextWriterTag.Img)

		    ' End all the tags.
		    ht.RenderEndTag()
		    ht.RenderEndTag()
		    ht.RenderEndTag()
		Next
	    End Using
	    Return sw.ToString()
	End Using
    End Function

    Sub Main()
	Console.WriteLine(GetDivElements())
    End Sub

End Module
'output

<div class="c">
	<a href="dot"><img src="dot.png" width="200" height="150" /></a>
</div><div class="c">
	<a href="net"><img src="net.png" width="200" height="150" /></a>
</div><div class="c">
	<a href="perls"><img src="perls.png" width="200" height="150" /></a>
</div>
----------------------------------------------------------
Module Module1
    Sub Main()
	' Locals used in Do While loop.
	Dim i As Integer = 100
	Dim z As Integer = 0

	' Loop.
	Do While i >= 0 And z <= 20
	    Console.WriteLine("i = {0}, z = {1}", i, z)
	    i = i - 10
	    z = z + 3
	Loop
    End Sub
End Module
------------------------------------------------------
'sqauare root 
Module Module1
    REM This is Module1.

    ''' <summary>
    ''' This is an XML comment.
    ''' </summary>
    ''' <remarks>Called at program start.</remarks>
    Sub Main()
	REM Get square root of 225.
	Dim value As Double = Math.Sqrt(225)

	' Print value. (Other comment syntax.)
	' ... Sometimes it helps to indent comments.
	Console.WriteLine(value)
    End Sub
End Module
-----------------------
'date
Module Module1
    Sub Main()
	' Write the today value.
	Console.WriteLine("Today: {0}", DateTime.Today)
	' Subtract one day.
	Dim yesterday As DateTime = DateTime.Today.AddDays(-1)
	' Write the yesterday value.
	Console.WriteLine("Yesterday: {0}", yesterday)
    End Sub
End Module
'
Module Module1
    Sub Main()
	' Write first day of current year.
	Console.WriteLine("First day: {0}", FirstDayOfYear)
	' Write first day of 1999.
	Dim y As New DateTime(1999, 6, 1)
	Console.WriteLine("First day of 1999: {0}", FirstDayOfYear(y))
    End Sub

    ''' <summary>
    ''' Get first day of the current year.
    ''' </summary>
    Private Function FirstDayOfYear() As DateTime
	Return FirstDayOfYear(DateTime.Today)
    End Function

    ''' <summary>
    ''' Get first day of the specified year.
    ''' </summary>
    Private Function FirstDayOfYear(ByVal y As DateTime) As DateTime
	Return New DateTime(y.Year, 1, 1)
    End Function
----------------------------
Windows Application in vb.net
Module Module1
    Sub Main()
	' Write first day of current year.
	Console.WriteLine("First day: {0}", FirstDayOfYear)
	' Write first day of 1999.
	Dim y As New DateTime(1999, 6, 1)
	Console.WriteLine("First day of 1999: {0}", FirstDayOfYear(y))
    End Sub

    ''' <summary>
    ''' Get first day of the current year.
    ''' </summary>
    Private Function FirstDayOfYear() As DateTime
	Return FirstDayOfYear(DateTime.Today)
    End Function

    ''' <summary>
    ''' Get first day of the specified year.
    ''' </summary>
    Private Function FirstDayOfYear(ByVal y As DateTime) As DateTime
	Return New DateTime(y.Year, 1, 1)
    End Function
====================================================
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, _
			   ByVal e As System.EventArgs) Handles MyBase.Load
	'
	' Fill in the data grid on form load.
	'
	DataGridView1.DataSource = GetDataTable()
    End Sub

    Private Function GetDataTable() As DataTable
	'
	' This Function needs to build the data table.
	'
	Return New DataTable()
    End Function
End Class

No comments:

Post a Comment