?
Solved

For loop in Lotus Script

Posted on 2004-08-16
8
Medium Priority
?
491 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 160 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 240 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

762 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