Visual Basic coding for GCSE work

RAZER Gamer

Estimable
May 27, 2015
35
0
4,590
I have just started my Computer Science GCSE and have learnt the very basics, this work isn't for GCSE but is still being marked. I was wondering if anyone could help me add a loop to this code:

Imports System.Console

Imports System.Math

Module Module1


Private Function CtoF(Celsius As Single) As Single

Return Round(Celsius * 9 / 5 + 32, 1)

End Function

Private Function FtoC(Fahrenheit As Single) As Single

Return Round((Fahrenheit - 32) * 5 / 9, 1)

End Function

Private Function CtoK(Celsius As Single) As Single

Return Round(Celsius + 273.15, 1)

End Function

Private Function FtoK(Fahrenheit As Single) As Single

Return Round((Fahrenheit + 459.67) * 5 / 9, 1)

End Function

Private Function KtoC(Kelvin As Single) As Single

Return Round(Kelvin - 273.15, 1)

End Function

Private Function KtoF(Kelvin As Single) As Single

Return Round((Kelvin - 273.15) * 1.8 + 32, 1)

End Function

Sub Main()


Dim Fahrenheit, Celsius, Kelvin As Single

Dim UserOption As Short

BackgroundColor = ConsoleColor.DarkBlue

ForegroundColor = ConsoleColor.White

Clear()

WriteLine("WELCOME TO THE TEMERATURE CONVERSION TOOL!")

WriteLine("Please choose to convert between Celsius/Fahrenheit/Kelvin. ")

WriteLine("Please press Enter to continue:")

ReadLine()

Clear()

WriteLine("List of conversion options:")

WriteLine(" (1) Please type 1 for Celsius to Fahrenheit")

WriteLine(" (2) Please type 2 for Fahrenheit to Celsius")

WriteLine(" (3) Please type 3 for Celsius to Kelvin")

WriteLine(" (4) Please type 4 for Fahrenheit to Kelvin")

WriteLine(" (5) Please type 5 for Kelvin to Celsius")

WriteLine(" (6) Please type 6 for Kelvin to Fahrenheit")

UserOption = ReadLine()

If UserOption >= 6 Then
Clear()
WriteLine("Error: Please enter a number listed 1-6")
ReadLine()
End If

If UserOption <= 1 Then
Clear()
WriteLine("Error: Please enter a number listed 1-6")
ReadLine()
End If

If UserOption = 1 Then

Clear()

Write("Please enter the amount in Celsius that you want to convert to Fahrenheit: ")

Celsius = ReadLine()

WriteLine("Fahrenheit = " & CtoF(Celsius))

WriteLine("Thank you for using the Temperature conversion tool!")

ReadLine()

End If

If UserOption = 2 Then

Clear()

Write("Please enter the amount in Fahrenheit that you want to convert to Celsius: ")

Fahrenheit = ReadLine()

WriteLine("Celsius = " & FtoC(Fahrenheit))

WriteLine("Thank you for using the Temperature conversion tool!")

ReadLine()

End If

If UserOption = 3 Then

Clear()

Write("Please enter the amount in Celsius that you want to convert to Kelvin: ")

Celsius = ReadLine()

WriteLine("Kelvin = " & CtoK(Celsius))

WriteLine("Thank you for using the Temperature conversion tool! ")

ReadLine()

End If

If UserOption = 4 Then

Clear()

Write("Please enter the amount in Fahrenheit that you want to convert to Kelvin: ")

Fahrenheit = ReadLine()

WriteLine("Kelvin = " & FtoK(Fahrenheit))

WriteLine("Thank you for using the Temperature conversion tool!")

ReadLine()

End If

If UserOption = 5 Then

Clear()

Write("Please enter the amount in Kelvin that you want to convert to Celsius: ")

Kelvin = ReadLine()

WriteLine("Celsius = " & KtoC(Kelvin))

WriteLine("Thank you for using the Temperature conversion tool! ")

ReadLine()

End If

If UserOption = 6 Then

Clear()

Write("Please enter the amount in Kelvin that you want to convert to Fahrenheit: ")

Kelvin = ReadLine()

WriteLine("Fahrenheit = " & KtoF(Kelvin))

WriteLine("Thank you for using the Temperature conversion tool! ")

ReadLine()

End If

End Sub

End Module


The code is a bit too spaced out because I copied it, but never mind, I would just like to add a restart to the:
If UserOption >= 6 Then
Clear()
WriteLine("Error: Please enter a number listed 1-6")
ReadLine()
End If

If UserOption <= 1 Then
Clear()
WriteLine("Error: Please enter a number listed 1-6")
ReadLine()
End If

Or an application restart, basically I want the error to restart the program.

Thanks
 

martinch

Estimable
Mar 21, 2014
28
0
4,590
Logically, you want something like:

while (true)
begin
// Print options, read selection and act accordingly
end while

I'll leave how to code it and the body of the loop as an exercise for you :)