Dynamic Variable Names in OpenScript

Is there a way to use dynamic variable names? What I mean by this is that the variable name in the file could be:
Name1, Name2, Name3, etc.
I may want to loop through these by saying something like:
For i = 0; i < iLoop; i++
String sFieldName = "{{ViewList.Name" + Integer.toString(i) + "}}";
JOptionPane.showMessageDialog(null, "sFieldName: " + "{{ViewList.{{sFieldName}}}}");
I don't want it to use the literal string of {{ViewList.Name1}}, but rather, I want to use the value from the DataBank for Name1. Thanks.
-John

Nishanth,
Thanks for your suggestion. Unfortunately, this is not a simple variable replacement. I want the name of the variable to be dynamic in nature. Imagine that I have 5 variables in the files named:
Name
FoodPref1
FoodPref2
FoodPref3
FoodPref4
I would like to loop through these and construct the variable name dynamically so it would be something similar to:
for i=1 to 4; i++
sFoodPrefVar = "FoodPref" + i;
getVariables().set("FoodPref",sFoodPrefVar);
JOptionPane.showMessageDialog(null, "Your Food Pref is: " + {{FoodPref}} + "\n");
This is pseudo code, but it would theoretically loop through the 4 food preferences. Thanks.
-John

Similar Messages

  • Creating dynamic variable names

    I know there has got to a way to do this but I am not finding anything on google. I want to create a dynamic variable name like name + i so when your in a loop the names come out name1, name2 and so on till however many you want. I have tried
    int name + i = 3;
    int name[i] = 3; // which obviously won't but I had to try
    int name{i} = 3;and I am out of ideas. Thanks for all your help.

    I'd suggest using variables named j or x when posting code which uses them as array indexes.
    [i] - is for italics formatting
    [u] - is for underlined formatting
    [code] is for class Example { ... } code formatting
    etc.

  • Dynamic Variable Names

    Okay, I just need to figure out how to make dynamic variable
    names. In this case, I have a loop, and inside the loop I need to
    create a new array for every iteration of the loop. Something like
    <cfloop from="0" to="10" index="i">
    <cfset LoopArray#i# = Some Value>
    </cfloop>
    But that doesn't work. How can you make dynamic variable
    named? I think it's probably something to do with evaluate or DE,
    but I don't know how to use them, and the livedocs make no sense to
    me. Thanks!

    On Thu, 22 May 2008 17:14:42 +0000 (UTC), kenji776 wrote:
    > Thank you both for your replied, I did manage to find a
    solution (the same one
    > posted by JR "Bob" Dobbs). Pretty much just looks
    like...
    >
    >
    > <cfloop from="1" to="3" index="i">
    > <cfset LinkResults["#i#"][1] = "Player 1's Move
    ID">
    > <cfset LinkResults["#i#"][2] = "Player 2's Move
    ID">
    > <cfset LinkResults["#i#"][3] = "Damage to player
    1">
    > <cfset LinkResults["#i#"][4] = "Damage to player
    2">
    > </cfloop>
    From your values, you don't want a two-dimensional array
    (which although
    you're actually building LinkResults as a struct, with the
    sequential
    numeric keys, it's basically an array), you want an array of
    structs, eg:
    LinkResults
    .player1.moveId
    LinkResults.player1.damage
    What is "i" actually counting through? IE: from 1-3 things...
    which are...
    what?
    Adam

  • Dynamic variable name

    Hi for all.
    I'm need create a object with "dynamic" name. For example
    Object ABCi = new ...
    where i is a indice.
    Please, help-me

    >
    Object ABC[] = new Object [size];
    for (int i=0; i<size;i++) {
    ABC[i] = ....
    }if you do something like this. How do you call one of the instances. How do you know how many there are??
    >
    Dynamic variable name? You're just making problems for
    yourselfIs there a better way? Because sometimes you have to have something like the above. Why is it a big problem?
    Thanks
    Brian

  • Dynamic variable names and invalid_character_err

    I'm neither an expert at structure notation nor dynamic
    variable naming conventions and would appreciate any help with the
    following. Thanks!
    This code works fine.
    <cfset idx="123">
    <cfset form.product[idx]=StructNew()>
    <cfparam name="form.product[idx].product_nm"
    default="Raspberry Jam">
    <cfform name="data_entry" method="post" format="flash"
    height="525" width="675" action="formdump.cfm">
    <cfformgroup type="tabnavigator" height="400"
    width="650">
    <cfformgroup type="page" label="Product #idx#">
    <cfinput name="static_form_name" type="text"
    label="Product" value="#form.product[idx].product_nm#" height="350"
    width="600" readonly="yes">
    </cfformgroup>
    </cfformgroup>
    </cfform>
    The following code results in the following error:
    "ORG.W3C.DOM.DOMEXCEPTION ERROR. Message: INVALID_CHARACTER_ERR: An
    invalid or illegal XML character is specified." The only change is
    in the "name" attribute of the <cfinput> tag:
    <cfset idx="123">
    <cfset form.product[idx]=StructNew()>
    <cfparam name="form.product[idx].product_nm"
    default="Raspberry Jam">
    <cfform name="data_entry" method="post" format="flash"
    height="525" width="675" action="formdump.cfm">
    <cfformgroup type="tabnavigator" height="400"
    width="650">
    <cfformgroup type="page" label="Product #idx#">
    <!--- Change value of name attribute from
    "static_form_name" to "product[idx].product_nm" --->
    <cfinput name="product[idx].product_nm" type="text"
    label="Product" value="#form.product[idx].product_nm#" height="350"
    width="600" readonly="yes">
    </cfformgroup>
    </cfformgroup>
    </cfform>
    Pam Grieger
    [email protected]

    Thanks for the info. Knowing what WON’T work is
    helpful!
    Here’s what I’m trying to do. I’m rewriting
    one of my apps, switching out conventional HTML form controls for
    <cfform> controls in Flash format. Many of the existing forms
    in my app are for updating data contained in a central database.
    When such a form is rendered to the screen, each form control is
    pre-populated with existing data. All form controls are named
    dynamically based upon the unique ID of the record being updated.
    Here’s a streamlined but typical example:
    <!--- User selected projects 14, 15, 16, and 17 for
    update. Get existing project data. --->
    <cfquery name="get_project_detail"
    datasource="#application.DataSource#">
    SELECT project_oid_nbr, project_nm
    FROM project_table
    WHERE project_oid_nbr IN (14,15,16,17)
    ORDER BY project_oid_nbr
    </cfquery>
    <!--- Initialize the project_nm form control. Form names
    are dynamic, based upon get_project_detail.project_oid_nbr. --->
    <cfloop query="get_project_detail">
    <cfparam name="form.project_nm_#project_oid_nbr#"
    default="#get_project_detail.project_nm#">
    </cfloop>
    <!--- Create HTML form control. --->
    <table>
    <cfloop query="get_project_detail">
    <tr>
    <td>
    <cfoutput>
    Project #project_oid_nbr#:
    <input type="text" name="project_nm_#project_oid_nbr#"
    value="#Evaluate("form.project_nm_#project_oid_nbr#")#">
    </cfoutput>
    </td>
    </tr>
    </cfloop>
    </table>
    This has been working just fine. However, I’m wondering
    if using the Evaluate() function is the most efficient way to go.
    Therefore I wanted to use structure notation to avoid the
    Evaluate() function, but as mentioned in my original post, this
    naming convention won’t work with <cfform> tags.
    Any suggestions as to the most efficient way to get the same
    result while still using <cfform> tags? Thanks so much!

  • Dynamic variable name generation

    Hi people,
    Is there any way of generating variable names dynamically in java in a loop? i.e.
    for(int i = 0; i<arrayLength; i++) {
    ArrayX.add(position, object)
    X++
    Where X is 0,1,2...etc. so i would have Array1 with something in it, Array2 with something in it, Array3 and so on.
    This is just a simple example but I've basically got an initial array of URL objects and then I want to call my getURL method on each link in my inital array and store the links associated to each initial URL in a different Array.
    Hope it makes sense, and i hope someone can help!
    Thanks in advance.

    Your example code is not clear to me (what is "position?"), and your description using URLs doesn't seem to need what you are asking for. I would be careful about using arrays - people sometimes use arrays when classes should be used.
    Anyway, I think you can get close to what you want by using a HashMap. You can use Strings as keys and the Strings would be "array01" "array02" etc.

  • Dynamic Variable name (for int/long) from a String variable

    Hi,
    I want to give a int/long variable name from a String.
    for ex.
    String str = lookup + "Id";
    lookup is a String variable coming from XML. Now, for instance lookup="name". So str = "nameId".
    Now I want to create a int/long variable by nameId.
    Could anybody tell me the way how to do. Please don't tell to use MAP.
    Edited by: Shah on Dec 5, 2007 3:26 PM

    Well you can't. Use a Map.
    The compiler translates variable names into slot numbers, either within an object or withing the local "stack frame" and these slot numbers are assigned names at compile time. No new slots can be created at run time. Java is not Basic.
    Reflection allows you to find existing field names and methods (not local variables), so it's possible to map, for example, XML attribute names to field names or setters in an object but the names have to be known at compile time.

  • JSP : create variable dynamic variable name and get his value.

    //HI forums.sun.com !
    //What I want to do is above :
    //out.println("<td style=\"width: "+col_width_+h+" \">")
    //Variable Declaration
    String col_width_1 = "100px";
    String col_width_2 = "150px";
    //etc String col_width_N = "XXXpx";
    //loop
    for (int h = 0; h < hrecset.getRowCount(); h++)
    //some code
    //create the variable name (exemple : col_width_0 ) with the "loop counter name" to get the value
    out.println("<td style=\"width: "+col_width_+h+" \">")//Do you understand what i mean?
    //some code
    //Variable Declaration
    String col_width_1 = "100px";
    String col_width_2 = "150px";
    //etc String col_width_N = "XXXpx";
    //loop
    for (int h = 0; h < hrecset.getRowCount(); h++)
    //some code
    //create the variable name with a concat with the loop counter variable name to get the value of the concatened variable
    out.println("<td style=\"width: "+col_width_+h+" \">")//Do you understand what i mean?
    //some code

    I apologize
    1) Sure i understand it but i click on the "code" button after i inserted the text above but it doesn't worked now it do.
    2) Because the table element need to have the total width in the HTML table TAG equal to the addition of every HTML td TAG to be W3 conform
    because i have a lot of cell where i want to adjust the width.
    so here my solution
    <%
    //Variable für Breite
    String col_width_unit = "px"; // px, cm,
    Integer total_table_width = 0;
    String[] col_width=new String[3];
    col_width[0] =  "350";
    col_width[1] =  "75";
    col_width[2] =  "50";
    %>
    <table style="page-break-inside:avoid;width:<%=gesamt_table_width+col_width_unit%>;">
    <%
    for (int h = 0; h < hrecset.getRowCount(); h++)
    out.println("               <td id =\"cell"+h+"\" class=\"tdall\"  style=\"width:"+col_width[h]+col_width_unit+"\" >");               
    %>
    </table>thank you very much

  • AS2 syntax and dynamic variable names

    Hi all,
    Trying to learn AS2 and hoping someone can help me by
    explaining the problems with the following sample code and what
    would be needed to make it work (i.e. to create dynamic variables
    and movie clips from an array).
    Thanks for your time!

    kglad: Thanks for the super-quick and tremendously helpful
    response! Much appreciated!
    A couple of quick follow-up questions:
    kglad wrote that "createEmptyMovieClip() returns a reference
    to the created movieclip".
    How would I use/access this reference?
    Also, in the updated code below, I have two issues:
    1. rolling over a movie clip yields "this is button
    undefined" rather than "this is button a" for example; and
    2. clicking on a movie clip outputs the result of the trace
    command for all four clips (in reverse order) rather than just the
    one clicked.
    Any insights into what I need to do differently? Thanks
    again!

  • [Custom Tags] Dynamic Variable Name // Spring MVC

    I am having a problem with a tag,
    i try to make a dynamic select tag that is reuseable, the problem is that my spring controller generates a model where i can access the list information for a select and that i have to pass this to the dynamic tag, the model could have different name, so it could be ${listitemsa} ${listitemsb} ${listitemsc} and i want to pass this list to my custom tag.
    i tried the following, but the problem is that the var is passed as a string and not the list, does anybody know how to do this?
    <tag:formfield-selectbox name="listA" path="prototypeForm.selectionA" list="${listitemsa} " />
    <tag:formfield-selectbox name="listB" path="prototypeForm.selectionB" list="${listitemsb} " />
    <tag:formfield-selectbox name="listC" path="prototypeForm.selectionC" list="${listitemsc} " />     
    <%@ tag body-content="scriptless" %>
    <%@ attribute name="name" required="true" %>
    <%@ attribute name="path" required="true" %>
    <%@ attribute name="list" required="false" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %> 
    <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
    <spring:bind path="${path}">
         <c:if test="${status.error}">
              <span class="error">
                   <c:forEach items="${status.errorMessages}" var="error">
                        <c:out value="${error}"/>
                   </c:forEach>
              </span><br />
         </c:if>
         <label for="<c:out value="${status.expression}"/>">${name}: </label>
         <form:select path="${path}">
              <form:option value="-1" label="--Please Select--" />
              <form:options items="${list}" />
         </form:select>
    </spring:bind>

    I've sorted it. Here's the solution for anybody experiencing the same problem.
    The problem is with switching from Java 1.2.1 to Java 1.3.0_02. Custom tags are (as of the JSP 1.1 spec) JavaBean compnents, and the Introspector appears to work differently in different Java versions.
    Consider this example:
    public void setAbc(String abc){}
    public boolean getAbc(){}Since the setter method takes a String and the finder method returns a boolean, the 1.2 Introspector takes the property type to be String, and returns null as the finder name. Java 1.3 (I haven't tested this explicitely, but this is what seems to be happening), returns null for both the setter name and the finder name (Probably a better way to do it, but breaks old code).
    We've rolled back to Java 1.2 and everything works again. It looks to me like the best way to fix the problem for 1.3 is to write custom BeanInfo classes for each JSP custom tag (Can anybody recommend a good JavaBeans book?). I don't yet know what will happen when you have multiple setter methods with different parameter types??? - something I've always found useful in custom tags.
    You don't get the problem on some JSP engines that don't use the Introspector (apparently JRun just puts the method name in the code and lets it fail at runtime if it doesn't exist, whereas apache and iPlanet check the methods exist at compile time).
    Here's where I got most of the answers from:
    http://groups.google.com/groups?hl=en&safe=off&ic=1&th=9330b85b1867cc7,3&seekm=8rnl24%24ef1%241%40nnrp1.deja.com#p
    http://groups.google.com/groups?hl=en&safe=off&ic=1&th=edd3053ac670ff5b,8&seekm=D8E32A666B62F7BD0076240185256A16.0073785185256A15%40webforums#p
    http://groups.google.com/groups?hl=en&safe=off&ic=1&th=7b5480449150ea26,3&seekm=3B2FA8C3.3F14A9F3%40switzerland.org#p

  • How to have a dynamic variable name?

    I have a form that determines how many phone numbers a client has to edit by running a query against the database. The client can have anywhere from 0-3 phone numbers. I am assuming I can just wrap a CFOUTPUT QUERY tag around my input field so that it will loop if there are more than 1. What I can't figure out is how to dynamically name the input field within the CFOUTPUT tag for the UPDATE query I run after the user submits the form.
    For example, if the query find that the user has 2 phone numbers in the table, how do I control their name?
    <cfinput name="?" ..........>
    <cfinput name="?2".........>
    How can this be done dynamically within the cfoutput that is returning results of the query?

    I presume you have an index number for each entry in your database. I would use that number, since you are assured it is unique.

  • Dynamic variable name in trigger

    hi ,
    i would like create audit trail for a table thru trigger where column_name must be dynamic...
    is it possible to fetch :new.column_name and its value dynamically ?
    pls help.

    Because auditors say there needs to be procedures in
    place to audit access to SSN,
    salary, bonus fields and other critical fieldsNow that's auditing access to specfic columns.
    What I'm talking about, and what the OP seems to me to be asking for, is generic auditing off any column. We get quite a lot of questions about such implementing a dynamic column level approach to auditing and I happen to think it's a bad idea. I'm just interested to know why many other people seem to think it's a good idea.
    Cheers, APC

  • C:set with dynamic variable name

    Hello,
    we have a litte market system.
    we iterate over the articles to display them on a page
    foreach article type we have to include a popup, but only once foreach article type.
    So if we have more than one article of the same type, the popup should be included only one time.
    <c:forEach var="article" items="#{MyArticleController.entities}">
        <c:if test="${requestScope[article.dtype] != true}">
            <!-- <ui:include src="/market/details/#{article.dtype}.xhtml"/>  -->          
            <c:set scope="request" var="${article.dtype}" value="1" />
        </c:if>
        <!-- <ui:include src="/market/preview/#{article.dtype}.xhtml"/>-->
    </c:forEach>I think the line with the c:set seems to be the problem.
    How can I solve this problem. How can I set a dynamic value and test against it later?
    Thanks
    Dirk

    You were close with your first example.
    However as noted, the <c:set> tag doesn't accept a dynamic expression for the "var" attribute.
    Suggested alternative: instead of using request attributes, have a seperate map
    <jsp:useBean id="articleTypeUsed" class="java.util.HashMap"/>
    <c:forEach var="article" items="#{MyArticleController.entities}">
        <c:if test="${not empty articleTypeUsed[article.dtype]}">
            <!-- <ui:include src="/market/details/#{article.dtype}.xhtml"/>  -->          
            <c:set target="${articleTypeUsed}" property="${article.dtype}" value="1" />
        </c:if>
        <!-- <ui:include src="/market/preview/#{article.dtype}.xhtml"/>-->
    </c:forEach>That should solve your issue with translating this java code into jstl.
    Whether the mix of JSTL and JSF/ui will work well together is a completely seperate issue, and one I can't really help with.

  • Dynamic variables name

    Hello,
    I'm a beginner and i'm looking from several days to resolve
    this problem but i don't find the solution. Can someone help me,
    Please.
    for each (var art:XML in Rs) {
    var eRef:String = String(art.ref); // Exemple Ref AX51
    Ref.data = eRef; // Exemple Ref AX51
    var aFormula:String = String(art.formula); // Exemple
    Formula +2A-5B+25C
    Formula.data = aFormula; // Exemple Formula +2A-5B+25C
    ??????? = Formula; // Exemple Dynamique Ref AX51 =
    +2A-5B+25C
    <mx:Panel title="XML" width="100%" height="100%">
    <mx:Label text="Formula" fontWeight="bold"/>
    <mx:Text id="AX51"width="100%" height="15"/> // +2A-5B+25C
    </mx:Panel>
    ********************************************/

    Thank for your reply,
    I saw that there is many errors, sorry. I send all the code
    below. I yhink that the problem comes from the object's declaration
    where i don't know to put there and explain why no results appear
    on the screen. First to compil it , i saw errors that came from
    object's deckaration. I can compil it , but there is no result.
    ////////////////////// Base.xml ///////////////////////////
    <?xml version="1.0" ?>
    <arts>
    <art>
    <ID>1</ID>
    <ref>AX51</ref>
    <formula>+2A-5B+25C</formula>
    </art>
    <art>
    <ID>2</ID>
    <ref>AW42</ref>
    <formula>+4F-2H+3K</formula>
    </art>
    <art>
    <ID>3</ID>
    <ref>AW43</ref>
    <formula>+9Z+3T+6B</formula>
    </art>
    </arts>
    ////////////////////// Test.mxml ////////////////////
    <?xml version="1.0" encoding="utf-8"?>
    <mx:ApolloApplication xmlns:mx="
    http://www.adobe.com/2006/mxml"
    width="606" height="614" initialize="initializeHandler();">
    <mx:Script>
    <![CDATA[
    [Bindable]
    private var MyDynamicObject:Object = new Object();
    public function initializeHandler():void {
    var myData:XML = new XML();
    var XML_URL:String = "Base.xml";
    var myXMLURL:URLRequest = new URLRequest(XML_URL);
    var myLoader:URLLoader = new URLLoader(myXMLURL);
    myLoader.addEventListener("complete", xmlLoaded);
    function xmlLoaded(evtObj:Event):void {
    myData = XML(myLoader.data);
    var Result:XMLList = myData.art.(ID >= 1 && ID
    <= 3);
    for each (var art:XML in Result) {
    var sPropertyName:String = String(art.ref);
    var sValue:String = String(art.formula);
    MyDynamicObject[sPropertyName] = sValue;
    ]]>
    </mx:Script>
    <mx:Panel title="XML Extraction" width="100%"
    height="476">
    <mx:Label text="Ref AX51" fontWeight="bold"/>
    <mx:Text id="AX51" text="{MyDynamicObject['AX51']}"/>
    <mx:Label text="Ref AW42" fontWeight="bold"/>
    <mx:Text id="AW42" text="{MyDynamicObject['AW42']}"/>
    <mx:Label text="Ref AW43" fontWeight="bold"/>
    <mx:Text id="AW43" text="{MyDynamicObject['AW43']}"/>
    </mx:Panel>
    </mx:ApolloApplication>
    Thanks for your help.

  • Using Dynamic Variable Names

    I am hoping someone can help me out with this.
    I am creating my own record that has the format (id_1, title_1, id_2, title_2...id_50, title_50). I was wondering if there was a way that I could iteratively assign values to each attribute in this record without having to explicitly type out each assignment (partially because the number of columns will vary).
    Any help is greatly appreciated!
    Thx

    I did not think that there was a way to access the attributes within a record/object by using an offset or an index (i.e. set the 4th attribute of the record to 'XXX').
    Here might be a better example for my problem. Let's say the "object" is a car. The car can have 1 to N options associated with it (we'll use 3 for this example). Each option has an ID associated with it as well as text that describes that option. Each car should only have one record that describes all of it's options collectively.
    car_id Opt1_id Opt1_Text Opt2_id Opt2_Text Opt3_id Opt3_text
    'car1' 25 'CD Player' 41 'A/C' 11 '4X4'
    'car2' 25 'CD Player' 40 NULL 10 '2X4'
    So how can I build these records without having to directly assign each value as show below?
    car(1).car_id := 'car1';
    car(1).Opt1_id := 25;
    car(1).Opt1_Text := 'CD Player';
    car(1).Opt2_id = 41;
    car(1).Opt2_Text := 'A/C';
    car(1).Opt3_id := 11;
    car(1).Opt3_Text := '4X4';
    Desired solution:
    car(1).car_id := 'car1';
    For i IN 1..3
    LOOP
    car(1).Opt||i||_id := <some id>;
    car(1).Opt||i||_Text := <some text>;
    END LOOP;

Maybe you are looking for

  • Fax won't work

    Hi,       just had to replace my officejet pro 8600 less than 6mths old because it decided to not turn on, replaced it with  HP OFFICEJET PRO 8620 set itup as per instructions to a "T" fax was working fine for the first month now all of a sudden i ca

  • Ess career and age iview problem

    Hi I have implemented ess. and when executing career and age following error is coming Business Server Page (BSP) error What happened? Calling the BSP page was terminated due to an error. SAP Note The following error text was processed in the system:

  • Encore CC and CS6 sound problems

    I have tried Premiere Pro CC and CS6 with several different video's I upload on youtube. 1. video with external music downloaded 2 different songs. Render in Premiere stops working, then I make it through render but Encore just stands there. I go thr

  • No Power BI for Office 365 License???

    Hi, we have installed the free Power BI SharePoint App. We have assigned the free license to two users. It now says correctly that we have 999998 of 1000000 licenses left. So far, so good :-) But...when I click "Power BI" in the left navigation pane,

  • Getting rid of or changing music

    I am new to mac and would like to know how to either get rid of the background music while viewing photos in Front Row or at least changing it. I am sure it's an easy answer, but I have no clue. Thanks for any help.