Dynamic Array and add result.

Experts,
   How can I code this array dynamically, data will be coming from a view that has all info in it.
   Localfield = any local or place.
   Localamountfield = amount based on a certain local

Dim LocateandAmount(1 to 10, 1 To 10) As String
LocateandAmount (1,1) = "ABC, $45.00"
LocateandAmount (1,2) = "ABC, $33.00"
LocateandAmount (2,1) = "DEF, $12.00"

then add amount based on every local, output will be ABC Local = $456.00
                                                                             DEF Local = $632.00

Thank you!
cyleAsked:
Who is Participating?
 
Sjef BosmanGroupware ConsultantCommented:
Some remarks and more questions (sorry!):
- where is this code located: agent, QuerySave of a form??
- the variable found is useless
- please put an Option Declare in your (Options) section, because...
- location and amount are not declared

For the rest, the code seems okay. But what do you do with the result, i.e. the new field loctotal? Don't you need a Save in this code somewhere (that's why my question about the agent or QuerySave). If you have R6, put
    MsgBox Join(doc.loctotal, ", ")
just after the last End Forall, then you'll see the resulting value.
0
 
Sjef BosmanGroupware ConsultantCommented:
What's about the solution Qwaletee gave you in your previous question?

Can you explain why the info has to be stored in the array? And why it has to be stored in an array at all?

If I had to do this, and the use of the information were more complex than you describe in the above, I'd create one or more new objects for this, with several easy methods.
0
 
cyleAuthor Commented:
qwaletee was on the right track and yes I need to store the value for more calculations. I need to first display the data per location then the total amount for that location (indefinite number of location). Then I need to add the result per year, per....Can you please walk me through it? Lets just start adding amt per location.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
cyleAuthor Commented:
Or maybe you have a different approach to do this?
0
 
Sjef BosmanGroupware ConsultantCommented:
So you get the totals from a view? Do you search the view, or do you take all results and process them? You could easily create a categorized view, in the first column you put the year, in the second the location, and then you add a totals column or you set the amount column to total the results. You could then read the values AND the totals from the view using a NotesViewNavigator object. But this is only possible if you read entire categories, and not single documents.

If I understood the previous question right (and this one), you just need to add numbers, and store them in the document. You want to store ALL the data, or just the computed results? Assuming the latter, you're on a possible way with your strings. Please look at your previous question to see the List that's created by Qwaletee, and how to List is to be handled when you need values. You can see a List as a Name-Value relationship, just like an Array, but with names instead of the array-index. An(other) example
    Dim income List As Double
    income("January")= 2000
    income("February")= 2020

    Forall income_value In income
        s= s + ListTag(income_index) + ": " + CStr(income_value)
    End Forall

Now, in your case, I suppose you need to store values in a field in the document. The only way to do so is to convert them into some format that can be stored in a NotesDocument. The easiest way is to use multivalue fields, using the AppendToTextList method. Go about it like this:
    Dim item As NotesItem
    Set item= doc.GetFirstItem("YourField") ' assuming the field exists
    Forall income_value In income
        Call item.AppendToTextList(ListTag(income_index) + ": " + CStr(income_value))
    End Forall
   
Furthermore, you need a separate List for every entity you want to count. You could do with one if you are sure that names are unique. Suppose there were someone whose name is April, you might count her salary twice, if you use income(:"April") once for the month and the second time for the name. So create
    DIm LocMonthAmount List As Double
    Dim LocYearAmount List As Double
and any other list you need. Remember, a name is always a string. If you accidentally use LocYearAmount(2004) it would work, but when retrieving the ListTag (i.e. the name) of a name-value pair, you would get "2004".

Confused? I sincerely hope not. Read everything there is on Lists, in the Designer Help database.
   
0
 
cyleAuthor Commented:
Maybe a display will help me explain it better.
Data is:    Location    Amount              
               ABC          456.00
               DEF            12.00            Location is indefinite and is not fixed. It has more than 10,000 records.
               HIJ             79.00
               ABC             9.00
               ABC             5.00
               DEF            32.00
Result should be:
               Location    Tamount
               ABC          470.00            Total amount based on location.
               DEF            44.00
               HIJ              79.00

I appreciate you helping this confused person :)
         
0
 
Sjef BosmanGroupware ConsultantCommented:
I'm sorry to say that it explained nothing :) We're both explaining, but did you understand my story? I have my doubts...

Do as Qwaletee suggested:

    Dim total List As Double

Walk through the view's rows, and for every row do the following
    If Not IsElement(total(location)) Then
        total(location)= 0
    End If
    total(location)= total(location) + amount

In the end, you wil have a List of totals, in which
    total("ABC")= 470
    total("DEF")= 44
    total("HIJ")= 79

The you have to convert this List into a storeable form. You suggested strings, and I suggested to use a multi-value stringitem. There are more ways to do this, but this is one:
    Dim s As String
    Dim item As NotesItem
    Forall total_value In total
        s= ListTag(total_value) & ", " & total_value
        If item Is Nothing Then
            Set item= doc.ReplaceItemValue("loctotal", s)
        Else
            Call item.AppendToTextList(s)
        End If
    End Forall

Can you explain where the confusion comes from?
0
 
cyleAuthor Commented:
Sjef_bosman,
   I do not understand, I'm going around, testing one after the other and my first problem is that I do not know where to go! ARGH!!!!! Excuse my ST...D! This is combination of a lot of errors , please bear with it.
Dim ses As New NotesSession
Dim ws As New NotesUIWorkspace      
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim view As notesview
Dim dc As NotesDocumentCollection
Dim s As String
Dim item As NotesItem
Dim total List As Double
Set db = ses.CurrentDatabase
Set view = db.GetView("MDataVW")
Set doc = view.GetFirstDocument
While Not doc Is Nothing
location = doc.location(0)
Msgbox location
amount = doc.amount(0)
Msgbox amount
If Not Iselement(total(location)) Then
  total(location)= 0
End If
total(location)= total(location) + amount
found = False            
Set doc = view.GetNextDocument(doc)
Wend
Forall total_value In total
s= Listtag(total_value) & ", " & total_value
If item Is Nothing Then
Set item= doc.ReplaceItemValue("loctotal", s)
Else
Call item.AppendToTextList(s)
End If
End Forall
0
 
cyleAuthor Commented:
Thanks for answering!
It is a button and then I call it. I need to save it in a form and user's use that view to check the data. So I need to save result in a document.
0
 
Sjef BosmanGroupware ConsultantCommented:
Indeed you do! Otherwise the results will go right into the bitbin ;)

If the result needs to be displayed only, then an MsgBox will do.
0
 
cyleAuthor Commented:
:):) what I meant was the result needs to be saved in a document after each loop.
0
 
Sjef BosmanGroupware ConsultantCommented:
Huh? There are two loops, but there is no outer-loop or so. Which loop do you refer to? Maybe it's best to make the code above a single subroutine or so, because you'd have to Erase total each time...
0
 
cyleAuthor Commented:
I'm testing the code and  Set item= doc.ReplaceItemValue("loctotal", s), gives me Object variable not set.
0
 
Sjef BosmanGroupware ConsultantCommented:
Yep, that's correct :)
0
 
Sjef BosmanGroupware ConsultantCommented:
There's more... ;)

The doc should be a different doc than the one used in the loop. That one ends in Nothing, so there is no object, hence the error message. Make this doc refer to the documetn you want to store the value in.
0
 
cyleAuthor Commented:
Thanks for all your help! You deserve more points than this! I will just open a new question for you!
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.

All Courses

From novice to tech pro — start learning today.