Variable declaration in a function

Hi all

Yes it is for a class :).
I am building a function that will tell me how many years a boat has been continuous. I'm having a problem with where / how to declare a variable.
I think that my function won't work if I can fix it - if I need help so much.
Error message
PLS-00201: identifier 'YEARS_INSERVICE' must be declared
Here is my code for the function
CREATE OR REPLACE FUNCTION get_years_inservice(
boat_id IN boat.boat_id%TYPE) RETURN NUMBER IS
BEGIN
SELECT MONTHS_BETWEEN(SYSDATE, pur_date)/12 INTO years_inservice
FROM boat
WHERE boat_id = boat_id;
RETURN ROUND(years_inservice);
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20348,
'Craft with ID '|| boat_id ||' does not exist.');
END get_years_inservice;
Here is the code for my table of boat:
-- Creates table of water craft for rent.
CREATE TABLE Boat
(Boat_ID NUMBER(10) 
Boat_Name VARCHAR2(30) NOT NULL,
Model VARCHAR2(30) NOT NULL,
Manufacturer VARCHAR2(30) NOT NULL,
Seating_Capacity NUMBER (10) NOT NULL,
STATUS VARCHAR2(30) NOT NULL,
pur_date DATE NOT NULL,
last_maint_date DATE,
CONSTRAINT "Boat_PK"
PRIMARY KEY ( Boat_ID)
)

/
-- Create Boat_ID Sequence
CREATE SEQUENCE boat_id_seq
START WITH     1000
 INCREMENT BY   25
 NOCACHE
 NOCYCLE;
/

--- Boat Data
INSERT INTO boat
  VALUES  (boat_id_seq.NEXTVAL, 'Speedy', 'Speedster', 'Seadoo', '4', 'Available', '15-Jan-2010', '15-Jan-2012'); 
INSERT INTO boat
  VALUES   (boat_id_seq.NEXTVAL, 'Gone', 'Speedster', 'Seadoo', '4', 'Unavailable', '15-Jan-2010', '15-Jan-2012'); 
INSERT INTO boat
  VALUES  (boat_id_seq.NEXTVAL,'Mama Kin', 'Deck Boat', 'Ranger', '6', 'Available', '15-May-2010', '15-May-2012');     
INSERT INTO boat
  VALUES  (boat_id_seq.NEXTVAL,'Beer R-U-N','Cuddy', 'Aerocraft', '6', 'Available', '15-October-2011', '15-May-2012');
INSERT INTO boat
   VALUES  (boat_id_seq.NEXTVAL, 'Rampage', 'Pontoon', 'Sailstar', '10', 'Available', '15-March-2009', '15-March-2012');   
INSERT INTO boat
  VALUES (boat_id_seq.NEXTVAL, 'Justyn Time',  'Pontoon', 'Sailstar', '10', 'Unavailable', '15-March-2009', '15-March-2012');   
INSERT INTO boat
  VALUES (boat_id_seq.NEXTVAL, 'Triumph',  'Pontoon', 'Sailstar', '12','Available', '15-Jan-2012', '15-Jan-2012');   
INSERT INTO boat
  VALUES (boat_id_seq.NEXTVAL, 'Big House', 'House Boat', 'Gulfstream', '16','Available', '15-Jan-2010', '15-Jan-2012');                   
INSERT INTO boat
  VALUES (boat_id_seq.NEXTVAL, 'Cabo Wabo', 'Barge', 'Sea Raider', '25', 'Available', '15-March-2009', '15-March-2012');  

COMMIT;
We thank you in advance to research.

G

GMoney says:
Still don't get what I expected much.

select GET_YEARS_INSERVICE(1125) AS YEARS_INSERVICE from BOAT

Yields:

YEAR_INSERVICE
1
1
1
1
1
1
1
1
1

I need to make months in service, and I'm not sure why the results has 9 lines?

You choose to SHIP without WHERE clause. BOAT has 9 lines, so the result will have 9 rows.

You pass a hardcoded value (1125) rather than the table as suggested thomaso BOAT_ID. If you are running

select boat_id, boat_name, get_years_inservice( boat_id ) years_inservice
  FROM boat

you will always get 9 rows but each row will have several years of this vessel at sea.

Justin

Tags: Database

Similar Questions

  • The local variable cannot be declared outside a function.

    I was getting an ORA-936 on an application that I support (Oracle 11 g, CF 11, Windows Server 2012).  The database went down yesterday, for some reason unknown to me, and when he came, I'm now getting this error message.  The only pointer to the .cfm file is the sponsor.  I don't see how to fix it.  Can what information I include that will help you help me?  It seems that the more I learn, something new always comes along.   Here is the error page that is displayed.  I have not changed all the statements, I know.   Thank you.

     The local variable application cannot be declared outside of a function.
    All variables defined with the var keyword must be declared inside a function.
    
    Resources:
    
        Check the ColdFusion documentation to verify that you are using the correct syntax.
        Search the Knowledge Base to find a solution to your problem.
    
    Browser       Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:46.0) Gecko/20100101 Firefox/46.0
    Remote Address       108.44.188.221
    Referrer       https://TestServer/secure/Requirement/requirementsum.cfm?frompage=orig&CFID=58847&CFTOKEN=1c45276fd65debf-7F25B5E6-AA99-1268-0B24AB3E54D73594
    Date/Time       27-May-16 01:25 PM
    Stack Trace
    
    
    coldfusion.compiler.ASTvariableDefinition$InvalidVarDefinition: The local variable application cannot be declared outside of a function.
        at coldfusion.compiler.ASTvariableDefinition.register(ASTvariableDefinition.java:98)
        at coldfusion.compiler.SemanticAnalyzer.transform(SemanticAnalyzer.java:340)
        at coldfusion.compiler.Treewalker.postorder(Treewalker.java:100)
        at coldfusion.compiler.Treewalker.postorder(Treewalker.java:27)
        at coldfusion.compiler.Treewalker.postorder(Treewalker.java:27)
        at coldfusion.compiler.NeoTranslator.parseAndTransform(NeoTranslator.java:443)
        at coldfusion.compiler.NeoTranslator.translateJava(NeoTranslator.java:370)
        at coldfusion.compiler.NeoTranslator.translateJava(NeoTranslator.java:147)
        at coldfusion.runtime.TemplateClassLoader$TemplateCache$1.fetch(TemplateClassLoader.java:436)
        at coldfusion.util.LruCache.get(LruCache.java:180)
        at coldfusion.runtime.TemplateClassLoader$TemplateCache.fetchSerial(TemplateClassLoader.java:362)
        at coldfusion.util.AbstractCache.fetch(AbstractCache.java:58)
        at coldfusion.util.SoftCache.get_statsOff(SoftCache.java:133)
        at coldfusion.util.SoftCache.get(SoftCache.java:81)
        at coldfusion.runtime.TemplateClassLoader.findClass(TemplateClassLoader.java:609)
        at coldfusion.filter.PathFilter.invoke(PathFilter.java:101)
        at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:94)
        at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:79)
        at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
        at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
        at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:58)
        at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
        at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
        at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62)
        at coldfusion.CfmServlet.service(CfmServlet.java:219)
        at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
        at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:437)
        at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:197)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:722)
    

    I had added end brand to all the and it has cleared up.  Weird.

    Which brings me to another question.  When you do make the end like this tag or use the tag?

  • APEX 4.2 translate data 'function and Global Variable declaration '.

    Hello everyone,

    I use APEX 4.2.1.00.08 and I wonder if there is a way to translate "Function and Global Variable declaration" textarea. Any other script text box is available for translation, but not this one.
    I know what the code is loaded on the header, but may contain important alert messages of global functions.

    Thanks in advance.

    Hi Grandmaster,

    "Function and global variables declaration" contains the JavaScript code, that is why it is not wise to include in the standard translation process.

    In my opinion, you have several options to access your translated messages:

    -) Use Application-> Substitutions or
    -) Store your message in the form of component shared-> SMS and and assign it to an application with the APEX_LANG element. Api MESSAGE (http://docs.oracle.com/cd/E37097_01/doc/doc.42/e35127/apex_lang.htm#CHDBCEAB)

    In 'Function and Global Variable declaration' use substitution syntax to replace the value. For example:

    var myDeleteMessage = "&G_MY_DELETE_MESSAGE.";
    ...
    alert(myDeleteMessage);
    

    where G_MY_DELETE_MESSAGE would be a part of the application or the request for Substitution.

    Concerning
    Patrick
    -----------
    Member of the APEX development team
    My Blog: http://www.inside-oracle-apex.com
    APEX Plug-Ins: http://apex.oracle.com/plugins
    Twitter: http://www.twitter.com/patrickwolf

  • How to find the number of bind variables declared in the current session

    Hi all
    I want to know a query to find out the number of variables declared in the current session.

    Note that the name of this forum is "SQL Developer *(Not for general SQL/PLSQL questions) * ', as well as for the issues with the SQL Developer tool. Please post these questions under the dedicated [SQL and PL/SQL | https://forums.oracle.com/forums/forum.jspa?forumID=75] forum (you have posted here before).

    Kind regards
    K.

  • If a class declares a static member variable, then the member functions cannot link to them

    For example

    Class ABCD

    public static int a;

    void function f;

    =======================================

    void f()

    a = 4;

    This compiles ok, but does not link.   fatal error LNK1120: 2 unresolved external

    Hi Gerald,

    Thanks for posting your query on the Microsoft community.
     

    I suggest that you post the same question on the MSDN forums for assistance.
     
    Follow the link and ask your question.
     
    Hope the above information helps.

    Do get back to us and let us know if you need help with Windows.
  • Problem with variable declaration

    I'm developing a multiuser Flash application, using the smartfox Server 2.0, but I'll have a problem with defining/declaration of a variable/object/table and then access. I am trying to set the "curMap" (be it a variable, the matrix, the object, everything that works) within the following function, like the array returned by the server, "resObj". It works fine as long as I only call 'curMap' within this function (see you in line: r_txt.text = curMap ;)) However whenever I try to call the "curMap" on the coding of the image outside the function, it returns under the indefinite form or usually nothing.  Any ideas on how to properly / attribute this? I tried various things (such as _root, _global or setting the var "curMap" outside of the function) with no luck.

    Here is my Code:

    smartfox.onExtensionResponse = function (resObj:Object, type: String)
    {
    If (type is 'xml')
    {
    If (resObj._cmd is "getMap")
    {
    curMap = resObj.db [0];
    r_txt. Text = curMap;
    } Else if (resObj._cmd == "getSurr") {}
    surrMap = resObj.db;
    b_txt. Text = surrMap [0];
    }
    }
    }

    Thank you

    Make sure that you are trying to access this variable before it is defined.  That is to say, which resembles an asynchronous function for the code of this function will probably run AFTER the code that appears in the lines that follow the body of the function.

  • Shared Variable Open accidents executable function

    I have a program which is programmatcially connection to network variables published PSP on a crio. Its a pretty simple application, so I'm contacting IO channels by publishing their data with analytical engine.

    My project works in developer mode, but does not work after you build an executable.  The executable does not error, it crashes completely and I am obliged to 'End task' within windows.  No errors, it was a pain, but I finally get this behavior up to this part of my code.

    I opened the connection in a method of class reentrante shared clone that I use to initialize the sensor data.  I don't know if the variable opening function does not support using a calling in a method of a class in this way or if it's just a weird bug. I built small executables of test using just the function of variable aperture that seem to work well when operating.  I also tried not reentrant execution with the same effect.

    I also wonder if my engine Run Time may be corrupted, but I don't know how to check that this executable is on my development computer.  I can't seem to find a way to re - install the runtime without completely removing LV2012 and from scratch.  Thank you

    Just an update on this forum, I have worked with John on a service request associated with this forum, and I was unable to reproduce this crash on Windows 7 or Windows XP (LabVIEW 2012).

  • Call a variable from outside a function

    Hey everybody!

    I am so confused. I hope that someone can help me here! I try to call the variable named "time' go outside a function. '"

    Here is my code:

    var myXML:XML = new XML();

    var XML_URL:String = 'youtube - time.xml";

    var myXMLURL:URLRequest = new URLRequest (XML_URL);

    var myLoader:URLLoader = new URLLoader (myXMLURL);

    myLoader.addEventListener (Event.COMPLETE, xmlLoaded);

    var time;

    function xmlLoaded(event:Event):void

    {

    time = XML (myLoader.data);

    }

    trace (Time);

    Here's what my XML looks like:

    10 < time > < / time >

    Whenever I run the trace (time); outside the service - I get an "undefined" message in the output window.

    How can I access the variable " " time "outside my service so I can assign to another variable like this: "

    var VIDEOS_SECONDS = time;

    Thank you very much for any help!

    Timothy

    Functions are called, the variables are accessible.

    First thing you need to do is to check that xmlLoaded is actually called. Copy your trace statement to test. If you never actually call the .load method on your URLLoader object, as suggested by Colin, nothing will never load.

    Second, if your code snippet above is literally everything from an image and run correctly, then most likely your trace statement executes before the XML loading data are completed. URLLoader runs asynchronously, which means that your main code stream do NOT stop and wait until she finishes.

  • By the way Self as a parameter or by passing an object Variable to a member function, both in the approach IN OUT NOCOPY Mode which is better?

    Hi all
    Asking for help which approach is better of the two in terms of performance and why (if there is no difference) or are they an and they same and only different in terms of syntax only.

    (A) to call a function with itself in passing as IN OUT nocopy
    (B) passing the calling object, same as IN OUT NOCOPY.

    @
    (In my approach, I need to pass an object with almost 30 attributes and I must assign values to few attributes of the object in a few member functions that will impact object)

    I have an object created in the
    CREATE or REPLACE TYPE my_obj AS OBJECT
    (
    NAME VARCHAR2 (100),
    FUNCTION CONSTRUCTOR My_obj RETURNS SELF AS RESULTS,
    FUNCTION MEMBER put_name (SELF IN OUT NOCOPY my_obj) RETURN PLS_INTEGER,
    RETURN of the MEMBER FUNCTION insert_name (v_my_obj IN OUT NOCOPY my_obj)
    PLS_INTEGER,
    MEMBER get_name PROCEDURE
    );
    /
    CREATE OR REPLACE TYPE BODY MY_OBJ

    FUNCTION CONSTRUCTOR RETURN self AS RESULT My_obj IS
    BEGIN
    NULL;
    RETURN;
    END;

    FUNCTION MEMBER (SELF IN OUT NOCOPY my_obj) put_name IS BACK PLS_INTEGER
    BEGIN
    Self.Name: = "my_name_in_self";
    RETURN 1;
    END put_name;

    MEMBER FUNCTION insert_name (v_my_obj IN OUT NOCOPY my_obj)
    IS BACK PLS_INTEGER
    BEGIN
    v_my_obj. Name: = "my_name_in_Alias";
    RETURN 1;
    END insert_name;

    MEMBER get_name PROCEDURE IS
    BEGIN
    dbms_output.put_line (self. (Name)
    END;
    END;
    /

    (a) put_name heel 1 call:

    declare
    v my_obj: = my_obj();
    number of ret_val;
    Start
    ret_val: = v.put_name;
    v.get_Name;
    end;

    o/p: my_name_in_self

    (a) insert_name citing heel 2:

    declare
    v my_obj: = my_obj();
    number of ret_val;
    Start
    ret_val: = v.insert_name (v);
    v.get_Name;
    end;

    o/p: my_name_in_Alias

    What is better to use the put_name or use the function insert_name.
    I manipulate the object when it is passed to a function.

    Thanks in advance,
    Kind regards
    Gaurav R

    As Billy said above, each member method has implicitly (which can be made explicit, as with "put_name", when required, for example, to specify the "nocopy" option) parameter named 'home '. For member functions, the passage of default mode is "inside". For the procedures of members, the passage of default mode is "outside". Therefore, the actual signature of the function of your 'insert_name":

    ...
    member function insert_name(self in my_obj, v_my_obj in out nocopy my_obj) return pls_integer
    ...
    

    Since you don't self directly access this function, it is logically equivalent to a static type function (which has no implicit setting of "self"):

    ...
    static function insert_name(v_my_obj in out nocopy my_obj) return pls_integer
    ...
    

    which is basically no different than using a non-object function that takes a parameter of type of object:

    create function insert_name(v_my_obj in out nocopy my_obj) return pls_integer
    

    Gerard

  • Variable effects with Loop function.

    I need to create a code that take the following strings:

    
    "Scale"
    "Position"
    "Side"
    
    
    
    
    
    
    
    
    
    
    
    

    And each of them, put in a copy of this code:

    thisComp.effect(!!!STRING HERE!!!)("Layer").name;
    
    
    
    
    
    
    
    
    
    

    And after that, the three variables, each one, receive a complete code.

    
    var a;
    var b;
    var c;
    
    
    
    
    
    
    
    
    
    
    
    

    The result would be this:

    
    var a = thisComp.effect("Scale")("Layer").name;
    var b = thisComp.effect("Position")("Layer").name;
    var c = thisComp.effect("Side")("Layer").name;
    
    
    
    
    
    
    
    
    
    
    
    
    

    I try to do it like this:

    var strings = ["Scale", "Position", "Side"];

    var val = function (a, b, c) {}

    for (var i= 0; I <channels.length; i ++) {}

    effectof the var = thisComp.effect () ('Layer') .namestrings[i];

    Val (effect);

    }

    }

    But don't have experience with functions and loops For.


    And not whether it is the right way to do it.

    I need to do this because my code becomes too long for many repetitions.

    I think for this, will have to use loop and the function.

    Thank you.

    You might have better luck if you describe what it is you are trying to do, rather than how you try to do, because it is not obvious (to me at least) exactly what your code is supposed to accomplish.

    Dan

  • Variable Declaration in the CSS of JavaFX file

    also requested on stackoverflow: http://stackoverflow.com/questions/13566210/declaring-variable-in-javafx-css-file/13566682

    So... caspian.css (the file style sheet which is distributed in the javafx runtime, defining the default styles for the user interface controls) has CSS variables, it assigns color values to a variable and then use that variable as the value of other CSS properties. I want to use this feature with ' {number} px ' type of values. For example, I want to declare a variable whose value of 10px RADIUS and use that variable each time I need to set a RADIUS, so if I need to change all the RADIUS values at the same time I can do so by changing the value of the variable. Is this possible?

    -----

    Here is my experience (which failed)

    It's my Experiment.fxml
    <?xml version="1.0" encoding="UTF-8"?>
    
    <?import java.lang.*?>
    <?import java.net.*?>
    <?import java.util.*?>
    <?import javafx.scene.control.*?>
    <?import javafx.scene.layout.*?>
    <?import javafx.scene.paint.*?>
    
    <AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml">
      <children>
        <TextArea layoutX="200.0" layoutY="119.0" prefWidth="200.0" styleClass="track" wrapText="true" />
      </children>
      <stylesheets>
        <URL value="@css/Experiment.css" />
      </stylesheets>
    </AnchorPane>
    ... and this is my ' css/Experiment.css: file
    * {
        -fx-radius-default: 10px;
    }
    .track {
        -fx-border-radius: -fx-radius-default;
        -fx-border-color: black;
    }
    This code does not work, what gives an error message:
    Could not resolve '-fx-radius-default' while resolving lookups for '-fx-border-radius' from rule '*.track' in stylesheet file: /home/abdullah/codebase/src/package/css/Experiment.css

    Search does not work for the unit values. You can create a demand for it in http://javafx-jira.kenai.com

  • export variables created in a function

    Hey all,.

    This isn't strictly a matter of powercli, but I hope someone can provide an overview of this.

    I'm building quite stocky scripts to do things and use the functions where I can, as you do

    problem is all the variables I create/update during execution of the function are not available outside the service PS 1, nobody knows how to do this?

    Consider code like this:

    function blah

    {

    Write-Host "Yes do stuff."

    $var = 1 + 1

    }

    $var is available only inside the function... I guess by design, but blocks of code, I'm building need to be able to spit out a $var - if I'm missing a fundamental part of the functions?

    I hope that someone can push me in the right direction - thanks in advance for the help!

    Kind regards

    David

    You can leave the function of the return variable in your hand like this

    function blah
    {
    Write-Host "yea do some stuff"
    $var = 1 + 1
    $var
    }
    
    $mainvar = blah
    
  • Variable declaration

    Hi all

    I have this code:

    Declare
    v_today date: = sysdate;
    v_hello VARCHAR (20): = 'Hello world ';
    v_tomorrow v_today % TYPE;
    BEGIN
    DBMS_OUTPUT. Put_line (v_hello);
    DBMS_OUTPUT. Put_line (v_today);
    DBMS_OUTPUT. Put_line (v_tomorrow + 1);
    END;

    The result is:

    Hello world
    14 DECEMBER 11


    How to declare this variable (* v_tomorrow v_today % TYPE; *) correctly so I get the result:

    Hello world
    14 DECEMBER 11
    DECEMBER 15, 11

    Thank you very much!!
    Declare
    v_today date :=sysdate;
    v_hello VARCHAR(20):='Hello World';
    v_tomorrow v_today%TYPE;
    BEGIN
    v_tomorrow := v_today;
    DBMS_OUTPUT.PUT_LINE(v_hello);
    DBMS_OUTPUT.PUT_LINE(v_today);
    DBMS_OUTPUT.PUT_LINE(v_tomorrow+1);
    END;
    /
    
  • Using variables for the AS2 function arguments

    Hello

    I am trying to create a function in AS2.

    After you create the function, I want to use the values stored in the variables specified for the arguments to the function instead of manually typing static values for the calculation of the service. Also, I want to use the function to assign a new value to the existing variable.

    I asked a similar question here 2 days ago and got the answer (thanks), but now I have another question - how to create the function to assign a value to the variable, the variable itself is also a function argument?

    For example, I have 6 numeric variables:

    var CoinA:Number = 10;
    var CoinB:Number = 20;
    var CoinC:Number;

    var CoinD:Number = 30;
    var CoinE:Number = 40;
    var CoinF:Number;

    Then I tried to create a function to assign values to the variables stuck and CoinF:

    function CalculationA(FirstCoin,_SecondCoin,_ThirdCoin):Void {}

    FirstCoin = SecondCoin + ThirdCoin;

    }

    CalculationA (stuck, CoinA, CoinB);
    CalculationA (CoinF, stuck, CoinF);

    The code above didn't really affect the values of 30 and 70 stuck and CoinF variables, but instead, stuck and CoinF values are undefined.

    Please give me the correct code if there is a good way to do this.

    Thank you

    Here's a way to do it, passing a string value with the name of the variable instead of the actual variable name...

    var CoinA:Number = 10;
    var CoinB:Number = 20;
    var CoinC:Number;
    var CoinD:Number = 30;
    var CoinE:Number = 40;
    var CoinF:Number;

    function CalculationA(FirstCoin,_SecondCoin,_ThirdCoin):Void {}
    This [FirstCoin] = SecondCoin + ThirdCoin;
    }

    CalculationA ('stuck', CoinA, CoinB);
    CalculationA ("CoinF", CoinD, person);

    (Note that in your second function call, I changed coins since CoinF (ThirdCoin) is not defined at this time).

  • Using variables for an AS2 function arguments

    Hello

    I am trying to create a function in ActionScript 2.

    After you create the function, I want to use the values stored in the variables specified for the arguments to the function instead of manually typing the static values for the arguments to the function. And also I want to use the function to assign a new value to the existing variable. Is this possible?

    For example, I've defined variables "here is a simple function named"CalculationA".

    var CoinA:Number = 10;
    var CoinB:Number = 20;
    var CoinC:Number;


    function CalculationA (CoinA, CoinB, stuck) {}

    Stuck = Number (CoinA) + Number (CoinB);

    }

    The code above does not really. No value is assigned to the variable stuck.

    Can someone give me a good AS2 code please?

    Thank you

    use:

    var CoinA:Number = 10;
    var CoinB:Number = 20;
    var CoinC:Number;

    CalculationA (CoinA, CoinB);

    function CalculationA(coinA,_coinB):Void {}

    Stuck = Number (coinA) + Number (coinB);

    }

Maybe you are looking for