Jump to content
Bobby Bradley

Array Building - Key Number Problems

Recommended Posts

Hi All,

Apologize if an answer exists already...did some research to no avail.

I have a script running a 2D array on a single table of records which has worked fine for me in past projects, but this time the "key" is a simple number field as opposed to a text field.

The problem is that the numbers range from 1 up over 2000.  The Array seems to lump some of the single, double and triple digit numbers into the 4 digit number keys also affecting the totals.  Basically, as a result instead of 1744 records being reported the array is lumping everything into only 818 records despite the "key" being unique and records with 4 digits are reporting inflated totals.

The reason for this array function is to future proof the table when multiples of keys are added (and serve other queries)

Fields in question are as follows:

EVENTS::__fk SHOW ID# (I've tried it as a Text and Number Field also validating)

Here's the array function (the rest of script works fine):

Let ( 
[ 
localArray = $$Rainbow ; key = EVENTS::__fk SHOW ID# ; 
pos = Position ( localArray ; key; 1 ; 1 ) ; 

rowNum = ValueCount ( Left ( localArray ; pos ) ) ; 
rowData = Substitute ( GetValue ( localArray ; rowNum ) ; "|" ; "¶" ) ; 

PrevGrandTotal_Proposal = GetValue ( rowData ; 2 ) + 0 ; 
PrevGrandTotal_COGS = GetValue ( rowData ; 3 ) + 0 ;  
PrevSalesTax = GetValue ( rowData ; 4 ) + 0 ; 
PrevLabor_COGS_Estimated = GetValue ( rowData ; 5 ) + 0 ;  
PrevSupport_COGS_Estimated = GetValue ( rowData ; 6 ) + 0 ;  
PrevLabor_Actual = GetValue ( rowData ; 7 ) + 0 ;  
PrevCOGS_fromQB = GetValue ( rowData ; 8 ) + 0 ;  

NewGrandTotal_Proposal = Case ( not IsEmpty ( EVENTS::ws_grandtotal_proposal_n ) ; EVENTS::ws_grandtotal_proposal_n ; 0 ) + PrevGrandTotal_Proposal ; 
NewGrandTotal_COGS = Case ( not IsEmpty ( EVENTS::ws_grandtotal_cogs_n ) ; EVENTS::ws_grandtotal_cogs_n ; 0 ) + PrevGrandTotal_COGS ; 
NewSalesTax = Case ( not IsEmpty ( EVENTS::ws_nys_salestax_proposal_n ) ; EVENTS::ws_nys_salestax_proposal_n ; 0 ) + PrevSalesTax ;
NewLabor_COGS_Estimated = Case ( not IsEmpty ( EVENTS::labor_cogs_total_n ) ; EVENTS::labor_cogs_total_n ; 0 ) + PrevLabor_COGS_Estimated ;
NewSupport_COGS_Estimated = Case ( not IsEmpty ( EVENTS::labor_support_total_n ) ; EVENTS::labor_support_total_n ; 0 ) + PrevSupport_COGS_Estimated ;
NewLabor_Actual = Case ( not IsEmpty ( EVENTS::actuals_labor_n ) ; EVENTS::actuals_labor_n ; 0 )   ;
NewCOGS_fromQB = Case ( not IsEmpty ( EVENTS::actuals_COGSfromQB_n ) ; EVENTS::actuals_COGSfromQB_n ; 0 ) ;


newRow = key & "|" & NewGrandTotal_Proposal & "|" & NewGrandTotal_COGS & "|" & NewSalesTax & "|" & NewLabor_COGS_Estimated & "|" & NewSupport_COGS_Estimated & "|" & NewLabor_Actual & "|" & NewCOGS_fromQB & "¶" ] ; 

Case ( pos = 0 ; 

localArray & newRow ; 

LeftValues ( localArray ; rowNum - 1 ) & newRow & RightValues ( localArray ; ValueCount ( localArray ) - rowNum ) ) )

Any advice is greatly appreciated...hope I've explained it well enough.

Share this post


Link to post
Share on other sites

Well, sleeping on it I found the culprit on my own.  Here's the fix if anybody has similar problems.

Changed the line 

pos = Position ( localArray ; key; 1 ; 1 ) ;

 TO

pos = Position ( localArray ; key; 1 ; -1 ) ;

so now it searches the array properly.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Who Viewed the Topic

    1 member has viewed this topic:
    Terrible Toll 
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.