Solved

For loop in Lotus Script

Posted on 2004-08-16
8
449 Views
Last Modified: 2013-12-18
Hi , Need some help on a 'for loop' in LotusScript.
I'm reading values from one form and updating them into another form.

The first form has a text field named TotalMANs. The value in this field can be between 1 to 175.

Also there are 175 other fields in the form which are called as MAN1 , MAN2 , MAN3, MAN4, MAN5, MAN6, UNTIL........ MAN175

Lets say I'm referring these fields in my agent as doc.TotalMANs,  doc.MAN1, doc.MAN2, doc.MAN3, doc.MAN4, UNTIL..............doc.MAN175

This is what I want to do now:
If the doc.TotalMANs value is 5 Then
 I want to read values from doc.MAN1, MAN2,MAN3,MAN4,MAN5 and append it in another field from a different form (doc2.MAN which is a multi-value field).

Similarly If the doc.TotalMans value is 100 Then
 I want to read values from doc.MAN1, MAN2.. until doc.MAN100 and append all these values to doc2.MAN.

So the loop should run based on the doc.TotalMans value.

I know I've to write a for loop for this.
Please advise
thanks
Kalios
0
Comment
Question by:kalios
  • 3
  • 3
  • 2
8 Comments
 
LVL 19

Expert Comment

by:madheeswar
ID: 11817525
the below code should work. And I assume,you have some key to fetch another field from a different form.

Sub Click(Source As Button)
      Dim ws As New notesuiworkspace
      Dim curdoc As notesdocument
      Dim uidoc As notesuidocument
      Dim ss As New notessession
      Dim db As notesdatabase
      Dim view As notesview
      Dim dc As notesdocumentcollection
      Dim doc As notesdocument
      Dim arr() As String
      
      Set uidoc=ws.currentdocument
      Set curdoc=uidoc.document
      Set db=ss.currentdatabase
      Set view=db.getview("urViewName")
      
      Dim item As notesitem
      
      Dim x As Integer
      Dim k As Integer
      k=0
      For x=1 To curdoc.totalMans(0)
            k=k+1
            tmpfld="Man"+Cstr(x)
            Set item=curdoc.getfirstitem(tmpfld)
            Redim Preserve arr(k)
            arr(k)=item.values(0) 'I assume Man1,Man2,....are not multivalue fields. If they are multivalue, then need to use loop here.
      Next
      tmpkey=curdoc.YourkeyField(0)
      Set dc=view.getalldocumentsbykey(tmpkey)
      Set doc=dc.getfirstdocument
      While Not doc Is Nothing
      'Your another field.
            doc.Man=arr
            Call doc.save(True,True)
            Set doc=dc.getnextdocument(doc)
      Wend
      
End Sub
0
 
LVL 19

Assisted Solution

by:madheeswar
madheeswar earned 40 total points
ID: 11817551
try this:
Sub Click(Source As Button)
      Dim ws As New notesuiworkspace
      Dim curdoc As notesdocument
      Dim uidoc As notesuidocument
      Dim ss As New notessession
      Dim db As notesdatabase
      Dim view As notesview
      Dim dc As notesdocumentcollection
      Dim doc As notesdocument
      Dim arr() As String
      
      Set uidoc=ws.currentdocument
      Set curdoc=uidoc.document
      Set db=ss.currentdatabase
      Set view=db.getview("urViewName")
      
      Dim item As notesitem
      
      Dim x As Integer
      Dim k As Integer
      k=0
      For x=1 To curdoc.totalMans(0)
            
            tmpfld="a"+Cstr(x)
            Set item=curdoc.getfirstitem(tmpfld)
            Redim Preserve arr(k)
            arr(k)=item.values(0) 'I assume Man1,Man2,....are not multivalue fields. If they are multivalue, then need to use loop here.
            k=k+1
      Next
      
      tmpkey=curdoc.YourkeyField(0)
      'if the another documents are more than one, then use the below code.
      Set dc=view.getalldocumentsbykey(tmpkey,True)
      Set doc=dc.getfirstdocument
      While Not doc Is Nothing
      'Your another field.
            doc.Man=Fulltrim(arr)
            Call doc.save(True,True)
            Set doc=dc.getnextdocument(doc)
      Wend
      'else if it is ONE document, then use below code:
      Set doc=view.getdocumentbykey(tmpkey)
            'Your another field.
      doc.Man=Fulltrim(arr)
      Call doc.save(True,True)
      
End Sub
0
 
LVL 24

Accepted Solution

by:
HemanthaKumar earned 60 total points
ID: 11820263
The loop should look like this

dim ws as new notesuiworkspace
dim note as NotesDocument
dim item as NotesItem
set note = ws.CurrentDocument.Document
For i = 1 to note.TotalMans(0)
 Set item = note.GetFirstItem( "Man" & cstr(i) )
 v = item.Values(0)
Next i

~Hemanth
0
 
LVL 2

Author Comment

by:kalios
ID: 11820788
Hi Hemanth,

This is what I've so far

Dim k As Integer
Dim MTNItem As NotesItem
Set MTNItem = NCdoc.GetFirstItem("MTN")
      
For k = 1 To doc.TotalMans(0)
      Call MTNItem.AppendToTextList("doc.MAN"+Cstr(k)+ Cstr((0)))            
Next

but i get a error at Call MTNItem.AppendToTextList("doc.MAN"+Cstr(k)+ Cstr((0)))            
object variable not set.

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 11821668
hold on.. what you are doing is not right.

First you have to prepare the item name and then get item handle and then get the value

I will try to rewrite your code and see if it works

Dim k As Integer
Dim MTNItem As NotesItem
Set MTNItem = NCdoc.GetFirstItem("MTN")
     
For k = 1 To doc.TotalMans(0)
      Call MTNItem.AppendToTextList(NCdoc.GetItemValue("Man" & cstr(k))(0))
Next
0
 
LVL 2

Author Comment

by:kalios
ID: 11821909
Hemanth it does not work with above code: It says object variable not set.

Ok Here is what I've as per your first suggestion. This works . However it is

Dim k As Integer
Dim MTNItem As NotesItem
For k = 1 To doc.Totmans(0)
    Set MTNItem = doc.GetFirstItem( "Man" & Cstr(k) )
    NCdoc.MTN = MTNItem.Values(0)                        
Next

The above works fine. However, each time it is replacing Ncdoc.MTN value. I want to append to NCdoc.MTN.
NCdoc.MTN = MTNItem.Values(0)  should be changed here.

please advise
thanks
Kalios
0
 
LVL 2

Author Comment

by:kalios
ID: 11823697
OK got it....here it is

                                                Dim k As Integer
                  Dim MTNItem As NotesItem
                  Dim MANItem As NotesItem
                  Dim NMAN As String
                  
                  For k = 1 To doc.Totmans(0)
                        Set MTNItem = doc.GetFirstItem( "MAN" & Cstr(k) )
                        Let NMAN$ = MTNItem.Values(0)                        
                        Set MANItem = NCdoc.GetFirstItem("MTN")
                        Call MANItem.AppendToTextList(NMAN$)
                  Next

0
 
LVL 19

Expert Comment

by:madheeswar
ID: 11827371
Kalios,
What is the difference between my code and the code which u used?

Do u think my code is not performing well?

-Thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now