Logic Help!

Experts, I'm logically confused right now can anyone help? Thanks.
I have this code that grabs data from another source and dumps it in these fields......But (AMT) needs to be added based on LOC. And when it loads in the field then it will give me one LOC, NAME and one sum AMT.
Call ores.Execute
If (ores.NumRows <> 0) Then
rowCTR = 1
Do
ores.NextRow
If (ores.GetError = DBstsSUCCESS) Then
Set doc = New NotesDocument(db)
' Setting fields area
doc.location = Trim(ores.GetValue("LOC"))
doc.locationname = Trim(ores.GetValue("NAME"))
????
amount = ores.GetValue("AMT")
Tamount = Tamount + amount
doc.period01 = Tamount
????
'set fields here
'load form
doc.form = "Monthly Data"
Call doc.Save(True,False)
Else
Msgbox "Error: " & ores.GetError & Error\$
End If
rowCTR = rowCTR + 1
Loop Until ores.IsEndOfData
Asked:
Who is Participating?

Commented:
Here's what I think you want.  You need to maintain an array of AMT totals per location value.  So, what you sort of want is:

location = Trim(ores.GetValue("LOC"))
amount = ores.GetValue("AMT")
Tamount(location) = Tamount(location) + amount

Now, arrays have to have numeric subscripts, so that won't really work.  But, LotusScript has something called a LIST that functions very much like an array with string subscripts.  So:

Dim Tamount List As Interger 'or As Long or As Single or As Double, depending on your needs
location = Trim(ores.GetValue("LOC"))
amount = ores.GetValue("AMT")
Tamount(location) = Tamount(location) + amount

But, there's one probelm with that as well.  Tamount("XYZ") = 5 would work.  Tamount("XYZ") = Tamount("XYZ") + 5 only wokr sometimes -- you can't referenec the old value unless it was previously assigned (unlike arrays, where it woudl default to zero amount).  So, final code:

location = Trim(ores.GetValue("LOC"))
amount = ores.GetValue("AMT")
If IsElement(Tamount(location)) Then
Tamount(location) = Tamount(location) + amount
Else
Tamount(location) = amount
End If

If you want to extract all the values:

Forall TamountValue in Tamoun
Print "The total amount for location " Listtag(TamountValue) "is:" TamountValue
End Forall

What this does is loop through the Tamount list, and pull out each value.  Each value pulled out is assigned to TamountValue for the duration of the loop.  If you want to find out the name of the subscript assigned to each one, the Listtag function does that for you.

Example:

Dim T List As Integer
T("one") = 1
T("two") = 2
T("four) = 4
T("Five") = 5 'only one with capitals

Print "Does -three- exist? " IsElement(T("three"))
Print "Does -five- exist? " IsElement(T("five"))
Print "Does -Five- exist? " IsElement(T("Five"))
Print "All values:"
Forall TValue in T
Print "For subscript: " Listtag(TValue)
Print " - - value is: " TValue
End Forall

Output:
Does -three- exist? " False
Does -five- exist? " False
Does -Five- exist? " True
For subscript: one
- - value is:  1
For subscript: two
- - value is:  2
For subscript: four
- - value is:  4
For subscript: Five
- - value is:  5
0

Groupware ConsultantCommented:
Could you tell us in pseudo-code what you want?
0

Groupware ConsultantCommented:
Good guesswork, but where does the Save come in?? The algorithm doe shave some flaws, I think...
0

Author Commented:
He does have the right idea, I saved after the loop is finished but LOC is more than one and it should display based on LOC like this:
LOC:   100
TAmount:  12,000.00
LOC:   200
TAmount:  11,000.00
location = Trim(ores.GetValue("LOC"))
amount = ores.GetValue("AMT")
If IsElement(Tamount(location)) Then
Tamount(location) = Tamount(location) + amount
Else
Tamount(location) = amount
End If
Else
Msgbox "Error: " & ores.GetError & Error\$
End If
rowCTR = rowCTR + 1
Loop Until ores.IsEndOfData
'load form
doc.period01 = Tamount
doc.form = "Monthly Data"
Call doc.Save(True,False)
ocon.Disconnect

0

Groupware ConsultantCommented:
cyle,

> doc.period01 = Tamount
You can't do that with a List, it cannot be stored. So you have to do soemthing different with it. Several ways:
1) you put everything in text, if you don't need to use it for computations at some later moment (see also Qwaletee's answer)
2) you put it into two multi-value fields in the document, one for the locations and one for the values
3) you create (or use) response documents to store location names and values (inefficient if that's all to be stored)

What's it to be?

Sjef
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Already a member? Login.

All Courses

From novice to tech pro — start learning today.