Using an array with a function

Hi all,
I'm working on an order form where users choose a course they want to order from a drop-down list, then enter the number of licences they require. I'm trying to build in a 'volume-based' discount model the form, and would like to ask for some help in using arrays and how to use them in functions. I'm very new to this, and would appreciate any help you can provide!
Basically, we have 3 products that can be ordered on the same form, and all have different discount models (i.e you get a different % discount for different numbers of licences ordered, depending on the course chosen). I'm storing the discount models in 3 separate two-dimensional arrays, then want to create a function that takes two parameters - the name of the array and the volume that the customer orders - to calculate the appropriate discount. I would then call the function on the change events of either the drop down list or the licence qty field.
Below is my attempt so far (only one array here, but the others are the same syntax). This is held in a script object called DiscountCalculator in the form. The idea of the function is to loop through the array until it finds the correct course, then loop through the value field until it finds the correct discount:
//code holds the discount model for each course in a 2 dimensional array. A new array is needed for each course.
//Course 1
var
Course1Array = new Array(3);
Course1Array[0]
= new Array(2);Course1Array[0][0]
= "49";  //'breakpoint' at which discount is appliedCourse1Array[0][1]
= "0";   //discount % given for this no of licences
Course1Array[1]
= new Array(2);Course1Array[1][0]
= "99";Course1Array[1][1]
= "20";
Course1Array[2]
= new Array(2);Course1Array[2][0]
= "199";Course1Array[2][1]
= "25";
function
CalculateDiscount(CourseArray, value){
for
(var i = 0; i <= CourseArray.length; i++){
if
(value <= CourseArray[i][0]){
return CourseArray[i][1]}
I can use a MessageBox to return a specified value from the array on the click event, so that seems to be set up correctly. But when I try to tcall the function in the change event of the drop-down list on the form:
DiscountCalculator.CalculateDiscount(fldCourse.rawvalue, fldqty.rawvalue)
It doesn't work, usually complaining that "Course1Array is not defined". I think it must be some kind of syntax error, but I have trawled the internet looking for some examples and can't find any.
I'd be grateful for any assistance.
Thanks
Matt

It might be easy to solve these issues if you post your form.
Post your form if it doesn't contain any confidential information.
Nith

Similar Messages

  • Using an array with a library function

    I have a library function that I would like to use on the data in an array. My problem is that the function(which I am using as a subVI) will not accept an array as the input data. So I need to pass each element of the array through the function, and rebuild the array so it is in the same configuration that it started at. I am hoping that there is a easy way to do this in labveiw without having to use a formula node. Any help would be appreciated.
    Amy

    I tried to do what you suggested, but for some reason I still can not wire the indexed array to the subVI. The error I'm getting say that I've wired two terminals not of the same type. The type of the sorce is 2D array of long. The type of the sink is unsigned long. I find that error odd seeing that the array has been indexed. I've attatched my VI. What the for loop is trying to do is pass each element of the array through the subVI, then return an array.
    Attachments:
    VolttoPress.vi ‏41 KB

  • Crash when use indexe array with in place element structure

    Hello !
    I have a problem with in place element structure. I want index a waveform array (16 elements) and when i execute or save that labview close....
    I dont have problem with waveform array 15 elements or less, but i need index 16 elements...
    Thanks for your help !!!
    Solved!
    Go to Solution.
    Attachments:
    Test.PNG ‏8 KB

    I give you my code but it work because i used a waveform array with only 15 elements. I can't save or execute with 16 elements...
    So add it (like picture Test.png) and you will see.
    Thank you
    Attachments:
    Test.vi ‏25 KB

  • Problem with SSAS cube reporting action when using pivot filter with cubevalue function

    Hi everyone,
    I have a quite specific problem when I combine cube actions (Reporting Action SSRS) with Excel's cubevalue() function.
    The problem is when I use a pivot filter as a parameter for the cubevalue() function. The action item does not show up in the context menue.
    The cube action works fine when I do it from a "normal" pivot or if I use the cubevalue() function without the reference to a pivot filter (all the parameters in the function are "hard-coded").
    I use SSAS 2012 and Excel 2010.
    Thanks for yor help.
    Gerhard

    Hi everyone,
    I actually figured out a way to solve this problem. I had to use a detour to solve this bug in Excel (at least I think it's a bug).
    What I needed to do: I had to make Excel belive that the filter is actuall hard-coded and does not come from a pivot filter. This was only possible by adding a new calculated measure to the cube that gives back the MEMBER_Unique_Name to the current member
    passed. This "value" can then be used to go back to the cube and select the cubemember function. Here is a small example.
    This is the cube member:
    CREATE MEMBER CURRENTCUBE.[Measures].[RegCompBranNameKey] AS
    [Company Branch].[Reg - Comp - Bran Name].CurrentMember.Properties("MEMBER_UNIQUE_NAME", TYPED),
    VISIBLE = 0 ;
    And this is then done in a hidden Excel cell:
    =CUBEMEMBER("Metrics";
     IF(RIGHT(CUBEVALUE("Metrics";<PivotFilter>;"[Measures].[RegCompBranNameKey]");5)="[ALL]";"[ALL]";
      RIGHT(CUBEVALUE("Metrics";<PivotFilter>;"[Measures].[RegCompBranNameKey]");LEN(CUBEVALUE("GlobalMetrics";<PivotFilter>;"[Measures].[RegCompBranNameKey]"))-57)
    I had to use the UniqueName property because I have a combined filter. That's also the reason for this truncation and also useing the last part of it. If you just have a straight key you more easily use it.

  • Dont want to use group by with sum function..

    Hi all
    I am using sum function but i dont want to use group by since my query give me following output which i dont want I want.
    0------------22---------(null)     Furniture
    0-----------     3700------     (null)     अनपेड बिल्स देणे
    15800-----14202-----(null)     Petty Cash
    (null)------     (null)------ 9109     Furniture
    (null)------ (null)------ 1789     Petty Cash
    (null)-------(null)------ 0     Checking In-Transfer
    I want like
    0------------22---------9109     Furniture
    0-----------     3700------     0     अनपेड बिल्स देणे
    15800-----14202-----1789     Petty Cash
    what should be the problem how I can handle the query my query is
    select  null as totalcr, null as totaldr, (sum(acct.amtsourcecr)-sum(acct.amtsourcedr)) as opening , ev.name as accountname
    from fact_acct acct right OUTER join  c_elementvalue ev on acct.account_id= ev.c_elementvalue_id
    where acct.dateacct < '01/04/2010'
    and ev.cr_account_base=2
    group by ev.name
    UNION
    select sum(acct.amtsourcecr) as totalcr, sum(acct.amtsourcedr) as totaldr, null as opening
    *,ev.name as accountname*
    from fact_acct acct right OUTER join  c_elementvalue ev on acct.account_id= ev.c_elementvalue_id
    where  acct.datetrx BETWEEN '01/04/2010' and '01/04/2010'
    group by  ev.name
    if I remove group by it shows me error .....not a single group by function ...
    please help me out ,,,
    thanking you

    This is one way you can do it without a group by:
    SQL> with t as
      2    (
      3      select 0 amt1, 22 amt2, null amt3, 'Furniture' tag from dual union all
      4      select 15800,14202,null, 'Petty Cash' from dual union all
      5      select null, null, 9109, 'Furniture' from dual union all
      6      select null, null, 1789, 'Petty Cash' from dual
      7    )
      8  select tag, amt1, amt2, amt3
      9  from
    10  (
    11    select sum(amt1) over (partition by tag) amt1
    12          ,sum(amt2) over (partition by tag) amt2
    13          ,sum(amt3) over (partition by tag) amt3
    14          ,first_value(t.tag) over (partition by t.tag order by rownum) tag
    15          ,row_number() over (partition by t.tag order by rownum) rn
    16    from t
    17  )
    18  where rn = 1
    19  /
    TAG              AMT1       AMT2       AMT3
    Furniture           0         22       9109
    Petty Cash      15800      14202       1789

  • Using Adobe Form with SRM Functionality.

    Hi Friends,
    Our client wants to achieve the total functionality of SRM Purchase Order and Shopping cart through Adobe Form.I would like to know if any of you have come across such a scenario where Adobe Form has been used to replicate SRM purchase Order and Shopping Cart functionality.
    It would be a great help to us if you kindly share your experience of the above scenarios.
    Thanks in advance.
    Best Regards,
    Koushik

    Note 1264423 - Customizing for print forms in SRM 7.0
    Summary
    Symptom
    New functionality/Enhancements provided in SRM 7.0 for print forms is only
    available in the SAP Interactive forms by ADobe and is not available in
    Smartforms delivered by SRM.
    More Terms
    PDF based forms, ADB, Adobe forms, Confirmation, BBP_CONF_ADB, SAP
    Interactive forms by Adobe, Output, SRM-EBP-CA-PRT, SRM-EBP-CGS
    Cause and Prerequisites
    All new enhancements or functionalities are supported only in SAP
    Interactive forms by Adobe which is delivered as part of the SRM 7.0. The
    Smartforms deliverd in previous verions would not have any new enhancements
    from SRM 7.0.
    So it is recommended to use the new SAP interactive forms By Adobe instead
    of the Smartforms for print and output in SRM 7.0.
    Solution
    The customizing required to switch to the new SAP interactive forms by
    Adobe are described avaiable as part of the customization documentation
    againt the IMG entries for Output:
    the documentation and the respecitive customizing can be accesed in the
    following manner:
    Step 1:
    Goto transaction SPRO -> SAP Reference IMG -> SAP Supplier relationship
    Management -> SRM Server -> Cross Application basic settings -> Set output
    Actions and output Format -> Define Actions for Document output.
    maintain the action defentions for all purchasing documents for which the
    new forms are intended to be used in the above mentioned customizing.
    Save the customizing
    Step 2:
    Goto transaction SPRO -> SAP Reference IMG -> SAP Supplier relationship
    Management -> SRM Server -> Cross Application basic settings -> Set output
    Actions and output Format -> Condition-Dependent Document Output.
    maintain the conditions for output for all purchasing documents for which
    the new forms are intended to be used in the above mentioned customizing.
    Save the customizing.
    For more details on each of the above mentioned steps access the
    corresponding documentation againt the respective customizing entry in
    SPRO.
    Release Status: Released for Customer
    Released on: 30.10.2008 11:23:10
    Priority: Recommendations/additional info
    Category: Customizing
    Main Component SRM-EBP-CA-PRT Document Output / Forms
    Valid Releases
    Software Component Release From
    Release
    To Release and Following
    SRM_SERVER 700 700 700
    regards
    Muthu

  • Using CAST/COLLECT with a function

    I have a select statement that gathers comments into a report by user ID and Project Name.
    This works really well until I get to a point where the total comments exceeds 4000 characters, then I get a "character string buffer too small".
    Is there another way to gather the comments and report on them in APEX?
    Here is the Select Statement:
    /** START SELECT
    SELECT
    PROJECT_NAME, USER_ID, COLLECT_FUNC(CAST(COLLECT (USER_NOTES) AS VARCHAR2_T)) as COMMENTS
    FROM
    TBL_PROJECT
    where PROJ_DATE >= to_date('5/1/2011','MM/DD/YYYY') and PROJ_DATE <= to_date('6/30/2011','MM/DD/YYYY')
    PROJECT_NAME, USER_ID
    order by USER_ID;
    /** END SELECT
    Where the VARCHAR2_T is:
    CREATE OR REPLACE TYPE "VARCHAR2_T" as table of varchar2(4000)
    and the function that collects the comments is:
    /*** START CODE
    create or replace function collect_func (t in varchar2_t)
    return varchar2
    as
    ret varchar(4000) := '';
    i number;
    begin
    i := t.first;
    while i is not null loop
    if ret is not null then
    ret := ret || ' -- <BR> ';
    end if;
    ret := ret || t(i);
    i := t.next(i);
    end loop;
    return ret;
    end;
    /*** END CODE

    SleepDeprivedInSeattle wrote:
    I created a workspace at http://apex.oracle.com
    The user name is: TEST_USER
    Password is: myPassword1!You need to tell us the workspace name as well.
    If you go to the SQL Workshop, SQL Commands window and try to execute:
    SELECT
    PROJECT_NAME, USER_ID, COLLECT_FUNC(CAST(COLLECT (COMMENTS_FLD) AS VARCHAR2_T)) as COMMENTS
    FROM
    TBL_PROJECT
    group by PROJECT_NAME, USER_ID
    order by USER_ID;
    It will work for 10 row. But if you select 1000 rows, it fails because one of the projects has more than 4000 characters in the COMMENTS_FLD field. I expanded the VARCHAR to 6000 and it still fails.The VARCHAR2maximum size of <tt>VARCHAR2</tt> value that can be returned in Oracle SQL is 4000 bytes.
    To return more than 4000 bytes, modify <tt>collect_func</tt> to return a CLOB, or use a different string aggregation technique. I normally (ab)use XMLDB for this as it:
    <li>allows for either VARCHAR2 or CLOB output
    <li>doesn't require any additional objects or privileges
    <li>produces clean and properly structured XHTML without a lot of tedious and unreadable concatenations (my colleagues point out that it introduces a lot of tedious and unreadable XMLDB stuff instead)
    SQL> select
      2            d.deptno
      3          , d.dname
      4          , xmlserialize(
      5             content
      6             xmlelement(
      7                 "ul"
      8               , xmlagg(
      9                  xmlelement("li", e.ename)
    10                  order by e.ename
    11                 )
    12             )
    13             as clob
    14             indent size=2
    15            ) employees
    16  from
    17            dept d
    18           join emp e on d.deptno = e.deptno
    19  group by
    20            d.deptno
    21          , d.dname
    22  order by
    23            d.deptno
    24*          , d.dname
    SQL> /
        DEPTNO DNAME       EMPLOYEES
         10 ACCOUNTING       <ul>
                       <li>CLARK</li>
                       <li>KING</li>
                       <li>MILLER</li>
                     </ul>
         20 RESEARCH       <ul>
                       <li>ADAMS</li>
                       <li>JONES</li>
                       <li>SCOTT</li>
                       <li>SMITH</li>
                     </ul>
         30 SALES       <ul>
                       <li>ALLEN</li>
                       <li>BLAKE</li>
                       <li>JAMES</li>
                       <li>MARTIN</li>
                       <li>TURNER</li>
                       <li>WARD</li>
                     </ul>
         40 OPERATIONS       <ul>
                       <li>FORD</li>
                     </ul>Note that there is a 32K limit on the total size of a report row in APEX, including all data and mark-up.

  • Using an array with an expression node on a PDA

    I'm having a problem deploying an application to my PDA (pocket PC 2003) when the block diagram has an array wired to an expression node.
    When I try to build the exe I get the following error:
    retrun is a missing VI or C file.
    Attached is an example VI that produces the same error
    Thanks for the help.
    Eric
    LV 8.2
    PDA Module 8.2
    Attachments:
    Array w ExN.vi ‏11 KB

    Hello,
    This is an issue known prior to release - it is documented in the PDA Readme file:
    Open the LabVIEW Readme files folder by selecting Start»All Programs»National Instruments»LabVIEW 8.2»Readme, and then open readme_PDA.html.
    Search that html page for "expression node" (without quotes) and you should find this issue acknowledged as the 8th bullet under the section entitled "VIs and Functions Known Issues."
    Best Regards,
    JLS
    Best,
    JLS
    Sixclear

  • Using Starts-with XSLT function with XI

    Hi All,
    Any help is apperciated. I am using the starts-with xslt function and when i do so the message gets stucks in the queue. If i run code without the starts-with then is works??
    <xsl:for-each select="receipt/prod">
         <xsl:for-each select="carrier/carrier_detail/carrier">
               <xsl:choose>
                   <xsl:when test="carrier_type='CASE'">
                        <xsl:choose>
                             <xsl:when test="starts-with(carrier_barcode, '00')">
                                                   do something
                                            </xsl:when>
                                           <otherwise>
                                                 do something
                                           </otherwise>
    so on..
    when i try to process messsage using this xslt format it gets sysfail in the queue, but without it, it works fine.
    I need to a special format if the condition of barcode starts with 00

    Chirag,
    Create xslt on abap mapping using transaction SXLT_TOOL on XI abap stack. Copy paste same xslt code and run with test file. You can debug code or most likely you can see error message too.
    Actually your mapping raising an exception which result in sys-fail.
    Hope this will help.
    Nilesh

  • Reading data from mlx90129 rfid tag chip by using spi communication with labview?

    Hi,
     i have evb90129 evalution board in that mlx90129 chip and external memory (cat25128) and three external sensors are there, i am logging data from chip by using rfid reader it ok i am reading. at the same time i configured spi communication and  i am trying to read data i am reading data from internal memory not from external memory i tried but i didnt suceed , now can i use labview to read data from mlx chip and external memory. for spi communication i am using sparkfunction atmega168 microcontroller and also i have spi to usb cable? now can i communicate or i required any devies? is it possible?
    thanks in advance,
    biji.

    I suspect the culprit to be the first parameter to your function actually. Calling another function requires the caller to allocate any buffer with a big enough size for the function to write something into. Allocate that array by using Initialize Array with U8 as type and the correct number as size. Pass this size also as read_length. While your code doesn't make use of this I think the third parameter to your function is either wrong or unnecessary.
    As you use it now it is really nothing more than a local stack variable which you could declare inside the fucntion just as well. On the other hand what you probably want to do is have a function prototype like:
    extern "C" _declspec(dllexport) unsigned char read_Sensor(unsigned *char read_data, unsigned long read_length, unsigned long *byte_transfered);
    But you will have to do some modifications in your C code to support that parameter correctly.
    That all said, doing the same in LabVIEW using VISA functions would have been done with about two VISA nodes, no DLL headaches and probably already long ago working.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Having clause with Analytic function

    can you pls let me know if we can use HAVING clause with analytic function
    select eid,empno,sum(sal) over(partition by year)
    from employee
    where dept = 'SALES'
    having sum(sal) > 10000I m getting error while using the above,
    IS that we can use HAVING clause with partition by
    Thanks in advance

    Your having clause isn't using an analytical function, is using a regular aggregate function.
    You also can't use analytical functions in the where clause or having clause like that as they are windowing functions and belong at the top of the query.
    You would have to wrap the query to achieve what you want e.g.
    SQL> ed
    Wrote file afiedt.buf
      1  select deptno, total_sal
      2  from (
      3        select deptno,sum(sal) over (partition by deptno) as total_sal
      4        from   emp
      5       )
      6  group by deptno, total_sal
      7* having total_sal > 10000
    SQL> /
        DEPTNO  TOTAL_SAL
            20      10875
    SQL>

  • How to alternate data storage into 2 arrays with an analog square wave input? (seems that the retriggera​ble function is not supported by my PXI card)

    Hi!  
    I'm trying to have an analog square wave input determine where data gathered from a second analog input channel is stored.  I want data to be stored to one array during the high signal period of the square wave and data to be store to another array during the low signal period of the square wave.  The square wave I'm using is of constant frequency (8.3 Hz).  I believe I need to use an analog input wave as opposed to a onboard clock or other timing mechanism because my square wave is also being used to modify the input going into my experimental setup.  Thus the data storage needs to be correlated to the timing of the data modification in the experiment.  I tried to use the retriggerable property node function, but receive error 200452, which I think means that my PXI card (6115) can't support this retriggerable function.  So I'm looking for other ways to accomplish alternating data storage in response to an incoming analog square wave.  Any help would be GREATLY appreciated... Thanks!  (I'm also quite new with LabView so toddler-type explanations would probably be most useful  )
    -Shari
    (LabView version 8.6)
    Attachments:
    Pulsed_Acq_Switch_Simplified.vi ‏47 KB

    Hello Shari,
          I am looking at your situation and it seems very intriguing.  after downloading your file I have a couple questions to ask if you don't mind answering.
          Currently in your program you are only taking one sample of data at a time,  this could lead to uneven sampling.  Would you like to sample at a consistent rate  (say 10 Kilosamples of data a second?)  if so what type of card are you using?
          Also,  Do you want your data to be in a 2-D array of data?
    Best Wishes,
    Daniel

  • Array execution with a function

    I have a series of buttons on the screen and they all have some sort of animation associated with them.  All of these buttons are in a symbol titled "MainMenu"  I would like to create an array and place all the button names in the array.  Then using a function when you press any button on the menu all the buttons will stop animating.
    I put this on the stage under document.compositonReady action...
    var buttonReset = ["steelBTN", "glassBTN", "woodBTN", "waterBTN"];
    sym.resetGlobal=function(){
    for(i=0; i<buttonReset.length; i++){
    sym.getSymbol("MainMenu").getSymbol[buttonReset[i]].stop("off");
    And this is on the button under the click action...
    sym.getComposition().getStage().resetGlobal();
    when I don't use an array and just use this...
    sym.resetGlobal=function(){
    sym.getSymbol("MainMenu").getSymbol("steelBTN").stop("off");
    sym.getSymbol("MainMenu").getSymbol("glassBTN").stop("off");
    sym.getSymbol("MainMenu").getSymbol("woodBTN").stop("off");
    sym.getSymbol("MainMenu").getSymbol("waterBTN").stop("off");
    ...everything works so I am thinking maybe I am not creating the array correctly in my first example?  Any help would be appreciated.
    Thanks in advance for the help.

    Actually if you want to reset all your buttons at once this should work:
    var buttonReset = ["steelBTN", "glassBTN", "woodBTN", "waterBTN"];
    function resetBtn(){
    for(i=0; i<buttonReset.length; i++){
    sym.getSymbol("MainMenu").getSymbol[buttonReset[i]).stop("off");
    resetBtn();

  • I have a PowerBook G4 with a non-functioning monitor.  It used to work with an external monitor, but I reinstalled the OS, which cleared the display preferences and now when I restart it won't detect the external monitor. How do I fix?

    I have a PowerBook G4 with a non-functioning monitor.  It used to work with an external monitor, but I reinstalled the OS, which cleared the display preferences and now when I restart it won't detect the external monitor. This means I can't use the computer anymore. How do I fix? I tried using the Command+F2 keyboard shortcut, but it doesnt' work.  It's possible that since I reinstalled the OS, it still needs to be set up, so there's only a welcome screen (but since I can't see it I'm not sure).

    There is no limit to the number of times you can re-install Office on the same computer.
    You can activate by telephone:
    The last paragraph is the relevant bit

  • Not able to copying files/folders from one Document Library to another Document Library using Open with Browser functionality

    Hi All, 
    We have SharePoint Production server 2013 where users are complaining that they are not able to copy or move files from one document library to another document library using “Open with Explorer” functionality.
    We tried to activate publishing features on production server but it did not work. We users reported following errors:  
    Copying files from one document library to another document library:
    Tried to map the document libraries and still not get the error to copy files: 
    In our UAT environment we are able to copy and move folders from using “Open with Explorer” though.
    We have tried to simulate in the UAT environment but could not reproduce the production environment.  
    Any pointers about this issue would be highly appertained.
    Thanks in advance
    Regards,
    Aroh  
    Aroh Shukla

    Hi John and all,
    One the newly created web applications that we created few days back and navigated to document library, clicked on “Open with Explorer”, we get this error.
    We're having a problem opening this location in file explorer. Add this website to your trusted and try again.
    We added to the trusted site in Internet Explorer for this web application, cleared the cache and open the site with same document library but still get the same above error.
    However, another existing web application (In same the Farm) that we are troubleshooting at the moment, we are able click on “Open with Explorer”,  login in credentials opens and we entered the details we are able to open the document
    library and tried to follow these steps:
    From Windows Explorer (using with Open with Explorer), tried to copy or move a files to
    source document library.
    From Windows Explorer moved this file to another destination document library and we got this error.
    What we have to achieve is users should be able to copy files and folders using
    Open with Explorer functionality. We don’t know why Open with Explorer
    functionality not work working for our environment.  
    Are we doing something wrong? 
    We have referred to following websites.
    we hope concepts of copying / Moving files are similar as SharePoint 2010. Our production environment is SharePoint 2013.   
    http://www.mcstech.net/blog/index.cfm/2012/1/4/SharePoint-2010-Moving-Documents-Between-Libraries https://andreakalli.wordpress.com/2014/01/28/moving-or-copying-files-and-folders-in-sharepoint/
    Please advise us. Thank you.
    Regards,
    Aroh
    Aroh Shukla

Maybe you are looking for