Wednesday, August 31, 2011

8.31.11

Dim Customer As New Customer

Protected Sub btnContinue_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnContinue.Click
If chkMail.Checked Then
Customer.Mail = True
Else
Customer.Mail = False
End If

If rdoEmail.Checked Then
Customer.MailType = "Email"
ElseIf rdoPostal.Checked Then
Customer.MailType = "Postal"
End If
End Sub


Protected Sub btnUpload_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles btnUpload.Click
Dim iSizeLimit As Integer = 5242880 '5mb
If uplCustList.HasFile Then
If uplCustList.PostedFile.ContentLength <= iSizeLimit Then
Dim sPath As String = "C:\uploads\" & uplCustList.FileName
uplCustList.SaveAs(sPath)
lblMessage.Text = "File uploaded to " & sPath
Else
lblMessage.Text = "File exceeds size limit."
End If
End If
End Sub


Option Strict On
Imports System
Namespace ArrayDemo
'a simple class to store ni the array
Public Class Employee
Private empID As Integer

'constructor
Public Sub New(ByVal empID As Integer)
Me.empID = empID
End Sub 'new

Public Overrides Function ToString() As String
Return empID.ToString()
End Function 'toString
End Class 'Employee

Class Tester

Public Sub Run()
Dim intArray() As Integer
Dim empArray() As Employee
intArray = New Integer(5) {}
empArray = New Employee(3) {}

'populate the array
Dim i As Integer
For i = 0 To empArray.Length - 1
empArray(i) = New Employee(i + 5)
Next i

Console.WriteLine("The integer array...")
For i = 0 To intArray.Length - 1
Console.WriteLine(intArray(i).ToString())
Next i

Console.WriteLine(ControlChars.Lf + "The employee array...")
For i = 0 To empArray.Length - 1
Console.WriteLine(empArray(i).ToString())
Next i

End Sub 'Run

Shared Sub Main()
Dim t As New Tester()
t.Run()
End Sub 'Main

End Class 'Tester

End Namespace 'ArrayDemo


Public Sub Run()
Dim intArray As Integer() = {2, 4, 6, 8, 19}
Dim empArray As Employee() = _
{New Employee(5), New Employee(7), New Employee(8), New Employee(12)}

Console.WriteLine("The Integer array...")
Dim theInt As Integer
For Each theInt In intArray
Console.WriteLine(theInt.ToString())
Next

Console.WriteLine("The employee array...")
Dim e As Employee
For Each e In empArray
Console.WriteLine(e.ToString())
Next e

End Sub 'Run


Namespace ArrayDemo

Class Tester

Public Sub Run()
Dim a As Integer = 5
Dim b As Integer = 6
Dim c As Integer = 7
Console.WriteLine("Calling with three Integers")
DisplayVals(a, b, c)


Console.WriteLine("Calling with four integers")
DisplayVals(5, 6, 7, 8)

Console.WriteLine("Calling with an array of four Integers")
Dim explicitArray() As Integer = {5, 6, 7, 8}
DisplayVals(explicitArray)

End Sub 'Run

Public Sub DisplayVals(ByVal ParamArray intVals() As Integer)
Dim i As Integer
For Each i In intVals
Console.WriteLine("DisplayVals {0}", i)
Next i
End Sub 'DisplayVals

Shared Sub Main()
Dim t As New Tester()
t.Run()
End Sub

End Class
End Namespace


Public Sub Run()
Const rowsUB As Integer = 4
Const columnsUB As Integer = 3

' define and initialize the array
Dim rectangularArray As Integer(,) = _
{{0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {9, 10, 11}}

'report the contents of the array
Dim i As Integer
For i = 0 To rowsUB - 1
Dim j As Integer
For j = 0 To columnsUB - 1
Console.WriteLine("rectangularArray[{0},{1}] = {2}", _
i, j, rectangularArray(i, j))
Next
Next
End Sub 'Run

No comments: