Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Dynamic Array and add result.

Posted on 2005-05-09
16
Medium Priority
?
203 Views
Last Modified: 2013-12-18
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!
0
Comment
Question by:cyle
  • 8
  • 8
16 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 13960862
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
 

Author Comment

by:cyle
ID: 13963037
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
 

Author Comment

by:cyle
ID: 13963051
Or maybe you have a different approach to do this?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 13963416
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
 

Author Comment

by:cyle
ID: 13963682
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
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 13966301
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
 

Author Comment

by:cyle
ID: 13970843
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
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 2000 total points
ID: 13971493
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
 

Author Comment

by:cyle
ID: 13971624
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
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 13971748
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
 

Author Comment

by:cyle
ID: 13971848
:):) what I meant was the result needs to be saved in a document after each loop.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 13971899
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
 

Author Comment

by:cyle
ID: 13971975
I'm testing the code and  Set item= doc.ReplaceItemValue("loctotal", s), gives me Object variable not set.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 13972278
Yep, that's correct :)
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 13972301
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
 

Author Comment

by:cyle
ID: 13972518
Thanks for all your help! You deserve more points than this! I will just open a new question for you!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question