Tuesday, November 8, 2011

Tuesday 11.08.11

Module Module1

Sub Main()
'show banner
DisplayBanner()
'Get user's name and say howdy
GreetUser()
End Sub

Sub DisplayBanner()
'Get the current color of the console text
Dim currColor As ConsoleColor = Console.ForegroundColor

'set text color to yellow
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("***** Welcome to FunWithModules *****")
Console.WriteLine("This simple program illustrates the role")
Console.WriteLine("of the Module type.")
Console.WriteLine("**********************************")

'reset the previous color of your console text.
Console.ForegroundColor = currColor
Console.WriteLine()
End Sub

Sub GreetUser()
Dim userName As String
Console.Write("Please enter your name: ")
userName = Console.ReadLine()
Console.WriteLine("Hello there {0}. Nice to meet ya.", userName)
End Sub
End Module


Public Class Program

Shared Function Main(ByVal args As String()) As Integer
'OS running this app?
Console.WriteLine("Current OS: {0}", Environment.OSVersion)

'List the drives on this machine.
Dim drives As String() = Environment.GetLogicalDrives()
Dim d As String
For Each d In drives
Console.WriteLine("You have a drive named {0}.", d)
Next


'Which version of the .NET platform is running this app?
Console.WriteLine("Executing version of .NET: {0}", Environment.Version)
Return 0

End Function

End Class


Module Module1

Sub Main()
Console.WriteLine("***** Fun With Data Types *****")
Console.WriteLine("Max of Integer: {0}", Integer.MaxValue)
Console.WriteLine("Min of Integer: {0}", Integer.MinValue)
Console.WriteLine("Max of Double: {0}", Double.MaxValue)
Console.WriteLine("Min of Double: {0}", Double.MinValue)
Console.WriteLine("Boolean.FalseString: {0}", Boolean.FalseString)
Console.WriteLine("Boolean.TrueString: {0}", Boolean.TrueString)
Console.ReadLine()

End Sub

End Module

Friday, November 4, 2011

Friday 11.4.11

Imports System.Web.Configuration
Imports System.Data.SqlClient
Imports System.Data

Partial Class listDataBinding
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If (Not Page.IsPostBack) Then
'create the Command and the Connection
Dim connectionString As String = WebConfigurationManager.ConnectionStrings("Northwind").ConnectionString
Dim sql As String = "SELECT EmployeeID, TitleOfCourtesy + ' ' + FirstName + ' ' + LastName As FullName FROM Employees"
Dim con As New SqlConnection(connectionString)
Dim cmd As New SqlCommand(sql, con)

Try
'Open the connection and get the data reader
con.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader()
'Bind the DataReader to the list
lstNames.DataSource = reader
lstNames.DataBind()
reader.Close()

Catch ex As Exception
Response.Write(ex.ToString())
Finally
'close the connection
con.Close()
End Try
End If
End Sub

Protected Sub cmdGetSelection_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdGetSelection.Click
Result.Text &= "Selected Employees:"
For Each li As ListItem In lstNames.Items
If li.Selected Then
Result.Text &= String.Format("
  • ({0}) {1}
  • ", li.Value, li.Text)
    End If
    Next
    End Sub
    End Class