locked
Using variables inside array declaration RRS feed

  • Question

  • It's in fact a syntax problem. So I just present a solution 

    I need to change an infofield. Sometimes I need "Speed", sometimes I need "Sync", etc

    So the idea was to use a variable InfoField="Speed"

    as you can combine an arrayline such as 

    FIELD18=";color=yellow"
    FIELD[18]="Box=Toggle"+FIELD18
    TextWindow.foregroundcolor=FIELD[18]["color"]
    TextWindow.writeline("tata")
     

    it's possible to declare a variable such as InfoField

    infofield="speed" txtfield="info="+infofield

    TextWindow.writeline("infofield = "+infoFIELD) TextWindow.writeline("txtfield = "+txtFIELD) TextWindow.writeline("") FIELD[18] = "Box=Toggle;"+txtfield+";color=yellow" TextWindow.foregroundcolor=FIELD[18]["color"] TextWindow.writeline("") TextWindow.writeline("RESULT Newfield = "+FIELD[18]["info"])

    or as single-liner  

    Infofield="speed"
    FIELD[18] = "Box=Toggle;"+"info="+infofield+";color=yellow"
    TextWindow.foregroundcolor=FIELD[18]["color"]
    TextWindow.writeline("RESULT Newfield = "+FIELD[18]["info"]) 


    Saturday, July 4, 2020 9:44 AM

Answers

  • You can also change only the info part of FIELD[18]:  (use after your last snippet)

    field[18]["info"]="snelheid"
    TextWindow.writeline("RESULT Newfield = "+FIELD[18]["info"]) 


    Jan [ WhTurner ] The Netherlands


    • Edited by WhTurner33Editor Saturday, July 4, 2020 11:04 AM
    • Proposed as answer by litdev Saturday, July 4, 2020 2:18 PM
    • Marked as answer by WhTurner33Editor Saturday, September 19, 2020 12:22 PM
    Saturday, July 4, 2020 11:03 AM
    Answerer

All replies

  • You can also change only the info part of FIELD[18]:  (use after your last snippet)

    field[18]["info"]="snelheid"
    TextWindow.writeline("RESULT Newfield = "+FIELD[18]["info"]) 


    Jan [ WhTurner ] The Netherlands


    • Edited by WhTurner33Editor Saturday, July 4, 2020 11:04 AM
    • Proposed as answer by litdev Saturday, July 4, 2020 2:18 PM
    • Marked as answer by WhTurner33Editor Saturday, September 19, 2020 12:22 PM
    Saturday, July 4, 2020 11:03 AM
    Answerer
  • Hello Jan,

    Ok jan, it's the normal way but  I was trying to put the variable inside the declaration of the Array. and it was just a syntax solution to use the quotes .

    But I have still another problem - but it can be a SB problem. ... How to assign a variable defined by another variable. as i used to do in the past with the HP-basic.  I get an inputlist with variables and their values ... 

    something such as  Field[15]="var=name;val=20"     

    as I want to use the variable "name" in the program It's clear something as Field[15]["var"]= Field[15]["val"] will not give name=20 and  creating a construction such as

    if field[1]["var"] = "name" then name=Field[15]["val"] endif     is not  a solution also as I don't know all the values I will get for "name".

    It's a problem I encounter often ... If in a program  I am asking to get a variablename as input I cannot use it  without using complex array-searches 


    • Edited by Eddy Abts Monday, July 6, 2020 8:22 PM
    Monday, July 6, 2020 8:19 PM