Basically, it seems to make it easier to debug your programs.
Here is the tutorial I wrote, based off of a tutorial from www.java2s.com/tutorial/vb
Module Module1
Public negative As Long = 33
Sub beepUp(ByRef negative)
For i = 1 To 10
Console.Beep(200, 200)
Threading.Thread.Sleep(1000)
negative += 3
Console.WriteLine(negative)
Next i
End Sub
Sub Main()
Dim maxValue As Byte = &HFF
Dim posValue As UInteger = &HF034
Dim negValue As Integer = &HF034
Dim negative As Long = -44
Console.WriteLine(maxValue)
Console.WriteLine(posValue)
Console.WriteLine(negValue)
Call beepUp(negative)
Console.WriteLine(negative)
For i = 1 To 10
Console.Beep(200, 200)
Threading.Thread.Sleep(1000)
negative += -2
Console.WriteLine(negative)
Next i
End Sub
I added a lot to this, including the subroutine, the loops, the long value, etc.
End Module
I then made the following changes - created a Sub called beepUp that replaced the for i function, and changed it to byVal. I think I more or less have byVal and byVar fixed in my head.
Module Module1
Public negative As Long = 33
Sub beepUp(ByRef negative)
For i = 1 To 10
Console.Beep(200, 200)
Threading.Thread.Sleep(1000)
negative += 3
Console.WriteLine(negative)
Next i
End Sub
Sub beepDown(ByVal negative)
For i = 1 To 10
Console.Beep(300, 250)
Threading.Thread.Sleep(500)
negative += -5
Console.WriteLine(negative)
Next
End Sub
Sub Main()
Dim maxValue As Byte = &HFF
Dim posValue As UInteger = &HF034
Dim negValue As Integer = &HF034
Dim negative As Long = -44
Dim craziness As Integer
craziness = negative
Console.WriteLine(craziness)
Console.Beep(100, 300)
Console.WriteLine(negative)
Console.Beep(100, 300)
Console.WriteLine(maxValue)
Console.WriteLine(posValue)
Console.WriteLine(negValue)
Call beepUp(negative)
Console.WriteLine(negative)
Call beepDown(negative)
Console.WriteLine(negative)
Call beepUp(negative)
End Sub
End Module
I also did another one of their console tutorials.
Sub main()
Dim result As New System.Text.StringBuilder()
result.AppendLine("MaxValue...")
Dim maxByte As Byte = Byte.MaxValue
Dim maxSByte As SByte = SByte.MaxValue
Dim maxShort As Short = Short.MaxValue
Dim maxUShort As UShort = UShort.MaxValue
Dim maxInteger As Integer = Integer.MaxValue
Dim maxUInteger As UInteger = UInteger.MaxValue
Dim maxLong As Long = Long.MaxValue
Dim maxULong As ULong = ULong.MaxValue
result.Append("Byte = ").AppendLine(CStr(maxByte))
result.Append("SByte = ").AppendLine(CStr(maxSByte))
result.Append("Short = ").AppendLine(CStr(maxShort))
result.Append("UShort = ").AppendLine(CStr(maxUShort))
result.Append("Integer = ").AppendLine(CStr(maxInteger))
result.Append("UInteger = ").AppendLine(CStr(maxUInteger))
Console.WriteLine(result.ToString())
Threading.Thread.Sleep(3000)
End Sub
I did another tutorial, only with option explicit set to On. I also changed the addition into a function.
Option Explicit On
Module Module1
Public sumOfNumbers As Integer
Function addition(ByVal number1 As Integer, ByVal number2 As Integer)
sumOfNumbers = number1 + number2 ''add numbers
Return sumOfNumbers
End Function
Sub Main()
Dim firstNumber, secondNumber As String
Dim number1, number2, sumOfNumbers As Integer
firstNumber = CStr(10)
secondNumber = CStr(20)
number1 = CInt(firstNumber)
number2 = CInt(secondNumber)
Call addition(number1, number2)
sumOfNumbers = number1 + number2 ''add numbers
Console.WriteLine("The is is {0}", sumOfNumbers)
System.Console.Beep(300, 300)
Threading.Thread.Sleep(3000)
End Sub
End Module
Here is another tutorial I worked on
Dim n As Integer
System.Console.Beep(200, 200)
n = 10
n += 5
n = CStr(n)
Console.WriteLine("addition " & n)
Threading.Thread.Sleep(1000)
System.Console.Beep(200, 200)
n = 10
n -= 5
n = CStr(n)
Console.WriteLine("subtraction " & n)
Threading.Thread.Sleep(1000)
System.Console.Beep(200, 200)
n = 10
n *= 5
n = CStr(n)
Console.WriteLine("multiplication " & n)
Threading.Thread.Sleep(1000)
System.Console.Beep(200, 200)
n = 10
n /= 5
n = CStr(n)
Console.WriteLine("multiplication " & n)
Threading.Thread.Sleep(1000)
System.Console.Beep(200, 200)
No comments:
Post a Comment