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.

Similar Messages

  • 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

  • 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

  • How do I create a variable name on the fly?

    Hi,
    If I have a String containing a value, how do I create a variable name using that value during program execution? That is if I have
    String fred = "newvar";
    How do I then create a new String with the name "newvar" (using the contents of fred)? I will never know what the content of fred is until this point. What I'd like to be able to do is something like
    String fred.subString(0) = "a new value";
    Obviously this won't work but if it did the statement would evaluate to something like
    String newvar = "a new value";
    Appreciate any help you can give,
    Dave.

    Here u go:
       private JCheckBox AddCheckBox( String strText, int nTextID )
          JCheckBox checkbox = null;
          Class checkboxDefinition;
          Class[] stringArgsClass = new Class[] {String.class};
          Constructor stringArgsConstructor;
          Object[] stringArgs = null;
          String arg = "";
          arg = "CheckBox" + nTextID;
          String label = new String(arg);
          stringArgs = new Object[] {label};
          try
            checkboxDefinition = Class.forName("javax.swing.JCheckBox");
            stringArgsConstructor = checkboxDefinition.getConstructor(stringArgsClass);
            checkbox = (JCheckBox) createObject(stringArgsConstructor, stringArgs);
            checkbox.setName(label);
            checkbox.setText(strText);
            checkbox.setSize(new java.awt.Dimension(CQuestionBase.PAGEWIDTH, 21));
            checkbox.putClientProperty("1",new Integer(nTextID));
            checkbox.setVisible(true);
          catch (ClassNotFoundException e)
            System.out.println(e);
          catch (NoSuchMethodException e)
            System.out.println(e);
          return checkbox;
       }This code was based on an example I found about two years ago. You can use the same methodolgy to create objects of any kind. Again, look at java.lang.Reflect.

  • 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

  • How to create dynamic variable in HANA

    Hello experts,
    Please help me on how to create dynamic variable in calculation view.
    Ex:  variable automatically should take YTD, or MTD values so that I can directly consume column in BW on hana or BO reporting.

    Hi ,
    Not sure on what are looking for. Have a look on the below blog once, if this is what you are looking out for:
    Applying YTD in SAP HANA with SAP BO Analysis Office
    Regards,
    Krishna Tangudu

  • 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!

  • 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!

  • Create dynamic field names

    I'm creating a PDF form using iText which takes information from a webpage which has multiple order entries. On my PDF i need to loop through this list and create individual PdfFormFields. The problem is I do not know how many items are ordered. How can I create different form fields?
    i.e.
    for(int i=0; i<orderVector.size(); i++) {
    PdfFormField qty = text.getTextField();
    // each time it loops i need qty to be a different name like qty1, qty2....
    // how do I accomplish this?
    Thanks for you help.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    How can I create different form fields?You can't dynamically set variable names. But the good news is that you don't
    have to.PdfFormField[] qtyArr = new PdfFormField[orderVector.size()];
    for(int i = 0; i < orderVector.size(); i++) {
        qtyArr[i] = text.getTextField();
    }This creates just the right number of form fields, referred to as qtyArr[0], qtyArr[1], etc.
    Is there some reason why you are using Vector and not ArrayList?

  • 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.

  • Create dynamic directory name from form field on Sharepoint

    Trying to save pdf file to sharepoint site using URL; but need to create directory (initially) and filename dynamically. After directory created addtn'l files may populate dir, so need to check for directory exists; if so just copy files to dir based on field name. I'm able to save files to hard-coded location only, based on below.
    How to check and/or create dynamic directory base don field name?
    // folder level JavaScript to allow access to the identity object properties
    trustedIdentity = app.trustedFunction( function (sProperty)
    var iProperty = "";
    app.beginPriv();
    iProperty = identity[sProperty];
    app.endPriv();
    return iProperty;
    // folder level JavaScript to allow Save As population of file name
    mySaveAs = app.trustPropagatorFunction(function(myForm, path)
         app.beginPriv();
         var myForm = event.target;
         return rtn = myForm.saveAs(path);
         app.endPriv();
    myTrustFunct = app.trustedFunction(function(myForm, path)
         app.beginPriv();
         var vTest1 = event.target.xfa.resolveNode("topmostSubform[0].Page1[0].Test1[0]").rawValue.toString();
         var vTest2 = event.target.xfa.resolveNode("topmostSubform[0].Page1[0].Test2[0]").rawValue.toString();
         var vTest3 = event.target.xfa.resolveNode("topmostSubform[0].Page1[0].Test3[0]").rawValue.toString();
         var vTest4 = event.target.xfa.resolveNode("topmostSubform[0].Page1[0].Test4[0]").rawValue.toString();         
         var vpdf_url=location.href;location.href='http://mysite2010.com/documents
         var vPath = "/vpdf_url/" + vTest1 + Test2  + vTest3 + " .pdf";
              //console.println("vPath: " + vPath);
         var retn = mySaveAs(myForm, vPath);
         app.endPriv();
         return retn;

    Acrobat/Reader cannot create a directory. The directory needs to exist before Acrobat/Reader can save a PDF file to that directory.
    You could create a plug-in and use that plug-in to create the directory. The plug-in should also be able to determine if the directory exists or not.
    SharePoint can be tricky because it is not like most web sites. There is a special dash board that helps manage the different parts of SharePoint like list, folders, web parts, documents, etc so you may need to be aware of these features and adjust for them.
    For  folder level functions, I would not use any LiveCycle JavaScript variations. The folder level scripts are shared and accessible by Acrobat forms.

  • How to create dynamic variable in Java?

    Hi,
    I want to create dynamic varible , using ArrayList or Vector. The number of array i dont knwo, so how to create dynamic ArrayList or Vector.
    for example:
    ArrayList1,ArrayList2,ArrayList3.....n
    or
    Vector1,Vector2,Vector3 .....n, the n value i will get at run time, so how to create the dynamic ArrayList or Vector or i can use any other Object in java,
    Pls provide your input.
    Sridhar

    1. I have a HashMap with dataok ... fair enough.
    2. depending on its size, i need to create variable
    to store them.uhm ... why? If you have a variable number of elements in the map then you'd need to generate a variable number of variables (a number, that is not know at compile time, as it seems). Now if you could somehow create those variables, how would you access them? You'd have to generate the code handling them as well ...
    Tell us what kind of data you've got and what you want to do with it. There's certainly a better solution to your problem.
    how to generate variables as per content size of the
    HashMapYou don't.

  • 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.

  • How to create dynamic variables with SSRS report ?

    Hi everyone,
    I want to create one dynamic SSRS report which  can show details when user input data into textbox . Example : Users will input app_id then report will show details of each this id ( name, phone,salary...) .
    Pls help me solve it .
    Many thanks,
    Hong

    Follow below step.
    1. First create a dataset. The select statement or result set must contain (App_id, name, phone,salary...).
    2. Add a report parameter "App ID" with default setting.
    3. Drag dataset fields to a table or tablix. Select the tablix properties. Go to Filter section.
    4. Select the expression as Field App ID, Operator as "=" and Value as Parameter App ID.
    Regards, RSingh

Maybe you are looking for

  • Purchase Info Record - Creation

    Hi, I want to create a Purchase Info Record. I came to know that, the following FM's are used for creating a Purchase Info Record. ME_INITIALIZE_INFORECORD ME_DIRECT_INPUT_INFORECORD ME_POST_INFORECORD The following are my questions.... Is there any

  • Interface required to post invoice in EBP system in SRM4.0

    We are using classic scenario in SRM 4.0 with non-sap backend system. We are in process to develop a interface , which can post invoice automatically in EBP system after getting data from non- sap backend system.  Could anyone please answer the follo

  • Modify page margins and cell size (Single Image/Contact Sheet layouts)

    This question was posted in response to the following article: http://help.adobe.com/en_US/lightroom/using/WS2B066516-C3B2-457b-B8DA-84F0E64A066B.html

  • Error in SM21 - Help

    Hi, I'm new to the forum. Can you help me understand how to go about troubleshooting this error in the system log (SM21). There are multiple entries with the same message. If you can let us know what steps we need to take to analyze the problem furth

  • Mounting parition issues

    Hi all, Issue#1: Every time I try to mount my windows partition in thunar i get "Failed to mount  "New partition" Not authorized to perform operation." I have udisks,udisk2,gvfs, gvfs-ac, polkit-gnome.  What am I missing here ? If i add the entry to