Using Variables Inside and Outside of Your Title

Uses of Variables

Variables are logical objects within a Lectora title that enable you to store, modify, and test values of numbers or strings during the runtime of a published title. You can conditionally perform actions in a title based on variable values and you can display variable values to the user.

There are many uses for variables, including branching to different sections of a title depending on user preferences and displaying information based on multiple user inputs. Variables enable you, as the title author, to capture what a user has done (such as click on a button) within the title and to conditionally act on that at a later time.

When you modify a variable, it is done with an action. See below.

To see all the variables in your title, select Tools>Variable Manager. Reserved variables are ones that are automatically created for you, i.e. entry fields, test questions, etc. User-Defined variables are variables that you create with an initial value and modify them with actions, as seen above.

Copying Your Variables to an Outside Database

If you want to store these variables and their values to an external source like a database or email, you would need to contact someone within your organization to write a cgi script to capture the data. They can write the script in whatever format/file type that is supported by the server hosting the content. A programmer knowledgeable in server-side scripting and database integration over the Internet/Intranet should perform the integration between Lectora and the database. Below is a sample ASP script that shows the setup of a basic script.

<%@ Language=VBScript %>
<%
'Get the parameters posted from the test'
testname=Request.form("TestName")
score=Request.form("Score")
user=Request.form("name")
numQuestions=Request.form("NumQuestions")
passingGrade=Request.form("PassingGrade")

'Validate that this is actually from a Lectora test'
if testname="" Or score="" Or user="" Or numQuestions="" Or passingGrade="" then
  Response.Write "<html>"
  Response.Write "<head><title>Failure</title></head>"
  Response.Write "<body>"
  Response.Write "STATUS=500"
  Response.Write "<br>"
  Response.Write "Could not parse test results due to a parameter error."
  Response.Write "</body></html>"
else
  'Write the results to a file named the same as the test'
  'This could be a database or any kind of object store, but'
  'to keep it simple, we will just use a flat text file'
  fileName = "c:\" & testname & ".log"
  
  'Open the results file for append'
  Const ForReading = 1, ForWriting = 2, ForAppending = 8

  Set objFSO = CreateObject("Scripting.FileSystemObject")

  if not objFSO.FileExists(fileName) then
    objFSO.CreateTextFile(fileName)
  end if

  Set objInFile = objFSO.OpenTextFile( fileName, ForAppending, True )

  'Write the results'
  objInFile.WriteLine( Date & ", " & Time & ", " & user & ", " & score )

  'Older courses produced by Lectora used a zero based index for the questions '
  '(i.e. Question0 is the first question)'
  'Newer courses are one based (i.e. Question1 is the first question)'
  'determine which one it is'
  Dim startIndex
  valTemp = Request.form("Question0")
  if( valTemp="" ) then
    startIndex=1
  else
    startIndex=0
  end if

  'Write all of the questions and answers'
  for i = startIndex to cint(startIndex + numQuestions-1)
    nameQ = "Question" + CStr(i)
    nameA = "Answer" + CStr(i)
    valQ = Request.form(nameQ)
    valA = Request.form(nameA)
    objInFile.WriteLine( nameQ & ": " & valQ )
    objInFile.WriteLine( nameA & ": " & valA )
  Next

  'Close results file'
  objInFile.Close
  Set objInFile = Nothing
  Set objFSO = Nothing
end if
%>

Support | About Trivantis
© Copyright Trivantis Corporation 2016