Solved

# Logic Help!

Posted on 2005-05-05
197 Views
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
doc.form = "Monthly Data"
Call doc.Save(True,False)
Else
Msgbox "Error: " & ores.GetError & Error\$
End If
rowCTR = rowCTR + 1
Loop Until ores.IsEndOfData
0
Question by:cyle

LVL 46

Expert Comment

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

LVL 31

Accepted Solution

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

LVL 46

Expert Comment

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

Author Comment

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
doc.period01 = Tamount
doc.form = "Monthly Data"
Call doc.Save(True,False)
ocon.Disconnect

0

LVL 46

Expert Comment

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

## Featured Post

### Suggested Solutions

Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…