Charas-Project

  • Home
  • Help
  • Search
  • Calendar
  • Login
  • Register
*
Please login or register.

Login with username, password and session length
 

News:

New forum theme up and running!



  • Charas-Project »
  • Off-Topic »
  • Archive »
  • Really Old Stuff »
  • General programming »
  • Visual Basic: Principles of Debugging
« previous next »
  • Print
Pages: [1]

Author Topic: Visual Basic: Principles of Debugging  (Read 3541 times)

Offline Kilyle

  • Because one language is never enough
  • Associate
  • *
  • Posts: 188
  • 45; bard, lifelong learner, published author
    • Marvel Fics by POV
Visual Basic: Principles of Debugging
« on: October 06, 2005, 09:57:25 AM »
First off, there is a slight :| problem, in that the debugging tutorial I wrote in college is in my Yahoo briefcase, and I can't currently access my account (password problems, trying to contact them and have it fixed).

However, if given enough reason, I could come up with a new tutorial covering basically the same stuff.

See, in college, I was a VB tutor for several quarters, and between that and my VB classes, I noticed students making the same darn errors over and over.  And the teachers never seemed to touch on debugging until like third quarter, which is a ridiculous policy.  What is the first thing a student does?  Make a program that doesn't work. _veryangry_ What is the first thing (s)he tries to solve this problem?  Run to the teacher.:bend:

SOOOO...my tutorial basically covers how to figure out what the problem is, how to fix it and, in some more complex instances, how to put on a bandaid so you can fix the problem later (very useful if you're up against a deadline).

If you are just learning how to program in VB, and come up against an error such as "When I press the button, it doesn't do what I told it to do," this is probably a good resource for you.  And if you are a more experienced programmer who nevertheless ends up having to fix simple code errors a couple times before a program will run, this might be a good place to check, as it deals with some helpful habits as well.

That said...anybody here feel they could use a resource like this?  (I hope I can get to my original soon, but if not, I'll start writing a new one in a posting here.)
Logged
I have a website now! Currently just points at my fanfics (over 230 works, totaling over 750,000 words, mostly in Marvel and Person of Interest and now Lackadaisy too). YouTube channel on hiatus but I hope to eventually recreate "A Fugitive in Stardew Valley" now that I know how to mod the game.

Offline Drighton

  • Acolyte
  • *
  • Posts: 419
(No subject)
« Reply #1 on: October 06, 2005, 01:54:54 PM »
I think this would be very useful to me. Sometimes, in theory, my calculations and code should work, but don't play out they way I hope.
Logged

Offline Kilyle

  • Because one language is never enough
  • Associate
  • *
  • Posts: 188
  • 45; bard, lifelong learner, published author
    • Marvel Fics by POV
How far along are you?
« Reply #2 on: October 06, 2005, 09:48:52 PM »
I'd also like a look at what level of programming is being used by my target readers.

Oh, and I don't get anywhere near as far as graphics with my tutorial--although some of the principles could be applied to graphics later on.  We never studied graphics in college, which means I had to leap from Q-Basic pixel art to GameMaker automatic use of graphics files, with no intervening VB step or any real understanding of how graphics files are to be applied to things.

Anyway...please tell me what sort of program you are trying to make at present, or what level of class you are in--that'd help me.
Logged
I have a website now! Currently just points at my fanfics (over 230 works, totaling over 750,000 words, mostly in Marvel and Person of Interest and now Lackadaisy too). YouTube channel on hiatus but I hope to eventually recreate "A Fugitive in Stardew Valley" now that I know how to mod the game.

Offline Drighton

  • Acolyte
  • *
  • Posts: 419
(No subject)
« Reply #3 on: October 08, 2005, 01:34:43 PM »
I'm currently making a 2D RPG, possibly with a LAN multiplay option. I'm also considering my next project to be a 3D RPG. I use DirectX for my graphics.

Currently, I'm pretty much done with all the graphics programming (drawing the stuff is a different matter) and just trying to make decisions on things like menus, inventory screens, coding a battle system, and proper AI.
Logged

Offline Linkizcool

  • Doesn't exist for official purposes.
  • Exemplar
  • *
  • Posts: 1,290
  • I am Canadian.
(No subject)
« Reply #4 on: October 08, 2005, 06:07:35 PM »
I Seriously need help debugging VB... I can't even get my game of Pong to work... No matter I know a lot about VB, commands and all, just not how to debug them.
Logged

Offline Kilyle

  • Because one language is never enough
  • Associate
  • *
  • Posts: 188
  • 45; bard, lifelong learner, published author
    • Marvel Fics by POV
Back to DSL after 2 months with 26kbs!
« Reply #5 on: November 15, 2005, 04:10:51 AM »
Thank God for civilization!  I had like four hours' warning to be packed up to go live with my grandma as she moved from Wisconsin to Washington (we lived at my aunt's house in Port Gamble for two months while the paperwork went thru so she could get an apartment near us).  26kbs--you don't wanna know what I thought of their internet service.

Anyway, I'm back!  So yay!  Unfortunate thing is that Yahoo Customer Care is being, well, not effective in dealing with my login problems, so in the meantime I can't update my webpage and can't access the VB Debugging Tutorial I have on my Yahoo!Briefcase.  So if I'm gonna do one, it's gonna be from scratch, and not as worked-out as the old one.  (Also, it's possible that some of the things I reference are a couple years out of date, but given the subject matter I doubt that will matter.)

Since I can't post this on my webpage as I had planned, guess I'll just post it here:


TITLE: My Program Just Won't Work!


 :( I made a button, and a textbox, and I wrote some code.  When I press the button, it's supposed to print "Orlando Bloom has ruined everything!" but it's not doing anything!  What's wrong?

DIAGNOSTIC: Click the textbox where the line is supposed to appear.

DIAGNOSIS: If the text DOES appear, you have the code in the wrong subroutine.  You were supposed to put it in the sub for the command button; instead, you put it in the sub for the textbox.

SOLUTION: Return to your form and double-click the command button.  This will bring up a sub for the command button.  Find your code and move it into this sub.

PREVENTION: The code does not go in the object where the text appears, but rather in the object that you click on.

 :( But the text didn't appear!  And, now that I look at it, the code is very clearly in the sub Command1_click()

DIAGNOSTIC: Double-click the command button on your form.

DIAGNOSIS: If this sends you to a subroutine called something other than Command1_click()--something like cmdPrintText_click(), say--then you wrote the code in the right place, but then changed the name of your command button.

SOLUTION: Either move the code to the new cmdPrintText_click() sub, or rename Command1_click() to match your current name for the button.

PREVENTION: Always name your objects when you create them, before you write any code.  If you rename objects for any reason, check to make sure that the associated code ends up with the correct names.

ADDITION: A similar problem will crop up if you renamed the textbox.  Say you wrote code using Text1, and then renamed it to txtPrintBox--you will get an error when the computer realizes that no object is named Text1.


Hmm...beginner problems, but things that I saw over and over and over again, things very easily fixed if you learn how to fix them--and things that my instructors never even touched on during the first quarter.
Logged
I have a website now! Currently just points at my fanfics (over 230 works, totaling over 750,000 words, mostly in Marvel and Person of Interest and now Lackadaisy too). YouTube channel on hiatus but I hope to eventually recreate "A Fugitive in Stardew Valley" now that I know how to mod the game.

Offline Barahir

  • Chieftain of the Edain
  • Initiate
  • *
  • Posts: 32
  • I sing tenor in A Cappella choir and I play cello and guitar
(No subject)
« Reply #6 on: November 20, 2005, 08:24:55 PM »
Hehe... having names that are actually relevant to the programme is also a good thing. Like "cmdKillProgramme" as opposed to "command16" or something.

On a side note... does anyone really use comments, in VB coding, unless you're writing a programme that someone else might need to edit later? Because I never really use comments, myself. Granted, I'm not the greatest programmer who ever lived, but I get along, anyway, and I seldom use comments.

       'Know what I mean?
Logged

Offline Kilyle

  • Because one language is never enough
  • Associate
  • *
  • Posts: 188
  • 45; bard, lifelong learner, published author
    • Marvel Fics by POV
Comments Are Good
« Reply #7 on: November 23, 2005, 12:57:07 AM »
ETA: FINALLY Yahoo Customer Care fixes my password problem.  So I found the tutorial in my Briefcase and put an upgraded version on my webpage.  Check out Common Errors in Visual Basic at http://www.geocities.com/Athens/Delphi/7822/Programming/VBDebug.html and will someone PLEASE tell me how to make that a link, because HTML doesn't appear to be working.

By the way, if anyone has some basic debugging comments, e.g. if you kept running across the same error and finally figured out how to fix it (very early in your programming days), feel free to tack them on.  And if you see ANY errors of mine, please point them out, because I'm doing this from memory and without VB installed on my computer (until I find my CDs again).


ON COMMENTS:
See, now, the need for good comments increases with the complexity of the program.

It's sorta related to my biggest beef with video games (mostly RPGs).  If I play a game for a while, get say a third of the way in, and then for some reason I don't or can't play it for a while, and then I return to it...what the heck was I doing?  None of this makes any sense.  I don't even know where I'm supposed to go or what things I need to make sure I get.  So I end up chucking the whole thing and starting the game over...and then getting really bored with the idea because I already did it once.  So in this sort of situation, I might never actually get to see the second part of the game.

(I've seen at least one game where you can initiate a talk between your characters that tells you where you were headed and what you needed to do...what a great idea!)

So with good comments, you can read through a program without trying to translate code into English.  And, in fact, if you had to read the code and translate, you'd be doing a great deal more work than merely translating into English.  You'd be trying to figure out how fifteen sentences would condense into one English sentence.  (Ever read fivers?  Like fivers of Star Trek: Voyager, or fivers of Star Gate?  They take out the fluff and leave the basic plot (and a few jokes).  Same idea.)

Another really good use of comments is when you can't work out what to do with a part, or you're so eager to get to the next bit that you want to skip this one.  So you write "Write the saved game to a file" or "Calculate the damage" and just move on.  You don't need to stick around trying to work out what all you plan to add to the equation (strength of attack, chance of blocking, armor that reduces damage, what have you)--do it later.  This is also good if you're coding and planning at the same time (that is, you didn't work out the entire system ahead of time), as you might later decide that you need different things in that equation.  And you can get back to it when you have the information you need.

I suggest making very visible comments if you need to put more (or different) code in that spot.  You can just skim through your code and note the big blocks of stars, for example.  Real easy.


Anyway...let's see.  (Yahoo, btw, still has my tutorials, still hasn't solved my login problem, and is almost the first entry on my Never Use Their Services Again list.  In the age of the internet, spending four months trying to get an account problem fixed is INSANE.)

:( My code is exactly what the instructor wrote!  But when I try to run it, is says I forgot to include an index!  ((I forget the exact error that pops up for this one.))

DIAGNOSTIC: The error mentions a particular object on your form, right?  Say it's cmdPrintButton.  Go into your code, find the spot where it uses cmdPrintButton, and change it to cmdPrintButton(0).

DIAGNOSIS: If this makes your code run without showing that error, then you made a control array without meaning to.  Basically, you have two (or more) controls with the same name, and to tell them apart the computer treats them like an array: cmdPrintButton(0), cmdPrintButton(1), cmdPrintButton(2), etc.  This means that the computer gave them an index (the number), and won't let you use them without it.

I don't exactly recall what my students did to get in this mess, but they did it a lot, and it involves giving multiple controls the same name.  A message pops up that asks you if you want to create a control array.  Many beginning students don't understand the message; if they press No, the program changes the name back to default (from cmdPrintButton to Command2), which frustrates them, and so if they didn't press Yes the first time, eventually they press Yes anyway.

Quite often, the controls end up on top of each other on the board, so you can't tell that there are multiple controls until you start moving objects around.

SOLUTION: Destroy the extra objects, leaving only one named cmdPrintButton (or whichever name you're using).  Go into its properties and find 'Index'.  It will have a number there; erase it.  You should no longer get this error.

LAST-MINUTE FIX: Depending on circumstances, it might be faster to go into your code and change cmdPrintButton to cmdPrintButton(0) (especially if you've just done this to diagnose the problem, since it would then take NO time).  If this makes your program work, and you don't have time to tinker with it further, leave it.  It's not an elegant solution, and it leaves you with one or more objects that are not being used, but it will at least work.

PREVENTION: Don't ever press 'Yes' to the control array question unless you actually want to create one.  And if the question pops up, realize that you already have a control with that name.  If you move your objects around, you should be able to spot it.  Either delete it or use it.
Logged
I have a website now! Currently just points at my fanfics (over 230 works, totaling over 750,000 words, mostly in Marvel and Person of Interest and now Lackadaisy too). YouTube channel on hiatus but I hope to eventually recreate "A Fugitive in Stardew Valley" now that I know how to mod the game.

  • Print
Pages: [1]
« previous next »
  • Charas-Project »
  • Off-Topic »
  • Archive »
  • Really Old Stuff »
  • General programming »
  • Visual Basic: Principles of Debugging
 

  • SMF 2.0.10 | SMF © 2015, Simple Machines
  • XHTML
  • 2O11
  • RSS
  • WAP2
  • Simple Machines Forum