Hi Everyone - I feel like an idiot! I have a simple table with 259 records of 9 fields of numbers that was loaded from a .txt file. The file contains investment transactions.
So,(number of shares * share price) + (commission) should equal Net Tran amount. I wrote a quick Xbasic script to read through the table and check that the calculations are correct. I am doing the math on the table columns and some rows fail even though the calculation is correct. Using the debugger displays the exact same amount in the two fields being tested, but the IF field_1 field_2 statement says they're different. About 7 records out of 259 have this screwy problem. Next I dim'd variables for all the corresponding table columns and used them for the calculations. Now every record fails!
Anyway, there is obviously something I am missing here!
''XBasic
option strict
dim imp as p
dim tot as n
dim f2 as n
dim f3 as n
dim f7 as n
dim f8 as n
dim f9 as n
'
' Open tables
'
imp = table.open("import",FILE_RO_EXCLUSIVE)
imp.fetch_first()
while .not. imp.fetch_eof()
f2 = imp.field_2
f3 = imp.field_3
f7 = imp.field_7
f8 = imp.field_8
f9 = imp.field_9
if imp.field_4 = "SELL" then
tot = (f2 * f3) - (f7 + f8)
' tot = (imp.field_2 * imp.field_3) - (imp.field_7 + imp.field_8)
tot = tot * -1
else
tot = (f2 * f3) + (f7)
' tot = (imp.field_2 * imp.field_3) + (imp.field_7)
end if
if (tot = f9) then
ui_msg_box("Invalid Transaction!",
"Recno: "+str(recno("import"))
+" F1: "+imp.field_1
+" F2: "+str(imp.field_2,9,0)
+" F3: "+str(imp.field_3,6,3)
+" F4: "+imp.field_4
+" F5: "+cdate(imp.field_5)
+" F6: "+str(imp.field_6,11,3)
+" F7: "+str(imp.field_7,5,2)
+" F8: "+str(imp.field_8,4,2)
+" F9: "+str(imp.field_9,10,2)
+" Total: "+str(tot,10,2))
end if
imp.fetch_next()
statusbar.set_text("Record: "+str(recno("import")))
end while
Script attached here...
So,(number of shares * share price) + (commission) should equal Net Tran amount. I wrote a quick Xbasic script to read through the table and check that the calculations are correct. I am doing the math on the table columns and some rows fail even though the calculation is correct. Using the debugger displays the exact same amount in the two fields being tested, but the IF field_1 field_2 statement says they're different. About 7 records out of 259 have this screwy problem. Next I dim'd variables for all the corresponding table columns and used them for the calculations. Now every record fails!
Anyway, there is obviously something I am missing here!
''XBasic
option strict
dim imp as p
dim tot as n
dim f2 as n
dim f3 as n
dim f7 as n
dim f8 as n
dim f9 as n
'
' Open tables
'
imp = table.open("import",FILE_RO_EXCLUSIVE)
imp.fetch_first()
while .not. imp.fetch_eof()
f2 = imp.field_2
f3 = imp.field_3
f7 = imp.field_7
f8 = imp.field_8
f9 = imp.field_9
if imp.field_4 = "SELL" then
tot = (f2 * f3) - (f7 + f8)
' tot = (imp.field_2 * imp.field_3) - (imp.field_7 + imp.field_8)
tot = tot * -1
else
tot = (f2 * f3) + (f7)
' tot = (imp.field_2 * imp.field_3) + (imp.field_7)
end if
if (tot = f9) then
ui_msg_box("Invalid Transaction!",
"Recno: "+str(recno("import"))
+" F1: "+imp.field_1
+" F2: "+str(imp.field_2,9,0)
+" F3: "+str(imp.field_3,6,3)
+" F4: "+imp.field_4
+" F5: "+cdate(imp.field_5)
+" F6: "+str(imp.field_6,11,3)
+" F7: "+str(imp.field_7,5,2)
+" F8: "+str(imp.field_8,4,2)
+" F9: "+str(imp.field_9,10,2)
+" Total: "+str(tot,10,2))
end if
imp.fetch_next()
statusbar.set_text("Record: "+str(recno("import")))
end while
Script attached here...
Comment