Initialise the array length via a function

Dear forum,
II need a number of integers as an array, but I don't know how many in advance. An I need this array only in the scope, then do waya with it. So I used
#include <iostream>
using namespace::std;
const int f ();
int main () {
int array[f ()];
return 0;
const int f () {
return 42;
. It worked fine under gcc, but CC compains with
Error: An integer constant expression is required within th\
e array subscript operator.
Is there a switch which makes CC swallow this program?
Cheers, Peter.

You are posting this question in the C forum, but
your question is about the C++ compiler.Hello Clamage,
this I realised 1e-6 s after clicking submit. It shall not happen again. Anyway, thanks for the quick response!
>
In standard C++, the dimension of an array allocated
statically or in a block must be a constant integer
expression. Reference: C++ Standard, section 8.3.4.
If g++ allows a non-constant value, that would be
non-standard extension.... which are getting at you after a while...
>
You can get the effect by allocating the array on the
heap:
int* array = new int[f()];Indeed. But what made me make the array static is that with new[], you also have to delete[] (which one always forgets).
>
But in C++ you have alternatives to C-style arrays.
You can use the standard vector class template. It
manages memory for you, allows a vector to be
expanded, optionally checks subscripts for being in
range. When you create a vector, you can specify the
starting capacity when you know the sizeI should try this.
Once again, thanks for your patience!
Cheers, Peter.

Similar Messages

  • Splitting a string into separate values, but the array length is variable

    We are a cabinet manufacturer.  I'm trying to write a report to show the location of individual hinges on a door.  I have a string that will look something like these examples:
    60, 540
    60, 540, 956
    60, 540, 956, 1340
    It may have 2, 3, 4, or 5 locations.  (Don't think I've ever seen one over 5).
    So I have a formula that says:
    Split({Doors.HingeCenterLines},',')[1]
    This will return 60 - the first figure in my string.
    I need to have all of them separated, but the critical thing is the last measurement.  I need it to be the height of the door minus the last hinge location.  So for an example, if I have a 1400mm tall door, the 4th example string listed above would be generated.  I want my entries to look like this:
    60
    540
    956
    60
    My string always references the hinge relationship to the bottom of the door, but for the top hinge only, I need it to be based on the distance from the top of the door.
    Can anyone help with this?  Thanks in advance!

    Try this code please:
    whileprintingrecords;
    local stringvar array arr := Split({Doors.HingeCenterLines},',');
    local numbervar temp;
    local stringvar fin_string;
    local numbervar i;
    For i := 1 to ubound(arr) do
         If i = ubound(arr) then
              temp := {Door_height} - tonumber(arr[i]);
              fin_string := fin_string + totext(temp,0,"");
         else
              fin_string := fin_string + arr[i] + chr(13);
    fin_string;
    You can then right-click the field > Format Field > Common tab > Check the 'Can Grow' option.
    -Abhilash

  • Get Type ArrayElement  fails if array length is 0

    All:
    Get<Type>ArrayElement fails if the array length is 0 in 1.4. It seems to work fine in 1.5. I was "googling" and I found this link -- http://e-docs.bea.com/wljrockit/v315/relnotes/relnotes.htm. It mentions that this problem -- The JNI methods GetStringChars and Get<>ArrayElements threw OutOfMemoryError if called with a String or array of zero length -- was fixed in version 3.1.4. What is version 3.1.4 and how does this relate to JDK verions that I get out of java -version.
    I will appreciate any pointers.
    M.P. Ardhanareeswaran
    Oracle USA

    Drag and drop within a datagrid is rather an unusual thing to do.
    I would suggest your problem lies in choosing to do something which will cause complications.
    Hope that helps.
    Recent Technet articles: Property List Editing;
    Dynamic XAML

  • Pioneer 8400 DVD receiver player, as iPhone ios6 update now when connecting the new iPhone with ios6 via blutooth (firmware prob) to my car DVD 8400 unit, when playing music such as on my phone or Pandora the track button does not function or work at all

    pioneer 8400 DVD receiver player, as iPhone ios6 update now when connecting the new iPhone with ios6 to my car DVD 8400 unit, when playing music such as on my phone or Pandora the track button does not function or work at all not even if i press skip track forward or back on the unit it doesn't function everything works except that. on listening to radio or anything else related not pairing thru Bluetooth unit works fine, seems there to be Bluetooth update that is not making iPhone and unit not compatible at all. does pioneer need fix this problem with update firmware or thru apple need help. my iPhone was working fine before with previous ios 5 before.

    Dear Valued Pioneer Customer:
    We would like to inform you of the availability of an optional Bluetooth® firmware update (HW05-SW01.27.20) that enables Bluetooth AVRCP control and metadata display from a compatible Pioneer CD or DVD Receiver when used with an iPhone® 5 or iOS 6 device.  If you do not own an iPhone 5 or iOS 6 device, there is no need to install this update.
    This firmware update may be used only with the following 2012 Pioneer products:
    CD Receivers
    DVD Receivers
    DEH-P8400BH
    DEH-P9400BH
    DEH-80PRS
    AVH-P2400BT
    AVH-P3400BH
    AVH-P4400BH
    AVH-P8400BH
    In order to perform this update, the following items are needed:
    A Pioneer CD or DVD Receiver above with built-in Bluetooth
    Laptop with built-in Bluetooth running Windows® 7
    Bluetooth firmware update (HW05-SW01.27.20)
    How to Obtain the Free Firmware Update
    1. Download the INSTRUCTIONS for the optional Bluetooth firmware update (HW05_SW01.27.20).
    2. Download the UPDATE FILE to a computer and transfer the file to a compatible 2012 Pioneer CD or DVD Receiver via a Bluetooth-enabled Windows 7 laptop.
    You can also arrange for Pioneer to update your 2012 Pioneer CD or DVD Receiver by calling Pioneer Customer Service toll free at 800-421-1404 during regular business hours (M-F 10AM-7:30PM Eastern Time, except on holidays). If this firmware update is performed by Pioneer, there is a charge of $60.00 (this charge includes return shipping of the updated unit within the U.S.). Charges for removal/reinstallation of the unit and shipment to Pioneer are the customer’s responsibility.
    How to Determine if the Firware Update has Already been Installed
    CD Receivers:
    • With the unit turned off (press and hold the source button until the CD Receiver turns off), press and hold the center of the volume knob to bring up the Settings menu → rotate the volume knob until "BT Version Info" is displayed and then press the center of the volume knob → The firmware version should show HW05-SW01.27.20.
    DVD Receivers:
    • With the unit turned off (press the home button and select ‘OFF’ from the source icons), press the home button → Press the “System” icon at the bottom of the screen → Select the “Bluetooth Version Info” option → The firmware version should show HW05-SW01.27.20.
    If the Bluetooth firmware version shows HW05-SW01.27.20, no further action is necessary.
    Questions
    If you have any questions, please contact the Pioneer Customer Service Center toll free at 1-800-421-1404, Monday through Friday, 10:00 a.m. to 7:30 p.m. (Eastern Time), except on holidays.
    Sincerely,
    Pioneer Electronics (USA) Inc.

  • Using the Array SetElements function

    Hi All,
    I'm trying to use the Array SetElements function to set a value to specific indices within an initialized array but I cannot figure out what the syntax is for the optional parameter 2. I've tried a whole bunch that seem to make sense but always get an error. Has anyone used this function before who can let me know what the syntax to use is?
    Thanks,
    Nick
    Solved!
    Go to Solution.

    Nick,
    So the syntax for setting all of the elements to a value can simply be written:
    SetElements( myArray,valueToSet )
    To add in the optional parameter 2 and define a range is something like this:
    SetElements( myArray,valueToSet, "[3..6]" )
    The .. operator is analagous to a : in Matlab.
    Good luck,
    Chris

  • How can I perform the LINEST function using the new version of Numbers? The old method of using "command enter" to complete the array function does not work. Please help ASAP!!!

    LINEST function using Numbers for Mac

    Thank you for your help. This page is somewhat helpful, but I still don't quite understand.  I am using the Numbers program, and my assignment calls for me to use the LINEST function to return a set of 10 values. 
    When I googled how to do this, a lot of pages mentioned hitting "command+enter" to complete the array function, but they were using an older version of Numbers and it doesn't do anything when I try it in the new version.  I tried using "Index" with LINEST, and i've managed to get about 5 values out of it.

  • Whats the maximum length array and why?

    Whats the maximum length array and why?
    I tryed to search the forum but most people was wondering about the maximun length of a String..

    for(int i =20;i<=32;i++) {
         try {
              int[] p = new int[(int)Math.pow(2,i)];
              pause(2000); // So that gc doesn't clean away the array before
                              // The OS memory manager gets to update.
              System.out.println("Paused! i: " + i);
         } catch(OutOfMemoryError e) {
              System.out.println("Ex!!");
              pause(10000); // Same sa before.
    void pause(int p) {
         try {
              Thread.sleep(p);
         } catch (Exception e) {}
    }I worte this little code to test this.
    It runs to 2^23 for me.
    I am running
    AMD Athlon, 512 DDR, Windows 2000 SP4
    java version "1.5.0-beta2"
    Java was using 42116 Kb RAM and 54632 Kb Swap when its at 2^23

  • Changing the Registration point via AS3 . how?

    hello,
    is it posseple to change the Registration point via AS3 ?
    Best Regards,
    Crimson

    The Attach Code window isn't working for me on this so I
    pasted the code into the message. Hope the formatting remains
    reasonable.
    public class HomePage extends MovieClip {
    public var frenchieReal:Swimmer; //Swimmer extends
    MovieClip; contains image of French Angel
    public var frenchie:Sprite; //To offset regisration point of
    frenchieReal
    public function loadStage() {
    var timer:Timer;
    var wayPoints:Array;
    //Establish timer for swimmers
    timer = new Timer(100, 0);
    //Create new swimmer supplying: image path, width, heigth,
    and initial x and y location
    frenchieReal = new Swimmer("Photoshop/oceanswimmer.png", 57,
    41, -24, -28);
    frenchie = new Sprite();
    frenchie.x = 244;
    frenchie.y = 532;
    this.addChild(frenchie);
    frenchie.addChild(frenchieReal);
    frenchieReal.setTimerListener(timer);
    //Set waypoints for swimmers
    wayPoints = [[230, 530],
    [240, 520],
    [250, 500],
    [260, 480],
    [298, 480],
    [358, 540],
    [368, 544],
    [388, 520],
    [398, 495],
    [404, 475],
    [420, 500],
    [458, 545],
    [528, 550]];
    frenchieReal.setPath(wayPoints);
    package {
    import flash.display.MovieClip;
    import flash.events.*;
    import flash.utils.Timer;
    import flash.net.*;
    import flash.display.*;
    public class Swimmer extends MovieClip {
    private var path:Array;
    private var pathLength:uint;
    private var pathLocation:int;
    private var loader:Loader;
    private var intercept:int;
    public function Swimmer(imagePath:String, w:uint, h:uint,
    xx:uint, yy:uint) {
    var urlRequest:URLRequest;
    this.x = xx; //Transaltion offsets for image MovieClip (eg,
    -24 and -28)
    this.y = yy; //Image is visible if these two values are
    nonnegative
    this.loader = new Loader();
    this.addChild(this.loader);
    urlRequest = new URLRequest(imagePath);
    if (urlRequest != null) this.loader.load(urlRequest);
    //Sets an array of waypoints
    public function setPath(p:Array) {
    this.path = p;
    this.pathLength = p.length;
    this.pathLocation = 1;
    this.parent.x = this.path[0][0];
    this.parent.y = this.path[0][1];
    this.intercept = -this.parent.y;
    public function setTimerListener(t:Timer):void {
    t.addEventListener(TimerEvent.TIMER, timerListener);
    //this.parent in timerListener is the Sprite object to which
    image MovieClip is parented
    function timerListener(e:TimerEvent):void {
    var i:int;
    var iMinus1:int;
    var xx:int;
    var y1:int;
    var y2:int;
    var rise:int;
    var run:int;
    var rotationAngle:int;
    if (this.path != null) {
    //Move to next segment?
    if (this.parent.x >= this.path[this.pathLocation][0]) {
    this.pathLocation++;
    //Go back to first segment?
    if (this.pathLocation == this.pathLength) {
    this.pathLocation = 1;
    this.parent.x = this.path[0][0];
    this.parent.y = this.path[0][1];
    this.intercept = -this.parent.y; //Minus y to translate
    everything to lower quadrant
    //y = ax + b
    //y = ((path
    [1] - path[i-1][1]) / (path[0] - path[i-1][0])) * this.x +
    path[i-1][1]
    i = this.pathLocation;
    iMinus1 = i - 1;
    this.parent.x += 2;
    xx = this.parent.x - this.path[iMinus1][0];
    y1 = -this.path[iMinus1][1];
    y2 = -this.path
    [1];
    rise = y2 - y1;
    run = this.path[0] - this.path[iMinus1][0];
    this.parent.y = ((y2 - y1) / (this.path
    [0] - this.path[iMinus1][0])) * xx + intercept;
    this.parent.y = -this.parent.y;
    rotationAngle = -(180/Math.PI) * Math.atan2(rise, run);
    this.parent.rotation = rotationAngle;
    trace("rise = " + rise + " run = " + run + " rotationAngle =
    " + rotationAngle + " Intercept = " + this.intercept);
    trace("x = " + this.parent.x + " y = " + this.parent.y + "
    rotation = " + this.parent.rotation);

  • Nested IPE (In Place Element) usage when accessing Cluster/Array data via DVR

    I am sharing data across several VIs and loops via a DVR, and accessing the data via a DVR IPE. The data is a cluster of arrays. The diagram below (VI attached) illustrates the structures invloved, but not the structure of the application.
    (The diagram above does not include initialization of the arrays, as it is intended only to illustrate the Cluster1 data type. Array lengths could be 100.)
    The DVR (DVR1) is passed to multiple VIs of the application at startup.
    Each VI executes loops that either read or write particular elements of each array (fArray1 or fArray2).
    I believe the DVR IPE (B1-DVR) provides blocking so that only one task can modify the data (Cluster1) at any time.
    Case 1 illustrates how I currently WRITE to array elements. The outer IPE (block B1) is rolled into a VI (not shown) that takes DVR1, Index, and Value as inputs.
    Cases 2 - 4 illustrate 3 additional methods that remove one or both of the inner IPEs (B2-Cluster and B3-Array).
    Case 2: IPE B3 (Array Index/Replace Elements) is replaced with a non-IPE 'Replace Array Subset'.'
    Case 3: IPE B2 (Unbundle / Bundle Elemnts)' is replaced with a non-IPE cluster 'Unbundle'/'Bundle'.
    Case 4: removes both B2 and B3.
    I implemented case 1 a long time ago.  When I had to do the same thing again recently, I did case 4.  When I stumbled across my earlier implementation, I was a bit suprised
    Which of the 4 cases should take the least time (or resources) to execute? I think case 4 has as few array allocations as any of the other 3.
    The attached image did not capture the Buffer Allocation marks, so I marked the ones that differed with a red "B".
    I am only interested in differences in how the arrays are handled, so I see no signioficant differences.
    Is this one of those cases where LV doesn't need my help?
    Incidently, I recently wrote a small app with shared data and decided to try FGVs to share array data.  For small arrays, 10^7 iterations, and an FGV based array-element read followed by a element write, the FGV was faster.  1.2us per read/write for FGV vs 3us per r/w for an DVR/IPE based read/write (like above).
    Peter
    LV 2011 SP1, Windows 7 64-Bit
    Attachments:
    IPE.vi ‏9 KB

    Option 1 is a definite no and as far as I know it has been NI's explicit intention to steer clear from it. I believe there's an idea in the IE which asks for this.
    I agree that option 2 makes sense, but I don't think it should be something the user specifies. Either LV can detect it automatically or it can't, but I doubt NI would let you have an option which creates the possibility for this kind of bug.
    I'm not sure, but the mark as modifier option on the IPES might be the option you're looking for. I know that it exists and I know very roughly what it does, but the documentation for it is very limited and I never actually played around with it, as usually I don't need these kinds of optimizations.
    You may well be right that a new option on the IPES is desirable and you should probably add it to the idea exchange.
    As for NIWeek, I'm not going this year, so I have no idea what kinds of sessions are around, but it's a great place to find people who know what they're talking about and ask them about it directly. Certain people in LV R&D would probably be ideal for this and if you ask relevant people, you might even get their names. I'm sure buying them a beer would also help to loosen their tounges. If you ask me, this type of interaction is the main value of the conference, not the sessions themselves.
    Try to take over the world!

  • Get value from the array based on the HashCode

    public static void runJoin(int[][] t1,int[][] t2)
         PrintWriter out=null;
         int rows = 1000;
         int cols = 7;
         int [][] myTable3 = new int[rows][cols];
         int x = 0;
         System.out.print("Running HashJoin:Method loads the "+
         "smaller table in the memory and applies a hashing function "+
         "to common column and stores it in another table. "+
         "The larger table is then read from the file. "+
         "The same hashing function is applied to Col n of the table and a       matching record in the first table is looked up. A match will create a row in Table 3. ");          
    //Apply hashing function to smaller table and store it in the memory.
              Integer[] It2 = new Integer[t2.length];
              int [] hashCodest2 = new int[t2.length];
              Hashtable ht = new Hashtable();
              for(int i =0; i <t2.length;i++){
                   It2[i] = new Integer(t2[0]);
                   hashCodest2[i] = It2[i].hashCode();
                   ht.put(new Integer(hashCodest2[i]),It2[i]);
              //Larger table get hashcodes
              Integer It1[] = new Integer[t2.length];
              int [] hashCodest1 = new int[t2.length];          
              for(int j =0; j <t1.length;j++){
                   It1[j] = new Integer(t1[j][4]);
                   hashCodest1[j] = It1[j].hashCode();               }
              //Based on the hashcode get the value from the Table2;
              try{
    out = new PrintWriter( new FileOutputStream( "c:\\HashJoinTable.txt" ) );
              Enumeration e = ht.keys();
                   while(e.hasMoreElements())
    //How do I get the value from the array based on the HashCode? Do I need to do a loop here???                         
    hashCodes1.get(e.nextElement());           
              }catch(Exception e){}

    ok I got it......
              //Apply hashing function to smaller table and store it in the memory.
              Integer[] It2 = new Integer[t2.length];
              int [] hashCodest2 = new int[t2.length];
              Hashtable ht = new Hashtable();
              for(int i =0; i <t2.length;i++){
                   It2[i] = new Integer(t2[0]);
                   hashCodest2[i] = It2[i].hashCode();
                   ht.put(new Integer(hashCodest2[i]),It2[i]);
              //Larger table get hashcodes and compare
              Integer It1[] = new Integer[t2.length];
              int [] hashCodest1 = new int[t2.length];          
              Hashtable ht2 = new Hashtable();
              for(int j =0; j <t1.length;j++){
                   It1[j] = new Integer(t1[j][4]);
                   hashCodest1[j] = It1[j].hashCode();               
                   ht2.put(new Integer(hashCodest1[j]),It1[j]);
              //Based on the hashcode get the value from the Table2;
              try{
    out = new PrintWriter( new FileOutputStream( "c:\\HashJoinTable.txt" ) );
              Enumeration e = ht.keys();
              Integer t3[] = new Integer[t2.length];
                   while(e.hasMoreElements())
                        t3[x] = (Integer) ht2.get(e.nextElement());                
                        x++;
              }catch(Exception e){}

  • How to update a chart when the array is updated

    Hi I am using an array to populate a chart in FB3 and having trouble updating the chart when the array is updated.
    Chart
             <mx:Label id="archiveTitle" x="10" y="10" text="Current Archive " fontSize="14" fontWeight="bold"/>
             <mx:PieChart id="chart" height="130" width="300" color="0x323232"
                showDataTips="false" dataProvider="{ratingAC}"  y="22">
                 <mx:series>
                    <mx:PieSeries field="Rating"/>
                </mx:series>
            </mx:PieChart>
    Array + Vars
             [Bindable]
             public var newsDB:ArrayCollection = mx.core.Application.application.newsDB as ArrayCollection;
             [Bindable]
             private var positive:int = 1;
             [Bindable]
             private var neutral:int = 0;
             [Bindable]
             private var negative:int = 0;
             [Bindable]
             private var ratingAC:ArrayCollection = new ArrayCollection([
             { Rating: 1 },  // no data
             { Rating: positive }, // [0] positive
             { Rating: neutral }, // [1] neutral
             { Rating: negative }  // [2] negative
            private function init():void{
                   buildChart();
                   newsDB.addEventListener(CollectionEvent.COLLECTION_CHANGE, test);
                   newsDB.addEventListener(CollectionEvent.COLLECTION_CHANGE, buildChart);
            private function test(e:CollectionEvent):void{
                 trace("array changed");
                 positive = 20
            private function buildChart(e:CollectionEvent=null):void{
                 for(var i:int; i<newsDB.length; i++){
                      if(newsDB[i].rateItem == 0){
                           trace(positive);
                           positive += 1;
                           //ratingAC.setItemAt(positive,0);
                           trace(positive);
                      if(newsDB[i].rateItem == 1){
                           neutral += 1;
                      if(newsDB[i].rateItem == 2){
                           negative += 1;

    Sorry, in my app I have an ArrayCollection of items from a news feed that the user has deemed important, and given each item a rating. The For loop will loop through the "newsDB" array and set the var accordingly (positive, negative, neutral). The variables are what is populating the arrayCollection (ratingAC). How would I either a) bind the variables to the ArrayCollection so that it updates when one has changed, or b) update the specific index in the array collection. When debugging, i notice that the variables are updating, but the arrayCollection is not.
    Thanks in advance!

  • Question on array.Length

    I have an array[4]. Then the subscripts are number 0, 1, 2, 3. Does array.Length return 4 or 3. I am thinking 4 but I want to make sure.

    java.secure(?).SecureRandom.java.security.SecureRandom
    It's more straightforward and has better statistical properties.While I agree, with the straightforward,
    but statistical I would of thought they'd
    be even.It's better for several reasons:
    1) nextInt is faster. It uses (on average) 1-1/3 calls to next(int), whereas nextDouble() (what Math.random() uses) always uses two. This also means nextInt will use up the generator's period more slowly.
    2) It's statistically better. Although the odds of you noticing that some numbers are favored (slightly) over the "noise" of the prng's own bias are negligible.
    3) It's nicer to use nextInt. It uses OO (instead of the relatively global function call to Math.random()), it doesn't compete with other parts of the Application for using up some of the prng's period, it allows the substitution of other (better or worse) algorithms with fewer changes, and it looks better.
    ~Cheers

  • Finding Array Length

    I was just wondering if i have an array
    double [][][] array = new double [1][2][3];array.length only gives 1, what function can i use to find the size of the other dimensions (2 and 3)? Thanks in advance for any help.

    I'll try and explain this a little better.
    Say array[0].length is 2, then that means that there is only
    array[0][0] and array[0][1].
    If array[0][0] is 4, then that means that there is only
    array[0][0][0], array[0][0][1], array[0][0][2], and array[0][0][3].
    The reason i did array[0][0].length and not array[0][1].length
    in my other post is because they would both return the same
    thing because of the way you declared the array.
    When you dodouble[][] array = new double[2][3];this is making it so that array[0].length is 3 and array[1].length is 3.
    But if you do this (shown in the previous post)
    double[][] aray = {
        { 2.4, 5.6, 6.4 },
        { 1.4 }
    }then array[0].length is 3, but array[1].length is 1.
    Hope this helps.

  • How come the output of the Array Subset VI is 2-D when I specify a 1-D subset?

    1. I'm trying to strip off a row from a 2-D array so I can search for a match within that row. When I use Array Subset and specify one row as the subset (for example, Row Index=0, Row Length=1, Column Index=0, Column Length=(a variable, typically 255), the output is a 2-D array.
    2. Do I have to use Reshape Array on the output of Array Subset to get the desired 1-D array? The help popup says I have have to add m dimension sizes to have the output be an m-dimensional array. If I add a dimension size, I get a 2-D output. If I fall back to one dimension size and hardwire it to '1', I get a 1-D array wire type but apparently the array doesn't contain all the data in the row from the original 2-D array.
    I'm using LV 5.1. What is the easiest way to strip off a row from a 2-D array in LV 5.1?
    I appreciate any help you can provide.
    Thanks,
    Jeff Bledsoe
    Jeffrey Bledsoe
    Electrical Engineer

    JeffreyP wrote:
    What is the easiest way to strip off a row from a 2-D array in LV 5.1?
    The easiest way to has always been just to use the "Index Array" function, choosing the indice of the row you wanted and with nothing wired to the column terminal (the lower one).
    Edit: I'm assuming that by "strip off" you mean "access", not "strip out"/"remove".Message Edited by Donald on 05-13-2005 02:03 PM
    =====================================================
    Fading out. " ... J. Arthur Rank on gong."
    Attachments:
    Index Out Row.jpg ‏6 KB

  • Forwarding the array of object to servlet class

    Hi
    i am new to this j2ee.So please cooperate with me.
    i am having an array of objects in a jsp page.
    Each object represent a option which could be seelected through radio button.
    Now i want to send one selected object,corresponding to selected radio button to my servlet ManageUser.
    how can i do that.can any one help me please.
    i have been trying like this but i guess it is not correct .
    <%--   
    --%>   
    <%@page contentType="text/html" pageEncoding="UTF-8"%>    
    <%@page import="abc.javabean.EmpJavaBean"%>  
    <!--importing pages(classes) to implement request response  -->  
    <%@page import="javax.servlet.ServletException"%>  
    <%@page import="javax.servlet.http.HttpServlet"%>  
    <%@page import="javax.servlet.http.*"%>  
    <%@page import="javax.servlet.RequestDispatcher"%>  
    <%@page import="java.util.*"%>  
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
       "http://www.w3.org/TR/html4/loose.dtd">    
    <html>  
        <head>  
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
            <title>JSP Page</title>  
            <script type="text/javascript">  
                //function for selecting the radio  
                function validateRadio(fetchedArrayObject)  
                    alert("hi");  
                    var thisone=-1;  
                    for(i=0;i<document.searchedEmpForm.radioGroup.length;i++)  
                            if(searchedEmpForm.radioGroup.checked==true)
    thisone=i;
    alert(thisone);
    var name=fetchedArrayObject[i].getEmpName();
    alert(name);
    session.setAttribute("fetchedArrayObject[i]",fetchedArrayObject[i]);
    if(thisone==-1)
    alert("you must select a radio Button");
    return false;
    return true;
    </script>
    </head>
    <body bgcolor="#8db6cd">
    <!--retreaving the array values from the servlet -->
    <%
    //int a;
    EmpJavaBean fetchedArrayObject[]=new EmpJavaBean[4];
    fetchedArrayObject=(EmpJavaBean[])request.getAttribute("substituteArray");
    //a=fetchedArrayObject[0].getEmpNumber();
    %>
    <h3>ur new no is <%=fetchedArrayObject[0].getEmpNumber()%></h3><br>
    <form name="searchedEmpForm" action="/Precize/ManageUser" onsubmit="return validateRadio(fetchedArrayObject)">
    <br></br>
    <h2 align="center">Your Searched Result Is Here</h2>
    <br></br>
    <table border="1" align="center">
    <thead>
    <tr>
    <th> </th>
    <th> <input type="button" value="Emp#" name="searchedPageEmpNumb"> </th>
    <th> <input type="button" value="Name" name="searchedPageEmpName"> </th>
    <th> <input type="button" value="Priv" name="searchedPageEmpPriv"> </th>
    <th> <input type="button" value="Role" name="searchedPageEmpRole"> </th>
    <th> <input type="button" value="Start Date" name="searchedPageEmpStartDate"> </th>
    <th> <input type="button" value="End Date" name="searchedPageEmpEndDate"> </th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td><input type="radio" name="radioGroup" value="r11" ></td>
    <td><%=fetchedArrayObject[0].getEmpNumber()%></td>
    <td><%=fetchedArrayObject[0].getEmpName()%></td>
    <td><%=fetchedArrayObject[0].getEmpPrivilege() %></td>
    <td><%=fetchedArrayObject[0].getEmpRole()%></td>
    <td><%=fetchedArrayObject[0].getEmpStartdate()%></td>
    <td><%=fetchedArrayObject[0].getEmpEndDate() %></td>
    </tr>
    </tbody>
    </table>
    <br><center><input type="submit" value="Update" name="updateButton" ></center>
    <h3 align="center">Select the Employee To be Updated/deleted</h3>
    </form>
    </body>
    </html>
    please suggest me the answer.
    regards
    thanx                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    I think you need to learn the difference between "java" and "javascript"
    calling session.setAttribute from a javascript function will not have the effect that you desire.
    If you give all radio buttons the same "name", then request.getParameter("radioGroup") should tell you the value of the selected one.

Maybe you are looking for