Solved

For loop in Lotus Script

Posted on 2004-08-16
8
470 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 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
Independent Software Vendors: 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

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…
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

732 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