You are on page 1of 2

Public Class Form1 Private Sub Button1_Click() Handles Button1.

Click 'If no character has been entered into textbox UserErrorHandler called If TextBox1.Text = "" Then GoTo UserErrorHandler End If 'If error encountered ErrorHandler called On Error GoTo ErrorHandler Dim Dim Dim Dim Dim character = CStr(TextBox1.Text) charcode As Integer = Asc(character) binaryVal As String remainder As Integer num As Integer

binaryVal = Convert.ToString(charcode, 2) remainder = binaryVal Mod 2 'Program steps through each value in the binary number and adds 1 to variable "num" 'whenever a 1 is found. This summation is divided by 2 and the remainder saved over 'variable "num". For Each variable If variable = num = num End If num = num Mod MsgBox(num) Next MsgBox(num) As Char In binaryVal "1" Then + 1 2

'When the "even" radio button is checked the program checks the value saved in "num". 'If the value is "1" a "1" is added to the end of the binary value making it even. 'If the value of "num" is "0" a "0" is added to the end of the binary value leaving it 'even If RadioButton1.Checked And num = 1 Then TextBox2.Text = binaryVal TextBox4.Text = binaryVal TextBox4.AppendText(1) ElseIf RadioButton1.Checked And num = 0 Then TextBox2.Text = binaryVal TextBox4.Text = binaryVal TextBox4.AppendText(0) End If 'When the "odd" radio button is checked the program checks the value saved in "num". 'If the value is "0" a "1" is added to the end of the binary value making it odd. 'If the value of "num" is "1" a "0" is added to the end of the binary value leaving it

'odd If RadioButton2.Checked And num = 0 Then TextBox2.Text = binaryVal TextBox4.Text = binaryVal TextBox4.AppendText(1) ElseIf RadioButton2.Checked And num = 1 Then TextBox2.Text = binaryVal TextBox4.Text = binaryVal TextBox4.AppendText(0) End If 'Skips over the ErrorHandlers so the Msgbox does not show unconditionally. GoTo SkipHandlers 'When UserErrorHandler called a message box appears prompting the user to input a 'character into the textbox. UserErrorHandler: MsgBox("Please enter character in textbox") ErrorHandlers:MsgBox(Error encountered) SkipHandlers: End Sub End Class

You might also like