Linux Basic
September 05, 2010, 10:26:15 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Linux Basic forums have just been installed. This, I hope, will be the place to talk about the new breed of Basics coming out for the Linux operating system. A place to get informed as well as help each other out with programming and installation issues. Be warned, I am as green as you are. I am here to learn as well.
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: NULL Value?  (Read 493 times)
drcrazy4
Newbie
*
Posts: 7


« 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:
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:
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 » Logged
Linux Basic
« on: January 15, 2010, 02:56:42 PM »

Create 3D Art for Free
 Logged
drcrazy4
Newbie
*
Posts: 7


« 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:
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
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!