Sorting rows creates formula errors

I have a simple Numbers 09 table to track money into and out of my Bank account and to show the balance. Data is entered as below:
Column A is date of entry
Row A1, A2 etc are the relevent dates of entry.
Col B is Cash In, Col C is cash out and Col D shows the balance.
For example D24 =D23+(B24-C24) i.e previous balance(cell D23) +cash in (B24)-cash out(C24) on date A24.
This works fine if the entries are built up progressively as time passes.
However, if with hindsight I need to change the date of an existing entry, when I re-sort column A by (using the arrow on the top of Col A to "Sort Ascending") the table re-sorts OK but the formula in Col D of the row that has moved is now incorrect. Instead of relating to the new "balance" cell in col D immediately above it in its new position, it clings on to the cell ref in D which it had before it was moved.
I then have to copy the formula down from the D cell above it to get the correct cell ref into place and then copy that cell one down to ensure that all Col D values are correct.
Excel didn't work like this.
All cells in my formula are "Relative" and none are "Absolute"
If anyone knows how to avoid this frustration I'd be truly grateful.

Venetian Seeker wrote:
Excel didn't work like this.
VS,
Yes, Excel works like this too, if you sort the entire table. You may not have recognized it, but it does. If you sort only one column, something you can do in Excel but not in Numbers, you may not get an error, but you have certainly done some serious mashing of your data.
Whenever you sort, or otherwise move things around in a table, Numbers and Excel track the movements and adjust the formulas. This is normally what you would want.
In the rare case when you want to reference a particular cell, regardless if that cell's content is relocated, you should use an addressing method that resists the effects of sorting and moving. That would normally involve the INDIRECT and ADDRESS functions. A running balance calculation is one of those rare cases.
Using your example "D24 =D23+(B24-C24) i.e previous balance(cell D23) +cash in (B24)-cash out(C24) on date A24", we can instead write the following:
D24 =INDIRECT(ADDRESS(ROW()-1, COLUMN())) +B-C
You can use this same formula in your entire column D.
Regards,
Jerry

Similar Messages

  • MS Query...cannot write sorted rows error

    I have an MS Query report crated and it was working well until i tried to remove a Criteria Filter within the query. I get an error "Cannot Write Sorted Row". If I acknowledge the error, the change to the criteria is not saved and it reverts to
    the original setting. I had several columns sorted, of which i deleted the SQL code for sort thinking that may help. I also tried to delete the Criteria Filter via the wizard and directly in SQL but that did not help.
    Any suggestions of what may be the issue?

    This is a Power Query forum and so it's unlikely you'll find MS Query experts here. That being said, did you try using Power Query for your scenario?

  • Error in creating Formula Variable

    Hi All:
    I'm having problems in creating formula variable. Trying to create FV on a characteristic using replacement path with attribute value , but the wierd part is it's not giving me any attributes it's just blank. Any help would be appreciated....
    Thanks,
    Manasa.

    Right click on the FM, create -> Characteristic -> attribute value -> but the attribute are not showing up.  This happens if the attribute is of key figure type. I was able to do this in another system (ASIA DEV) but now trying in Europe Dev.

  • SSRS 2008 Column Chart with Calculated Series (moving average) "formula error - there are not enough data points for the period" error

    I have a simple column chart grouping on 1 value on the category axis.  For simplicity's sake, we are plotting $ amounts grouping by Month on the category axis.  I right click on the data series and choose "Add calculated series...".  I choose moving average.  I want to move the average over at least 2 periods.
    When I run the report, I get the error "Formula error - there are not enough data points for the period".  The way the report is, I never have a guaranteed number of categories (there could be one or there could be 5).  When there is 2 or more, the chart renders fine, however, when there is only 1 value, instead of suppressing the moving average line, I get that error and the chart shows nothing.
    I don't think this is entirely acceptable for our end users.  At a minimum, I would think the moving average line would be suppressed instead of hiding the entire chart.  Does anyone know of any workarounds or do I have to enter another ms. connect bug/design consideration.
    Thank you,
    Dan

    I was having the same error while trying to plot a moving average across 7 days. The work around I found was rather simple.
    If you right click your report in the solution explorer and select "View Code" it will give you the underlying XML of the report. Find the entry for the value of your calculated series and enter a formula to dynamically create your periods.
    <ChartFormulaParameter Name="Period">
                      <Value>=IIf(Count(Fields!Calls.Value) >= 7 ,7, (Count(Fields!Calls.Value)))</Value>
    </ChartFormulaParameter>
    What I'm doing here is getting the row count of records returned in the chart. If the returned rows are greater than or equal to 7 (The amount of days I want the average) it will set the points to 7. If not, it will set the number to the amount of returned rows. So far this has worked great. I'm probably going to add more code to handle no records returned although in my case that shouldn't happen but, you never know.
    A side note:
    If you open the calculated series properties in the designer, you will notice the number of periods is set to "0". If you change this it will overwrite your custom formula in the XML.

  • File sent but no rows created in RFC

    File - RFC
    I can see no errors in the MM,
    no errors in receiver adapter
    receiver side CC is showing Green
    the file is sent succesfully but I dont see any rows created in my RFC
    help !!!!!
    regards,
    Nikhil.

    do u mean to say that you have no errors in the both the sender and receiver channels in CC monitoring?
    checked by executing the code directly. does it create the rows?
    have you done the content conversion on the sender side? if not:
    this can help u:
    http://help.sap.com/saphelp_nw04/helpdata/en/ae/d03341771b4c0de10000000a1550b0/frameset.htm

  • Getting "Unexpected end of formula" error in user-defined function

    I created a user-defined function and registered it successfully in Discoverer Admin (10g), and it shows up in Discoverer Plus. However, when I call the function, I get this error:
    "Error in formula -- unexpected end of formula"
    If I hard-code in parameters, I can successfully run the function as such from Oracle SQL Developer:
    SELECT PAYLINETOT('2324', '111', to_date('01-Sep-2010'), to_date('31-Oct-2010'))
    FROM DUAL;
    But I still get the same error if I enter this in the calculation dialog in Discoverer:
    PAYLINETOT('2324', '111', to_date('01-Sep-2010'), to_date('31-Oct-2010'))
    Any idea what's going on and how to get this to work?

    Michael,
    I tried your suggestion, and this time I got a different error message that said that the function had not been registered with the EUL. I thought I had registered it, but when I checked, the return data type was wrong. I corrected it, and the function is "valid" in Discoverer Admin. Yet, when I go back to Discoverer Plus and attempt to use the function (and yes, I logged out and logged back in), I get the same error message:
    "Error in formula - unexpected end of formula - Error: Function PAYLINETOT has not been registered with the EUL."
    Any idea where the disconnect is? Are these two separate errors? How could Discoverer Admin tell me that the function is registered and Discoverer Plus tell me otherwise? And yes, I've made sure that the "Available in Desktop/Plus" checkbox is checked.

  • Sort rows by fill color?

    Is it possible in Numbers to sort rows based on the row fill color? There are only 2 colors the rows have as background (fill), and it would save time to sort based on the highlighted row. Any ideas?
    Thank you-

    I agree with jerrold.
    I will certainly not ask Apple for such a feature.
    Here is a script which may give you an efficient response.
    property columnOffset : 2
    tell application "Numbers"
    activate
    set {rName, tName, sName, dName} to my getSelection()
    if (character 2 of rName) as text > "9" then
    set columnLetter to text 1 thru 2 of rName
    else
    set columnLetter to character 1 of rName
    end if
    set twoNames to my decoupe(rName, ":")
    set {colNum1, rowNum1} to my decipher(item 1 of twoNames)
    set columnToSort to colNum1 + columnOffset
    tell document dName to tell sheet sName to tell table tName
    set myColor to background color of (get properties of range rName)
    set nbRows to count rows
    repeat with r from 1 to 14 --nbRows
    set val to background color of (get properties of range (columnLetter & r & ":" & columnLetter & r))
    set val to (val is myColor)
    set value of cell r of column columnToSort to val
    end repeat
    end tell
    end tell
    --=====
    on getSelection()
    local mySelectedRanges, sheetRanges, thisRange, _, myRange, myTable, mySheet, myDoc, mySelection
    tell application "Numbers"
    activate
    tell document 1
    set mySelectedRanges to selection range of every table of every sheet
    repeat with sheetRanges in mySelectedRanges
    repeat with thisRange in sheetRanges
    if contents of thisRange is not missing value then
    try
    --return thisRange --poorly formed result
    thisRange as text
    on error errMsg number errNum
    set {_, myRange, _, myTable, _, mySheet, _, myDoc} to my decoupe(errMsg, quote)
    --set mySelection to (a reference to (range rn of table tn of sheet sn))
    return {myRange, myTable, mySheet, myDoc}
    end try
    end if -- contents…
    end repeat -- thisRange
    end repeat -- sheetRanges
    end tell -- document 1
    end tell -- application
    return {missing value, missing value, missing value, missing value}
    end getSelection
    --=====
    on decipher(n)
    local letters, colNum, rowNum
    set letters to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    if (character 2 of n) as text > "9" then
    set colNum to (offset of (character 1 of n) in letters) * 64 + (offset of (character 2 of n) in letters)
    set rowNum to (text 3 thru -1 of n) as integer
    else
    set colNum to offset of (character 1 of n) in letters
    set rowNum to (text 2 thru -1 of n) as integer
    end if
    return {colNum, rowNum}
    end decipher
    --=====
    on decoupe(t, d)
    local l
    set AppleScript's text item delimiters to d
    set l to text items of t
    set AppleScript's text item delimiters to ""
    return l
    end decoupe
    --=====
    Select a cell with the color to use in the sort.
    Run the script.
    It will fill the column whose offset from the selected one is defined by the property 'columnOffset'
    If the background of the cell in the source column is the searched one the value will be 1
    if the background is not this one, the value will be 0.
    So it will be easy to use a condition.
    Yvan KOENIG (from FRANCE mardi 10 mars 2009 20:39:44)

  • Creating Formula colums

    Hi All,
    I want to create formula column in apex as in Oracle Forms.
    I would like to know how (which properties to be set or processes or any thing else) to use the formula and where.
    For example:
    Suppose I have two Text Items: As soon as value is entered in either of the two columns its sum should be displayed in a third Display only text Item.
    Hoping for a quick response.
    Thanks in Advance.
    Arif Khadas

    Thanks for your replies andy.
    Run the page and do View, Source from the menu (View, Page Source in FireFox). Search for id="P264_SAL", then id="P264_COMM" and then id="P264_TOTAL". I have found all this in the source code. I am copying it and making it bold for your reference. Is there any problem with it.
    <td colspan="1" rowspan="1" align="left"><input type="hidden" name="p_arg_names" value="6233313766736725" /><input type="text" name="p_t11" size="30" maxlength="2000" value="" id="P264_SAL" onChange="javascript:calculateTotal();" /></td></tr><tr><td nowrap="nowrap" align="right"><label for="P264_COMM"><a class="t13OptionalLabelwithHelp" href="javascript:popupFieldHelp('6234124848739895','4050738722309497','')" tabindex="999">Comm</a></label></td>
    <td colspan="1" rowspan="1" align="left"><input type="hidden" name="p_arg_names" value="6234124848739895" /><input type="text" name="p_t12" size="30" maxlength="2000" value="" *id="P264_COMM"* onChange="javascript:calculateTotal();" /></td></tr><tr><td nowrap="nowrap" align="right"><label for="P264_TOTAL"><a class="t13OptionalLabelwithHelp" href="javascript:popupFieldHelp('6234901084742553','4050738722309497','')" tabindex="999">Total</a></label></td>
    <td colspan="1" rowspan="1" align="left"><input type="hidden" name="p_arg_names" value="6234901084742553" /><input type="text" name="p_t13" size="30" maxlength="2000" value="" *id="P264_TOTAL"* /></td></tr>
    Also following are the initial part of the source where there is error on Line 17 char 2.
    <html lang="en-us" xmlns="http://www.w3.org/1999/xhtml" xmlns:htmldb="http://htmldb.oracle.com">
    <head>
    <script src="/i/javascript/htmldb_html_elements.js" type="text/javascript"></script>
    <script src="/i/javascript/htmldb_get.js" type="text/javascript"></script>
    <script type="text/javascript">
    <!--
    /*Global JS Variables*/
    var htmldb_Img_Dir = "/i/";
    //-->
    </script>
    <link rel="stylesheet" href="/i/css/core_V22.css" type="text/css" />
    <!--[if IE]><link rel="stylesheet" href="/i/css/core_ie_V22.css" type="text/css" /><![endif]-->
    <script type="text/javascript">
    function calculateTotal()
    var v1 = $v('P264_SAL');
    var v2 = $v('P264_COMM');
    $x('P264_TOTAL').value = parseFloat('0' + v1) + parseFloat('0' + v2);
    </script>
    Thanks once again.

  • 'sort key too long error' while trying to use dynamic sql

    Hi All,
    I have been trying to generate an interactive report using a dynamically generated SQL query.. for this I have
    1) Created a application process that returns the dynamically generated SELECT statement
    2) Create a process in the page which creates a collection based on the SELECT statement returned by the application process
    3) An interactive report that selects ALL (SELECT * ....) from that particular collection.
    On implementing I am getting the 'ORA-01467: sort key too long' error.
    On checking this out online I realized that one has to change the Block size of the database to get past this error, but in order to do that I would have to re-create the database, create a backup of the data and then re enter them into the new database which would be a nightmare.
    I would like to know if there is any work around to this....
    CODE IN THE APPLICATION PROCESS
    DECLARE
    q VARCHAR2(1000);
    BEGIN
    IF :P124_COUNTRY - :P124_WORK_GROUP - :P124_PRODUCT - :P124_ROLE = 1 THEN
    q:= 'SELECT VISA_COUNTRY AS "Country", ROUND(((COUNT(VISA_ID)/(SELECT COUNT(ROW_ID) FROM PSA_RESOURCE_MANAGER WHERE ACTIVE_FLAG = ''Y''))*100),2) || ''%'' AS "Travel Readiness %" FROM PSA_VISA_INFO WHERE ACTIVE_FLAG = ''Y'' AND VISA_ACTIVE_FLAG = ''Y'' GROUP BY VISA_COUNTRY';
    END IF;
    return q;
    END;
    CODE IN THE PROCESS THAT CREATES THE COLLECTION:
    APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY_B(
    p_collection_name => 'TRAVRED_TEST',
    p_query => 'application_process=set_query' );
    CODE IN THE INTERACTIVE REPORT:
    Select *
    From apex_collections
    Where collection_name = 'TRAVRED_TEST';
    I also tried selecting just 'c001, c002' etc which gave me a 'no data found' output. The query work fine when I ran it in the SQL Workshop
    Please help!
    Thanks in advance :)

    Hey Ben,
    I am getting the same error when I used the following code in the app process....
    DECLARE
    q VARCHAR2(32767);
    BEGIN
    IF :P124_COUNTRY - :P124_WORK_GROUP - :P124_PRODUCT - :P124_ROLE = 1 THEN
    q:= 'SELECT visa_country,
    COUNT(visa_id) visa_count
    FROM psa_visa_info
    WHERE active_flag = 'Y'
    AND visa_active_flag = 'Y'
    GROUP BY visa_country),
    row_id_count AS
    (SELECT /*+ MATERIALIZE */
    COUNT(ROW_ID) row_count
    FROM PSA_RESOURCE_MANAGER
    WHERE ACTIVE_FLAG = 'Y')
    SELECT visa_country,
    ROUND(visa_count/(SELECT row_count FROM row_id_count)*100,2) travel_readiness FROM PSA_VISA_INFO WHERE ACTIVE_FLAG = ''Y'' AND VISA_ACTIVE_FLAG = ''Y'' GROUP BY VISA_COUNTRY';
    END IF;
    return q;
    END;
    Thanks

  • Power Query occassionally connects, seems to load, but returns only 200 rows with 1 error

    I have a Power Query that i have used for few weeks, successfully, but occasionally requires being run a few times to return records.  Just lately it seems to require run more than a few times to make it work. 
    When it doesn't return records , it seems to connects and start retrieving data, but returns only randomly like 100 - 200 rows with 1 error.  The error doesn't have any message. So its hard to troubleshoot from that perspective.
    Query appends two other large and merges in a few others. The data sources are either csv files, Sharepoint Lists and tables in workbook.
    I haven't identified anything in terms of environment or query changes that might cause this.
    When it finally does retrieve all records,  it might be after i have done the following things, but i can't say for certain exactly what did the trick:
    * to run query multiple times
    *maybe simply changing anything in query resolves issue
    * making upstream queries (that are merged or appended into this query)  to Not Load to worksheet or model, eg just have connection
    I'd think this type of error and situation while not common is encountered by others.
    Does this ring a bell for anyone, and if so, can you please shed some light on the reasons and resolutions for this?
    Thanks!

    If you click on "1 error" it should show the editor with a query that will select the rows with errors. This unfortunately might not show all errors for various reasons, but you should try it.
    If that doesn't work, here's an example of how to retrieve error details.
    Suppose the following query:
    = Table.FromRecords({[A="B", B="C" + 1]})
    Notice how we're using the + operator with a string and number. This will result in an error.
    I can create a custom column that uses the 'try' operator over the B column. This returns a record with details which I then expand to retrieve the message.
    let
    Source = Table.FromRecords({[A="B", B="C" + 1]}),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each try [B]),
    #"Expand Custom" = Table.ExpandRecordColumn(#"Added Custom", "Custom", {"HasError", "Error"}, {"Custom.HasError", "Custom.Error"}),
    #"Expand Custom.Error" = Table.ExpandRecordColumn(#"Expand Custom", "Custom.Error", {"Message"}, {"Custom.Error.Message"})
    in
    #"Expand Custom.Error"
    Let me know how this works for you.
    Tristan

  • IDCS3 - Sort Rows in a Table

    Hello...is it possible to sort rows of text alphabetically in a table created in ID? Can't find any reference to that in Help.
    Thanks!
    Lisa

    Sounds like your easiest solution is to use the ORDER BY clause in your SQL statement:
    http://www.w3schools.com/sql/sql_orderby.asp
    If that won't do the trick, this might help:
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
    (see Sorting and Otherwise Manipulating Data toward the bottom)

  • Can someone help me for "ROW-00060: Internal error: [dainsert,16]

    p.MsoNormal, li.MsoNormal, div.MsoNormal
    {margin:0in;margin-bottom:.0001pt;font-size:11.0pt;font-family:'Calibri','sans-serif';}
    p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
    {margin-top:0in;margin-right:0in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;font-size:11.0pt;font-family:'Calibri','sans-serif';}
    span.EmailStyle15
    {font-family:'Calibri','sans-serif';color:windowtext;}
    .MsoChpDefault
    @page Section1
    {size:8.5in 11.0in;margin:1.0in 1.0in 1.0in 1.0in;}
    div.Section1
    {page:Section1;}
    ol
    {margin-bottom:0in;}
    ul
    {margin-bottom:0in;}
    Hi,
    Can somebody help regarding the following error message:
    Source DB: SQL 2005, using MS OLDEDB Provider for SQL
    Destination: Oracle 10g, using Oracle Provider for OLEDB.
    In a table “EventLog” I have 800,000 rows and using OLEDB Source(SQL) and OLEDB Destination(Oracle) controls. After loading 702,000 rows I am getting the following error and stops the flow:
    [D-EventLog [32443]] Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005. An OLE DB record is available.  Source: "OraOLEDB"  Hresult: 0x80004005  Description: "ROW-00060: Internal error: [dainsert,16]7".
    [D-EventLog [32443]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.  The "input "OLE DB Destination Input" (32456)" failed because error code 0xC020907B occurred, and the error row disposition on "input "OLE DB Destination Input" (32456)" specifies failure on error. An error occurred on the specified object of the specified component.  There may be error messages posted before this with more information about the failure.
    [DTS.Pipeline] Error: SSIS Error Code DTS_E_PROCESSINPUTFAILED.  The ProcessInput method on component "D-EventLog" (32443) failed with error code 0xC0209029. The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.  There may be error messages posted before this with more information about the failure.
    [S-EventLog [32386]] Error: The attempt to add a row to the Data Flow task buffer failed with error code 0xC0047020.
    [DTS.Pipeline] Error: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED.  The PrimeOutput method on component "S-EventLog" (32386) returned error code 0xC02020C4.  The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing.  There may be error messages posted before this with more information about the failure.
    I can see some buffer related issue here, but can somebody guide me hot to come out of this .
    For the Data Flow Control properties that I have(default values):
    <!--[if !supportLists]-->i)                    <!--[endif]-->DefaultBufferMaxRows=10000
    <!--[if !supportLists]-->ii)                   <!--[endif]-->DefaultBufferSize= 10485760
    <!--[if !supportLists]-->iii)                 <!--[endif]-->EngineThreads=5
    Thanks
    Sreenaiah

    Hi David,
    The things are changing depending on "DefeaultMaxBufferRows" and "DefaultBufferSize" values.
    When I use the default values that I got in the package when I created it, the number of records loading up to a 10% and throwing the above exception. When I increaded these two property values to double, the a 70% records loaded but finally I enedup with the same error message.
    As you mentioned I have tarced for the cause of ROW-00060  error, but could not get a proper solution.
    I feel its something related to the buffer sizes.
    But when I keep a maximum buffer and test it then I got a different error saying that insufficient memory after loading a 90% of records.
    Thanks
    Sreenaiah

  • To delete a row created through "Add Another Row" in OA Framework

    Hi All,
    I am using Add another Row concept in one of OA page.
    The fields in row are mandatory.
    So if user cliaks on add another ro, so new row gets added, but suppose he doesnt enter any data then it gives error on submit button, saying"fileds are mandatory".
    Is there anyway by which user can delete the row created by "Add another Row".
    Thanks in advance

    Hi Tapash..
    Actually I want to remove the row where user has not entered any data.
    As the some of the fields are mandatory, so when user clicks on submit button, it throws error that please enter values for mnadtory fields. I want to remove this validation for the row where user has not entered any data.
    Thanks

  • ORA-39083: Object type TRIGGER failed to create with error:

    i m getting these two error when i import data using impdp.
    ORA-39083: Object type TRIGGER failed to create with error:
    ORA-00942: table or view does not exist
    i have exported (expdp) data from production db, when i importing (impdp) the dump file to the test db i m geting the above two errors.
    example:
    ORA-39083: Object type TRIGGER failed to create with error:
    ORA-00942: table or view does not exist
    Failing sql is:
    CREATE TRIGGER "NEEDLE"."CC_BCK_TRG" BEFORE INSERT OR UPDATE
    ON NIIL.cc_bck_mgmt REFERENCING NEW AS NEW OLD AS OLD FOR EACH ROW
    DECLARE
    w_date DATE;
    w_user VARCHAR2(10);
    BEGIN
    SELECT USER,SYSDATE INTO w_user,w_date FROM DUAL;
    IF INSERTING THEN
    :NEW.cretuser :=w_user;
    :NEW.cretdate :=w_date;
    END IF;
    IF UPDATING THEN
    :NEW.modiuser :=w_user;
    :NEW.modidate :=w_date;
    END IF;
    END;
    status of the above trigger in pro db is valid. and source table also exist even though i m getting error when i import
    please suggest me...

    perhaps you don't have table... (impdp created trigger before create table)
    check about "NIIL.cc_bck_mgmt" table.
    and then create it (trigger) manual ;)
    Good Luck.

  • Can't Create Bean Error

    I modified the numguess example that comes with tomcat but I get a "can't create bean" error message when I call my jsp file. If anyone can see what I'm doing wrong or suggest ways to discover the problem I'd appreciate it.
    My modified jsp:
    <!--
    Copyright (c) 1999 The Apache Software Foundation. All rights
    reserved.
    Number Guess Game
    Written by Jason Hunter, CTO, K&A Software
    http://www.servlets.com
    -->
    <%@ page import = "num.NumberGuessBean" %>
    <jsp:useBean id="numguess" class="num.NumberGuessBean" scope="session"/>
    <jsp:setProperty name="numguess" property="*"/>
    <html>
    <head><title>Number Guess</title></head>
    <body bgcolor="white">
    <font size=4>
    <% if (numguess.getSuccess()) { %>
    Congratulations! You got it.
    And after just <%= numguess.getNumGuesses() %> tries.<p>
    <% numguess.reset(); %>
    Care to try again?
    <% } else if (numguess.getNumGuesses() == 0) { %>
    Welcome to the Number Guess game.<p>
    Play with default limits ( a number between 0 and 100)<p>
    or enter upper and lower limits.<p>
    <form method=get>
    Play with defaults?: <input type=radio name=default value="yes">Yes
    <input type=radio name=default value="no">No
    <\form>
    <% if (numguess.getRadio().equals("no")) { %>
    <form method=get>
    Enter upper limit:<input type=text name=upperLimit>
    Enter lower limit:<input type=text name=lowerLimit>
    <\form>
    <% numguess.reset(); %>
    <% } %>
    <form method=get>
    What's your guess? <input type=text name=guess>
    <input type=submit value="Submit">
    </form>
    <% } else { %>
    Good guess, but nope. Try <b><%= numguess.getHint() %></b>.
    You have made <%= numguess.getNumGuesses() %> guesses.<p>
    I'm thinking of a number between <jsp:getProperty name="numguess" property="lowerLimit"/> and <jsp:getProperty name="numguess" property="upperLimit"/>.<p>
    <form method=get>
    What's your guess? <input type=text name=guess>
    <input type=submit value="Submit">
    </form>
    <% } %>
    </font>
    </body>
    </html>
    and the modified bean:
    * ====================================================================
    * The Apache Software License, Version 1.1
    * Copyright (c) 1999 The Apache Software Foundation. All rights
    * reserved.
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions
    * are met:
    * 1. Redistributions of source code must retain the above copyright
    * notice, this list of conditions and the following disclaimer.
    * 2. Redistributions in binary form must reproduce the above copyright
    * notice, this list of conditions and the following disclaimer in
    * the documentation and/or other materials provided with the
    * distribution.
    * 3. The end-user documentation included with the redistribution, if
    * any, must include the following acknowlegement:
    * "This product includes software developed by the
    * Apache Software Foundation (http://www.apache.org/)."
    * Alternately, this acknowlegement may appear in the software itself,
    * if and wherever such third-party acknowlegements normally appear.
    * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
    * Foundation" must not be used to endorse or promote products derived
    * from this software without prior written permission. For written
    * permission, please contact [email protected].
    * 5. Products derived from this software may not be called "Apache"
    * nor may "Apache" appear in their names without prior written
    * permission of the Apache Group.
    * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
    * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
    * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
    * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
    * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    * SUCH DAMAGE.
    * ====================================================================
    * This software consists of voluntary contributions made by many
    * individuals on behalf of the Apache Software Foundation. For more
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * Originally written by Jason Hunter, http://www.servlets.com.
    package num;
    import java.util.*;
    public class NumberGuessBean {
    int answer;
    boolean success;
    String hint;
    int numGuesses;
    String radiochoice;
    int lowerLimit=0;
    int upperLimit=100;
    String error;
    public NumberGuessBean() {
    reset();
    public void setGuess(String guess) {
    numGuesses++;
    int g;
    try {
    g = Integer.parseInt(guess);
    catch (NumberFormatException e) {
    g = -1;
    if (g == answer) {
    success = true;
    else if (g == -1) {
    hint = "a number next time";
    else if (g < answer) {
    hint = "higher";
    else if (g > answer) {
    hint = "lower";
    public void setRadio(String s) {
         radiochoice=s;
    public String getRadio() {
         return radiochoice;
    public void setLowerLimit( int lowerLimit) {
         this.lowerLimit=lowerLimit;
    public int getLowerLimit() {
         return lowerLimit;
    public void setUpperLimit(int upperLimit) {
         this.upperLimit=upperLimit;
    public int getUpperLimit() {
         return upperLimit;
    public boolean getSuccess() {
    return success;
    public String getHint() {
    return "" + hint;
    public String getError() {
         return ""+error;
    public int getNumGuesses() {
    return numGuesses;
    public void reset() {
         if (getRadio().equals("yes")) {
              answer = (int)(Math.random()*100);
         else {
              int i;
              i=(int)(Math.random()*upperLimit);
              if (i<lowerLimit) {
                   i=i+lowerLimit;
              answer=i;
         success = false;
    numGuesses = 0;

    implement synchronizable and createa constructor, then check it once again.

Maybe you are looking for

  • How to compile Universal binaries in Mac OS X Lion with static linking

    Hello Experts, I have a projects which needs to be ported on Mac. This project uses some third party libraries and link them statically. I am new to Mac world and hence struggling to compile universal binaries with static linking on Mac 10.7.3 system

  • HP PSC 2510 All in One - can't get wireless feature to work with AE

    I just got the Airport Extreme 802.11n access point. But I can't get my old HP printer to connect wirelessly. This is an 802.11b device and should be compatible. I can plug it in to the AE and it works, but can't get the wireless feature to work. Any

  • How to write selection Query for the following requirment.

    Hi All, I am new to ABAP, I need a help , I need to select all plants(WERKS) from MARC at Plant/Material level, then I need to take all sales organozation(VKORG) from T001w, then I need the company code(BUKRS) from TVKO based on VKORG, then I need th

  • Capturing MERGE errors

    I am trying to capture errors coming out of the MERGE statement (in 9i). Currently when a record causes an ABEND, I get a 'end-of-file on communication channel' message and everything stops. What I would like to do is capture the offending record's k

  • How to delete unwanted microsoft word files...PLEASE!

    I would love to know how to delete files in microsoft word that are saved under my documents. The only way I can delete a saved word documsnet is when it has ONLY been saved to the desktop, then I drag it to the trash. When it has been saved to my do