r/visualbasic • • Jan 12 '20

Need a bit help

So ive done a program and my teacher just casually said its spagheti code and i need to somehow fix it but im totally out of idea how to do that so i would appreciate all help i can get from here!
Here is the code:
https://pastebin.com/qzPbMXh8

6 Upvotes

33 comments sorted by

View all comments

1

u/fuzzfeatures Jan 16 '20 edited Jan 16 '20

Hi again,

Have a look at my previous post first .. this explains some simplifications to your original code. The code below adds the ability to type in several characters and display them.

Rather than include the whole code here, I've pasted everything after the user input prompt

        Dim validCharacters As String = "0123456789AbcdEFGHhLnoPtUY"
        'Check that the entered text characters are all valid
        Dim allCharactersValid As Boolean = True
        For Each character As String In text
            If Not validCharacters.Contains(character) Then
                allCharactersValid = False
                Exit For
            End If
        Next

        Dim index As Integer
        If allCharactersValid Then
            For Each character As String In text
                index = validCharacters.IndexOf(character)
                For i As Integer = 0 To numbers(index).GetUpperBound(0)
                    Console.Write(numbers(index)(i))
                Next
                Console.Write(" ")
            Next
            Console.WriteLine()
            For j As Integer = 0 To letters(index).GetUpperBound(0)
                For Each character As String In text
                 Console.Write(letters(validCharacters.IndexOf(character))(j) & " ")
                Next
                Console.WriteLine()
            Next
        Else
            Console.WriteLine("wrong value!")
        End If
        Console.ReadKey()
    End Sub