Tuesday, November 8, 2011

Tuesday 11.8.11

Sub Main()
Dim myChar As Char = "a"c
Console.WriteLine("Char.IsDigit('a') {0}", Char.IsDigit(myChar))
Console.WriteLine("Char.IsLetter('a') {0}", Char.IsLetter(myChar))
Console.WriteLine("Char.IsWhiteSpace('Hello There', 5): {0}", Char.IsWhiteSpace("Hello There", 5))
Console.WriteLine("Char.IsWhiteSpace('Hello There', 6): {0}", Char.IsWhiteSpace("Hello There", 6))
Console.WriteLine("Char.IsPunctuation('?'): {0}", Char.IsPunctuation("?"c))

Dim c As Char = Char.Parse("w")
Console.WriteLine("Value of myChar: {0}", c)

End Sub


Module Module1

Sub Main()
Console.WriteLine("****** Fun With Strings *******")
Dim firstName As String = "June"

Console.WriteLine("Value of firstName: {0}", firstName)
Console.WriteLine("firstName has {0} characters.", firstName.Length)
Console.WriteLine("firstName in uppercase: {0}", firstName.ToUpper())
Console.WriteLine("firstName in lowercase: {0}", firstName.ToLower())

Dim myValue As Integer = 3456789
Console.WriteLine("Hex value fo myValue is: {0:X}", myValue)
Console.WriteLine("Currency value of myValue is: {0:C}", myValue)
End Sub

End Module


Sub Main()
'Use the StringBuilder
Dim sb As New StringBuilder("***** Fantastic Games ******")
sb.Append(vbLf)
sb.AppendLine("Half Life 2")
sb.AppendLine("Beyond Good and Evil")
sb.AppendLine("Deus Ex 1 and 2")
sb.Append("System Shock")
sb.Replace("2", "Deus Ex: Invisible War")
Console.WriteLine(sb)
Console.WriteLine("Sb has {0} chars.", sb.Length)
End Sub


Imports System.Text

Module Module1

Sub Main()
'Accept all defaults for the optional
PrintFormattedMessage("Call One")

'Provide each optional argument
PrintFormattedMessage("Call Two", True, 5, ConsoleColor.Yellow)

'Print this message in current case, one time, in gray
PrintFormattedMessage("Call Three", , , ConsoleColor.Gray)

'same as previously show, but Cleaner!
PrintFormattedMessage("Call Four", textColor:=ConsoleColor.Gray)

End Sub


Sub PrintFormattedMessage(ByVal msg As String, _
Optional ByVal upperCase As Boolean = False, _
Optional ByVal timesToRepeat As Integer = 0, _
Optional ByVal textColor As ConsoleColor = ConsoleColor.Green)
'store current console foreground color
Dim fGroundColor As ConsoleColor = Console.ForegroundColor
'set console foreground color
Console.ForegroundColor = textColor
'print message in correct case x number of times
For i As Integer = 0 To timesToRepeat
Console.WriteLine(msg)
Next
'reset current foreground color
Console.ForegroundColor = fGroundColor
End Sub
End Module


Imports System.Text

Module Module1

Sub Main()
ArrayOfObjects()

End Sub


Sub ArrayOfObjects()
Console.WriteLine("=> Array of Objects.")
' an array of objects can be anything at all.
Dim myObjects(3) As Object
myObjects(0) = 10
myObjects(1) = False
myObjects(2) = New DateTime(1969, 3, 24)
myObjects(3) = "Form & Void"

For Each obj As Object In myObjects
'print the type and value for each item in array.
Console.WriteLine("Type: {0}, Value: {1}", obj.GetType(), obj)
Next
End Sub
End Module


Imports System.Text

Module Module1

Sub Main()
RedimPreserve()
End Sub


Sub RedimPreserve()
Console.WriteLine("=> Redim / Preserve keywords.")
'Make an array with ten slots
Dim myValues(9) As Integer
For i As Integer = 0 To 9
myValues(i) = i
Next
For i As Integer = 0 To UBound(myValues)
Console.WriteLine("{0} ", myValues(i))
Next

'ReDim the array with extra slots
ReDim Preserve myValues(15)
For i As Integer = 9 To UBound(myValues)
myValues(i) = i
Next

For i As Integer = 0 To UBound(myValues)
Console.WriteLine("{0} ", myValues(i))
Next

Console.WriteLine()
End Sub

End Module


Imports System.Text

Module Module1

Sub Main()
RedimPreserve()
End Sub


Sub RedimPreserve()
Console.WriteLine("=> Redim / Preserve keywords.")
'Make an array with ten slots
Dim myValues(9) As Integer
For i As Integer = 0 To 9
myValues(i) = i
Next
For i As Integer = 0 To UBound(myValues)
Console.WriteLine("{0} ", myValues(i))
Next

'ReDim the array with extra slots
ReDim Preserve myValues(15)
For i As Integer = 9 To UBound(myValues)
myValues(i) = i
Next

For i As Integer = 0 To UBound(myValues)
Console.WriteLine("{0} ", myValues(i))
Next

Console.WriteLine()
End Sub

End Module


Partial Class Paging
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim connStr As String = WebConfigurationManager.ConnectionStrings("Northwind").ConnectionString
Dim sqlStr As String = "SELECT [ProductID],[ProductName], [UnitPrice], [UnitsInStock] FROM Products"
Dim ds As New DataSet
Dim SqlAdapter As New SqlDataAdapter(sqlStr, connStr)
SqlAdapter.Fill(ds)

GridView1.DataSource = ds
GridView1.DataBind()

End Sub


Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
GridView1.DataBind()
End Sub
End Class

No comments: