Sub main()
Dim temp As Integer
temp = Console.ReadLine()
If temp > 32 Then
Console.WriteLine("Temperature above freezing. Watch out for water on the road.")
Else ''This else is very important, you must add it.
If temp <= 32 Then
Console.WriteLine("Warning! Ice on Road!")
If temp = 32 Then
Console.WriteLine("Temp exactly freezing, beware of water.")
Else
Console.WriteLine("Watch out for black ice!" & " Temp: {0} ", temp)
End If
End If
End If
End Sub
Here is another tutorial from that book, I modified it a little with a do - loop while
Dim keepGoing As Boolean = True
Dim targetInteger As Integer
Do
targetInteger = Console.ReadLine()
Select Case targetInteger
Case 5
Console.WriteLine("5")
keepGoing = False
Case 10
Console.WriteLine("10")
keepGoing = False
Case 15
Console.WriteLine("15")
keepGoing = False
Case 20
Console.WriteLine("20")
keepGoing = False
Case 25
Console.WriteLine("25")
keepGoing = False
Case Else
Console.WriteLine("Value not found. Please try again.")
End Select
Loop While keepGoing = True
Console.WriteLine("Information accepted")
Here is a final case select tutorial
Dim target As String = "Milo"
Select Case target
Case "Alpha" To "Lambda"
Console.WriteLine("Alpha to Lamba Executed")
Case "Lamba" To "Zeta"
Console.WriteLine("Lamba to Zeta Executed")
Case Else
Console.WriteLine("Else executed")
End Select
Here is an online tutorial on arrays from http://www.java2s.com/Tutorial/VB/0160__Collections/0020__Array.htm
Sub main()
Dim sourceArray() As Integer = {1, 2, 3, 4, 5, 6, 7, 8}
Dim result As New System.Text.StringBuilder
Dim counter As Integer
result.Append("{")
For counter = 0 To sourceArray.Length - 1
result.Append(sourceArray(counter).ToString())
If (counter < (sourceArray.Length - 1)) Then result.Append(", ")
Next counter
result.Append("}")
Console.WriteLine(result.ToString())
Console.ReadLine()
End Sub
Here is another tutorial
Dim arySalaries(15) As Integer
Dim aryNames(15) As String
Dim intCounter As Integer
aryNames(0) = "JZ"
arySalaries(0) = 36000
aryNames(1) = "BT"
arySalaries(1) = 63000
aryNames(2) = "LS"
arySalaries(2) = 45000
' set other array names here
aryNames(15) = "PX"
arySalaries(15) = 18000
'show the elements of the array
For intCounter = 0 To 15
Console.WriteLine("Array element: " & intCounter & vbCrLf & "Salary: " & arySalaries(intCounter) & vbCrLf)
Next
Console.ReadLine()
Here is another Jesse Liberty console tutorial
Dim counterVariable As Integer = 0
Do While counterVariable < 10
Console.WriteLine("CounterVariable: {0}", counterVariable)
counterVariable = counterVariable + 1
Loop
Console.ReadLine()
Here I wrote a quick count-controlled tutorial
Dim countVar As Integer = 0
Dim arrayHolder(15) As Integer
Do Until countVar = arrayHolder.Length - 1
arrayHolder(countVar) = 3 * (countVar + 1)
Console.WriteLine(arrayHolder(countVar))
countVar += 1
Loop
Console.ReadLine()
Here is a Jess Liberty tutorial using exit Do
'using exit Do
Dim counterVariable As Integer = 0
Do
Console.WriteLine("counterVariable: {0}", counterVariable)
counterVariable = counterVariable + 1
If counterVariable > 9 Then
Exit Do
End If
Loop
Console.ReadLine()
Here is a quick tutorial I wrote on using inner and outer loops
'using a for loop
Dim inner As Integer
Dim outer As Integer
For inner = 1 To 15
For outer = 1 To 15
Console.WriteLine("{0} * {1} = {2}", inner, outer, inner * outer)
Next
Next
Console.ReadLine()
Here is a Jesse Liberty tutorial on mods
'modulus operator to return remainders
Dim counter As Integer
'count from 1 to 100
For counter = 1 To 100
'display the value
Console.Write("{0} ", counter)
If counter Mod 10 = 0 Then
Console.WriteLine(vbTab & counter)
End If
Next counter
Console.ReadLine()
No comments:
Post a Comment