Understanding code

Help_me_Mannn
08-30-2009, 07:00 AM
Well i have an exam coming up and one of the past papers has this as a question:

Comment on the documentation within the above code. Can you determine the purpose of the RunAway function.

A copy of the code:

Public Sub RunAway (X as Single, Y as Single, Distance As Integer)
Dim NewLeft As Single
Dim NewTop As Single
‘Me being the current form and cmdMove a button on this form
If Y > Me.cmdMove.Top – 100 And Y<Me.cmdMove.Top + Distance + Me.cmdMove.Height Then
‘Horizontally in line
Me.cmdMove.Top = (Me.Height – Me.cmdMove.Height – 400) * Rnd
If X > Me.cmdMove.Left – 100 And X < Me.cmdMove.Left + Distance +Me.cmdMove.Width Then
‘also vertically in line
Me.cmdMove.Left = (Me.Width – Me.cmdMove.Width) * Rnd
End If
End if
EndSub



Can someone please comment each line of the code and tell me what it means. zzz Exam is in a day thanks :D

mkaras
08-30-2009, 04:12 PM
Did you go to the classes?

If not then I would suggest that you try to figure this out on your own. This is a rather easy subroutine and you would do well with making a sample applet, adding a cmdMove button and then calling this subroutine. Try for example seeing what happens when you would call this from the Timer routine in the form.

In general we do not do homework here and I daresay that should include preparation for exams. Problems like this are designed to exercise your ability at logical reasoning and too much concentration on a single routine will not be all that useful for looking at another problem. Also consider that on exam day the time available for such a problem is very limited and it may not be possible to spend half the period on once such problem.

It is also highly likely that the instructor has taken the problem from one of the home work exercises or an in-class discussion. So if you have been engaged all along and keeping apace with the class then the analysis should be a snap.

mkaras

kassyopeia
08-31-2009, 03:24 AM
Regarding
Comment on the documentation within the above code.
I'd suggest you look through your class materials for a discussion of the main purposes of documenting code. Different teachers tend to emphasize different things here. Once you know what is expected, base your comments on whether the given documentation meets these purposes or not.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum