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

Show parent comments

1

u/LondonPilot Jan 12 '20

Excellent.

If I was sitting down with you, there’s a lot more we could do to bring it towards being professional standard, but for a beginner I’d say that’s not a bad start. It’s 100 times easier to read than it was before, and one of the most important things to learn if you want to improve is that your code must be easy to read. Professional programmers spend 80% of their time changing code, and only 20% writing new code, so making code easy to read is vital. Well done - I hope your teacher agrees!

1

u/Dennis13631 Jan 12 '20

Thanks man i appreciate all the help u gave me but i still feel like i wont even finish it alone :( This seems way too hard for a beginner or maybe its just me that im bad at this . Ive tried with SetCursorPosition too but it just wont place the next chars on the same row

1

u/LondonPilot Jan 12 '20

Yeah, SetCursorPosition is probably the way to go here.

Let’s try breaking it down. First of all, concentrate on the user typing in just two letters. Decide where the second letter should go on the screen, and use SetCursorPosition to put the second letter in the right place. You will need a variable to keep track of whether it’s the first or second letter. And you can “hard code” the position, so just work out the correct X and Y for each part of the character you’re displaying, and put the numbers in the program code.

The next step is to make it work with more than two letters. Again, use a variable to keep track of how many letters you’ve done so far, but this time try to get the program to calculate the X position using some simple maths (something like characterNumber * 10, if you have a variable called characterNumber and you decide to allow 10 spaces per character).

That will work so long as the user’s text fits on one line. If you have time for a bit more of a challenge, you can work on splitting text over more than one line... you’ll need to calculate the X position (which will be a bit more complex now), and also the Y position, so this really is a bit of a challenge, and definitely not one to worry about until you’re confident with just one line.

1

u/Dennis13631 Jan 12 '20

But to be honest we still havent learned that setcursorposition so not sure how it works completly i just found it while browsing to get my job done :D

→ More replies (0)