Monday, November 22, 2010

Monday 11/22/2010


Sub Main()
OneValue("Mr. Gates")
Console.WriteLine()
TwoValues(50, "Mr. Gates")
Console.WriteLine()
ThreeValues("Mr. Gates ", 50, 2500000.0)
Console.ReadLine()
End Sub

Sub OneValue(ByVal Name As String)
Console.WriteLine("Hello " & Name)
End Sub

Sub TwoValues(ByVal Age As Integer, ByVal Name As String)
Console.WriteLine("Age: " & Age)
Console.WriteLine("Name: " & Name)
End Sub

Sub ThreeValues(ByVal Name As String, ByVal Age As Integer, ByVal Salary As Double)
Console.WriteLine("Name: " & Name)
Console.WriteLine("Age: " & Age)
Console.WriteLine("Salary: " & Salary)
End Sub


Here is a tutorial that will return a string value from a function


Sub Main()
Dim iFirstDay As Integer
Dim iLastDay As Integer
Dim iCurrentDay As Integer

iFirstDay = Console.ReadLine()
iLastDay = Console.ReadLine()

For iCurrentDay = iFirstDay To iLastDay
System.Console.WriteLine(WeekdayName(iCurrentDay))
Next iCurrentDay
Console.ReadLine()

End Sub

Function WeekdayName(ByVal iDayNumber As Integer) As String
Dim sWeekdayName As String

Select Case iDayNumber
Case 1
sWeekdayName = "Sunday"
Case 2
sWeekdayName = "Monday"
Case 3
sWeekdayName = "Tuesday"
Case 4
sWeekdayName = "Wednesday"
Case 5
sWeekdayName = "Thursday"
Case 6
sWeekdayName = "Friday"
Case 7
sWeekdayName = "Saturday"
Case Else
sWeekdayName = ("Invalid Day Number")
End Select
Return sWeekdayName

End Function


Here is a tutorial looking at arrays


Sub Main()
Dim arr As Array
Dim int() As Integer = {12, 16, 20, 24, 28, 32, 36}
Dim int2() As Integer = {12, 16, 20, 24, 28, 32, 36}
arr = CType(int, Array)

For i = 0 To int.GetUpperBound(0)
Console.WriteLine("Int2(" & i & "): " & int2(i))
Next



Dim byFours() As Integer = {12, 24, 36, 38, 50}
Dim names() As String = {"k", "s", "s", "d", "n"}
Dim miscData() As Object = {"This", 12D, 16UI, "a"c}
Dim objArray() As Object

miscData = names

Dim myArray1a() As Integer
Dim myArray1b As Integer()
Dim myArray2(10) As Integer

Dim Employees1(,) As Object
Dim employees2(200, 2) As Object

Dim jagged1(9)() As String
Dim jagged2()() As String = New String(9)() {}

Dim myArray1arr As Array
Dim myArray2a As Array = Array.CreateInstance(GetType(Integer), 10)

Dim members() As Integer = {3, 10}
Dim myArray3a As Array = Array.CreateInstance(GetType(Integer), members)

Console.ReadLine()

End Sub



Here is another array


Dim i As Integer

Dim array As Integer() 'declare array variable
array = New Integer(9) {} 'allocate memory for array

Console.WriteLine("Subscript " & vbTab & "Value ")

For i = 0 To array.GetUpperBound(0)
Console.WriteLine(i & vbTab & array(i))
Next

Console.WriteLine("The array contains " & _
array.Length & " elements")


Console.ReadLine()


Here is a tutorial by Michael Halverston on managing windows forms and controls at run time



Dim form2 As New Form

form2.Text = "My New Form"
form2.FormBorderStyle = FormBorderStyle.FixedDialog

'specift that the position of the form will be set manually
form2.StartPosition = FormStartPosition.Manual

'declare a rectangle structure to hold the 4 dimensions
'upper left corner of the form (200, 100)
'width and height of the form (300, 250)

Dim form2Rect As New Rectangle(200, 100, 300, 250)

'set the bounds of the form using the rectangle object
form2.DesktopBounds = form2Rect

'display the form as a modal dialog box
form2.ShowDialog()

End Sub


Here is the last tutorial for the evening on initializing arrays


Dim array1, array2 As Integer() 'declare two arrays

'initializer list specifies number of elements
'and value of each element
array1 = New Integer() {2, 7, 4, 8, 5, 14, 90, 60, 70, 42}

'allocate array2 based on length of array1
array2 = New Integer(array1.GetUpperBound(0)) {}

'set vlues in array2 by a calculation
For i = 0 To array2.GetUpperBound(0)
array2(i) = 2 + 2 * i
Next

Console.WriteLine("Subscript " & vbTab & "Array1" & vbTab & "Array2")
Console.WriteLine("")
'display values for both arrays
For i = 0 To array1.GetUpperBound(0)
Console.WriteLine(i & " " & vbTab & vbTab & array1(i) & vbTab & array2(i))

Next
Console.ReadLine()

No comments: