Public Sub main()
Dim testObject As New Tester()
testObject.run()
Console.ReadLine()
End Sub
Public Class dog
Public weight As Integer
Public color As String
End Class
Public Class Tester
Public Sub run()
'create an integer
Dim firstInt As Integer = 5
'create a second integer
Dim secondInt As Integer = firstInt
'display the two integers
Console.WriteLine("fistInt: {0}, secondInt: {1}", firstInt, secondInt)
'modify the second integer
secondInt = 8
'display the two integers
Console.WriteLine("firstInt: {0}, secondInt {1}", firstInt, secondInt)
'create a dog
Dim milo As New dog()
'assign a value to weight
milo.weight = 5
milo.color = "brown"
'create a second reference to the dog
Dim fido As dog = milo
'display their values
Console.WriteLine("Milo:{0}, {1}; Fido: {2}, {3}", milo.weight, milo.color, fido.weight, fido.color)
'assign a new weight to the second reference
fido.weight = 9
fido.color = "white"
'display the two values
Console.WriteLine("Milo:{0}, {1}; Fido:{2}, {3}", milo.weight, milo.color, fido.weight, fido.color)
End Sub
Here is another tutorial by Jesse Liberty
Option Strict On
Imports System
Public Class TestClass
Sub SomeMethod(ByVal firstParam As Integer, ByVal secondParam As Single)
Console.WriteLine("Here are the parameters recieved: {0}, {1}", _
firstParam, secondParam)
End Sub
End Class
Module Module1
Sub main()
Dim howManyPeople As Integer = 5
Dim pi As Single = 3.14
Dim tc As New TestClass()
tc.SomeMethod(howManyPeople, pi)
Console.ReadLine()
End Sub
End Module
I get the impression that when you code using vb.net you need to have an understanding of Common Intermediate Language going on in the back of your mind.
Here is the final tutorial of the day
Module Module1
Sub main()
Dim array As Integer() = New Integer() {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 35}
Dim total As Integer = 0, i As Integer = 0
For i = 0 To array.GetUpperBound(0)
total += array(i)
Next
Console.WriteLine("Total of array elements: " & total)
Console.ReadLine()
End Sub
End Module
3 comments:
I agree it is a good idea to have a mental construct of what the computer is doing in your mind as you program. You could even think of the computer's behavior as the base class, and your programming source code as the derived class.
(since I couldn't find a way to re-edit this coment, I deleted it and replaced it with a newer one-twice.)
Post a Comment