Jun 29, 2009

Morning Joe and Calculations in Lectora

How can you use Lectora to convert kilobytes to megabytes? On the surface this seems like a basic question not worth expanding on. However, the solution in Lectora involves using variables in a creative way so I thought I'd share my thoughts. I'm also testing the waters with a morning cup of Joe today. I had stopped drinking coffee because it made me a little edgy but it's so good I'm reverting back today. Hopefully I won't go off the deep end!

Open a new Lectora project (or use an existing one) and add the following items to the page:
  • A text entry field (Add > Object > Form Object > Entry Field). Accept the defaults but change both the entry name and associated variable name to "kilobytes".
  • A button (Tools > Button Wizard). Choose any button. Name it "Calculate".
  • A text block (Add > Object > Text Block). Name it "Result".

Next, you need to add a variable (Tools > Variable Manager). Name it "calculate_megabytes".

Now its time to play with actions. This is where the logic resides in Lectora. Create an action group (Add > Group). Name the group "Calculate Megabytes". With the group selected, add the following three actions to the group (Add > Action).
  • In the first action, use modify variable to set calculate_megabytes to the value of the text entry field. You have to use VAR() to get the contents of the kilobytes variable. That is a little trick that will come in handy down the road if you continue to work with variables in Lectora. Be sure to spell the variable correctly including case sensitivity.

    • Action Name: Set Megabytes Variable
    • Action: Modify Variable
    • Target: calculate_megabytes
    • Value: VAR(kilobytes)
    • Modification Type: Set Variable Contents

  • On the second action, use modify variable to multiply calculate_megabytes by 0.0009765625. One kilobyte is 0.0009765625 megabytes. It takes 1024 kilobytes to make 1 megabyte.

    • Action Name: Kilobytes to Megabytes
    • Action: Modify Variable
    • Target: calculate_megabytes
    • Value: 0.0009765625
    • Modification Type: Multiply Variable By

  • On third third action, use change contents to set the text block equal to calculate_megabytes to reveal the calculation result to the learner.

    • Action Name: Show Result
    • Action: Change Contents
    • Target: Result
    • New Contents: calculate_megabytes

Be sure to check and make sure the actions are in the correct order in the action group. Otherwise, the calculation will not work correctly. The correct order is "Set Megabytes Variable" then "Kilobytes to Megabytes" then "Show Result".

Finally, connect the action group to the button. Open the button properties and select the On Click tab. Choose the action "Run Action Group" with the target "Calculate Megabytes".

You're good to go. Preview the project and test it out. My pace of typing has started to increase. The coffee must be kicking in.

No comments: