[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

For loop in Lotus Script

Posted on 2004-08-16
8
Medium Priority
?
510 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
Technology Partners: 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!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

649 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