Explore the community Forums Lectora Lectora Questions & Answers Convert Values to Text

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #349050 Score: 0
    Profile photo of Brian Dombrowski
    Brian Dombrowski
    Member
    beginner
    intermediate
    friend finder
    wise owl
    advanced
    @bdombrowski4094

    Hello,

    I am new to working with variables in Lectora. I know that you can create actions that add values to a variable. However, my question is, is it possible to change values/numbers in a variable to text strings and then combine them together. For example, instead of adding the numbers 1,2,3 together in the variable, the numbers would be stored as 123. The idea behind this would be to ultimately have these numbers display in a text box on a page.

    Don’t know if this is possible, but thought I would ask.

    Thanks,
    Brian

    #349055 Score: 1
    Profile photo of Tim K
    Tim K
    Member
    contributor
    beginner
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    wise owl
    curious george
    Group Member
    201 pts
    @timk

    If you only add numbers Lectora will calculate the mathemical result. To prevent Lectora from doing that you have to use a string somewhere, e.g. four actions to a button

    1.

    Action: Modify variable
    Type: Set equal to
    Value: a

    2.

    Action: Modify variable
    Type: Add to variable
    Value: 1

    3.

    Action: Modify variable
    Type: Add to variable
    Value: 2

    4.

    Action: Modify variable
    Type: Subtract from variable
    Value: a

    The result will be “12”

    Tim

    This post has received 1 vote up.
    #349153 Score: 0
    Profile photo of Brian Dombrowski
    Brian Dombrowski
    Member
    beginner
    intermediate
    friend finder
    wise owl
    advanced
    @bdombrowski4094

    Tim,

    Thanks for replying to my original post. This actually works pretty good, but I would like to take this one step further.

    What if I have some buttons on my page that replicate a keypad on a phone or laptop keyboard. I would like to tap random number keys (buttons) so that it stores the numbers  I tap in the order I tap them into the variable. So for example, if I tap the 241 keys, it stores those numbers in the variable in that sequence.  Is that possible to do in Lectora?

    Ideally I would like to have the numbers display as I type in a text box. Don’t know if that is doable though.

    Thanks,
    Brian

    #349162 Score: 1
    Profile photo of Math Notermans
    Math Notermans
    Member
    contributor
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    LUC16 Attendee
    LUC16
    wise owl
    curious george
    67 pts
    @mnotermans5114

    If you use Tim’s tip that will work.

    For each button add a sequence of actions as Tim suggests.
    That will add the current key as a String to that variable..
    in the end you will have the keys you choose in your variable.

    A few things need to change to Tim’s sequence though..

    1.

    Action: Modify variable
    Type: Add to variable ( if you leave this as in Tim’s version to set equal to, your old values are gone )
    Value: a

    2.

    Action: Modify variable
    Type: Add to variable
    Value: 1 <– the value on your button

    3.

    Action: Modify variable
    Type: Subtract from variable
    Value: a

    4.
    Action: Change content
    Target: textfield your using
    Value: Set Text
    Text: VAR(typedValues) <– the variable your using to store things.

     

    Ensure the value of your variable at start is empty else you see 0 upfront.

    This post has received 1 vote up.
    #349280 Score: 0
    Profile photo of Brian Dombrowski
    Brian Dombrowski
    Member
    beginner
    intermediate
    friend finder
    wise owl
    advanced
    @bdombrowski4094

    Thanks, Math. I was able to figure that out before I got your post. I basically did what you suggested.

    The one other thing I would like to be able to do is if necessary, remove the last value in the variable. So if the variable stored 3214, the action triggered would remove 4.

    For something like this though, I’m thinking I would probably have to use a JavaScript function, right?

    #349322 Score: 0
    Profile photo of Math Notermans
    Math Notermans
    Member
    contributor
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    LUC16 Attendee
    LUC16
    wise owl
    curious george
    67 pts
    @mnotermans5114

    Yeah cant think of a Lectora action to remove the last ‘character’ of a variable. A simple javascript like:

    var theString = 'Brian Dombrowski1';
    var theStringMinusOne = theString.slice(0, -1);
    console.log(theStringMinusOne);
    
    will do the trick...
    #349411 Score: 0
    Profile photo of Brian Dombrowski
    Brian Dombrowski
    Member
    beginner
    intermediate
    friend finder
    wise owl
    advanced
    @bdombrowski4094

    That makes, sense, Math. I like can use javasscript to perform operations that are not native to Lectora.

    Thanks,
    Brian

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.