Author Topic: NULL Value?  (Read 1181 times)

drcrazy4

  • Newbie
  • *
  • Posts: 7
NULL Value?
« on: January 15, 2010, 02:56:42 PM »
Sorry you'll have to forgive me if I'm missing something obvious as I'm still learning the ropes. I'm basically trying to add up all of the values in a column (in a columnview). Here is my code:
Code: [Select]
PUBLIC SUB subTotal()

  DIM i AS Integer
  DIM sT AS Float
  DIM amount AS Float
  
  sT = 0
  amount = 0

  IF salesJournal.Count > 1
    FOR i = 1 TO salesJournal.Count
      amount = Val(salesJournal[i][3])
      sT = sT + amount
    NEXT
  ENDIF
  
  sT = sT + Val(salesJournal[0][3])
  customerDisplay("Subtotal", sT, "", "")
  
END
The problem is that I get the error 'Null key' on the line
Code: [Select]
amount = Val(salesJournal[i][3]) when there is more than 1 item in the columnview. If anybody could help with this I'd greatly appreciate it, as it's driving me mad. Thanks!

PS. I have already checked to make sure that salesJournal[1][3] etc. does have a value.
« Last Edit: January 15, 2010, 02:59:38 PM by drcrazy4 »

Linux Basic

NULL Value?
« on: January 15, 2010, 02:56:42 PM »

drcrazy4

  • Newbie
  • *
  • Posts: 7
Re: NULL Value?
« Reply #1 on: January 15, 2010, 03:04:47 PM »
Nevermind I just realised it's a problem with the FOR statement. If anybody else ever has the same problem, this code works:
Code: [Select]
PUBLIC SUB subTotal()

  DIM i AS Integer
  DIM sT AS Float
  DIM amount AS Float
 
  sT = 0
  amount = 0

  FOR i = 0 TO salesJournal.Count - 1
    amount = Val(salesJournal[i][3])
    sT = sT + amount
  NEXT

  customerDisplay("Subtotal", sT, "", "")
 
END