VB Trace Table Help!

Associate
Joined
2 Dec 2004
Posts
138
Location
oxford
Hi All, I have been asked to create a trace table from the following piece of Code:
Code:
Value = 1
Do While DecimalNumber <> 0
    Digit = (DecimalNumber Mod 2) ‘= Number DIVIDE Number
    BinaryNumber = BinaryNumber & Digit
    DecimalNumber = DecimalNumber \ 2
    Value = Value * 2
Loop
Output BinaryNumber
I have been researching this for a while but i still don't understand how i can create a trace table with this code. I have been given what values to run through "starting with DecimalNumber equal to 7 and again with DecimalNumber equal to 254. "

Then suggest any code changes...

If anyone could help me it would be greatly appreciated.

Thanks,

Iceman911
 
Last edited:
Associate
Joined
5 Jun 2005
Posts
987
Location
Leicestershire
Trace tables are a construct in computer science, used to perform a "dry run" (on paper if you like) of an algorithm, to analyse how the algorithm's state changes as it executes, and thus to check that it does what is expected. Basically you put every variable in a block of code being analysed into its own column across the top of a table, and then put the instructions executed by the program down the side. For each instruction you record the current values of the variables in the grid. And there you have your trace table.

See here:http://mias.uwimona.edu.jm/training/cit/introprog/Slides/Tracing.ppt

You should be able to understand what to do now I think. Post back if you don't understand/have questions.
 
Associate
OP
Joined
2 Dec 2004
Posts
138
Location
oxford
Thank you for your reply. Is this what the trace table should look like. Sorry for my ignorance but my Course is not a programming course, but has this unit in it :confused:

Value
Value 1
DecimalNumber 7
Digit 3.5
BinaryNumber 3.5
DecimalNumber 1.75
Value 3.5
Output 0000111

Thank you.

Iceman911
 
Associate
Joined
5 Jun 2005
Posts
987
Location
Leicestershire
Err well not quite, like I said, variables accross the top, instructions down the side, values of variables for each instruction in the grid. Thus you see what the effect of each step is, and how the program/algorithm terminates. I've done the dry run with Value 7. I included the conditional value as an "extra" column so you can see when it changes to false (and hence the loops stops.)



Obviously one problem with the code appears to be that "BinaryNumber" is not initialized, hence at the end it still has whatever it had at the beginning prepended to the result. Obviously it should be initialized to blank before doing anything else. I guess that's part of what they wanted you to "discover" by doing the trace of the algorithm.
 
Back
Top Bottom