hi, for homework an optional task was to create a binary to denary and denary to binary converter, using console application in VB.NET .. anyway i gave it my best shot however and it all works except for the denary to binary conversion, can someone please help me out? not been programming for very long so my code might be a bit messy or badly written i dont know, but if someone can help me fix this itd be really appreciated..
VB.NET:
Module Module1
Sub Main()
'Declare variables
Dim subjump As String
Dim retry As Char
'Set console window dimensions, add title to console window
Console.WindowHeight = 30
Console.WindowWidth = 100
Console.Title = "Binary<->Denary Converter"
'Repeat label
repeat:
'Prompt user to select type of conversion, read into the subroutine jump variable after being uppercased
Console.WriteLine("Please select conversion type(For Binary->Denary type BIN, for Denary->Binary type DEN)")
subjump = UCase(Console.ReadLine)
'Redirects to appropriate subroutine depending on requested conversion type
If subjump = "BIN" Then
BIN()
ElseIf subjump = "DEN" Then
DEN()
Else
'If user input invalid type of conversion, jump to repeat label to try again
Console.WriteLine("Invalid response, please try again")
GoTo repeat
End If
'Ask user if they wish to try another conversion, read into retry variable
Console.WriteLine("Would you like to try another conversion? (Y/N)")
retry = UCase(Console.ReadLine)
'If user chooses to try another, jump to repeat label, else continue
If retry = "Y" Then
GoTo repeat
End If
'Display exit message, console window closes after 1.5 seconds
Console.WriteLine("Thank you for using the converter.")
System.Threading.Thread.Sleep(1500)
Console.Out.Close()
End Sub
Sub BIN()
'Prompt user to input value to be converted, value converted to denary as it is read into variable 'output1'
Console.WriteLine("Please enter the Binary number you wish to convert to Denary")
Dim output1 As Integer = Convert.ToInt32(Console.ReadLine, 2)
'Result of conversion is outputted to user
Console.WriteLine("Your number in Denary is " & output1)
End Sub
Sub DEN()
'Prompt user to input value to be converted, value converted to binary as it is read into variable 'output1'
Console.WriteLine("Please enter the Denary number you wish to convert to Binary")
Dim output1 As Integer = Convert.ToInt32(Console.ReadLine, 10)
'Result of conversion is outputted to user
Console.WriteLine("your number in Binary is " & output1)
End Sub
End Module
Last edited: