r/visualbasic • u/Dennis13631 • 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
3
u/LondonPilot Jan 12 '20 edited Jan 12 '20
It’s not really “spaghetti code” as such - that would suggest the flow of the program is hard to follow.
The flow of this program is simple - but it’s hard to read.
So:
Move the “numbers” and “letters” variables into a different module (or class, if you know about classes yet)
For the “letters” variable, put each string onto a different line, and indent them so that it’s immediately clear that they’re showing the letters (I think Visual Studio will let you do this, I can’t remember and I’m on my phone so I can’t test it)
Take that massive list of if statements, and at the very least change it to a select/case. Even better, if you can figure out how to turn this pseudo-code into code:
If between 0-9, Subtract ASCII code for 0
Else if between A-Z, Subtract ASCII code for A then Add 10