Jump to content

Array Building - Key Number Problems


This topic is 2558 days old. Please don't post here. Open a new topic instead.

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.

Link to comment
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.

Link to comment
Share on other sites

This topic is 2558 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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