Solved

The following works ,but it seems clumsy

Posted on 2003-11-17
6
273 Views
Last Modified: 2013-12-18
HI

I finally have the logic worked out on this damn thing.

Here is what works I am sure it can be sweetened up

What do you think

Regards

James


Sub Approved
      
      Dim ws As New NotesUIWorkspace
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim doc As NotesDocument, note As notesdocument
      Dim view As NotesView
      Set note = ws.CurrentDocument.Document
      Set db = session.CurrentDatabase
      Set view = db.GetView( "AvailHol")
      If view Is Nothing Then
            Msgbox "Cannot find view"
            Exit Sub
      End If
      If note.HasItem("RequesterName") Then
            Set doc = view.GetDocumentByKey(note.RequesterName(0)) ' KEY Value passed to view
      End If
      
      If Not doc Is Nothing Then
            
            If note.type(0) = "Vac" And  Month(note.StartDate(0)) >6 Then
                  tmpNewDaysTotal = note.NewDaysTotal(0)    
                  tmpAllowanceAH_1 = tmpNewDaysTotal + doc.AllowanceAH_1(0)
                  tmpAllowanceAH_2 = doc.allowanceAH_2(0) - tmpNewDaysTotal
                  doc.AllowanceAH_1 = tmpAllowanceAH_1
                  doc.AllowanceAH_2 = tmpAllowanceAH_2
                  doc.totalAH_1 = doc.CarriedOverAH_1(0) + doc.AllowanceAH_1(0)
                  doc.totalAH_2 = doc.CarriedOverAH_2(0) + doc.AllowanceAH_2(0)
                  Goto SaveIt
                  
            Else
                  If Month(note.StartDate(0)) < 6 And note.type(0) = "Vac" Then
                        If note.newdaystotal(0)  =< doc.CarriedOverAH_2(0) Then
    REM If doc.CarriedOverAH(0)>= 1 And doc.CarriedOverAH(0) <= 5 Then
                              doc.CarriedOverAH_1 = doc.CarriedOverAH_1(0) + note.NewDaysTotal(0)
                              doc.CarriedOverAH_2 = doc.CarriedOverAH(0) - note.NewDaysTotal(0)
                              doc.totalAH_1 = doc.CarriedOverAH_1(0) + doc.AllowanceAH_1(0)
                              doc.totalAH_2 = doc.CarriedOverAH_2(0) + doc.AllowanceAH_2(0)
                              Goto SaveIt
                              
                        Else
                              If (doc.CarriedOverAh_2(0) <> 0)  And (note.newdaystotal(0)  > doc.CarriedOverAH_2(0)) Then
                                    tmpCarriedOverAH_2 = doc.CarriedOverAH_2(0)
                                    tmpNewDay = note.newdaystotal(0) - tmpCarriedOverAH_2
                                    tmpAllowanceAH_2 = doc.AllowanceAH_2(0) - tmpNewDay
                                    tmpAllowanceAH_1 = doc.AllowanceAH_1(0) + tmpNewDay
                                    doc.CarriedOverAH_1 = doc.CarriedOverAH_1(0) + tmpCarriedOverAH_2
                                    doc.CarriedOverAH_2 = 0
                                    doc.AllowanceAH_1 = tmpAllowanceAH_1
                                    doc.AllowanceAH_2 = tmpAllowanceAH_2
                                    doc.totalAH_1 = doc.CarriedOverAH_1(0) + doc.AllowanceAH_1(0)
                                    doc.totalAH_2 = doc.CarriedOverAH_2(0) + doc.AllowanceAH_2(0)
                                    
                              Else
                                    If doc.CarriedOverAH_2(0) = 0 Then
                                          tmpNewDaysTotal = note.NewDaysTotal(0)    
                                          tmpAllowanceAH_1 = tmpNewDaysTotal + doc.AllowanceAH_1(0)
                                          tmpAllowanceAH_2 = doc.allowanceAH_2(0) - tmpNewDaysTotal
                                          doc.AllowanceAH_1 = tmpAllowanceAH_1
                                          doc.AllowanceAH_2 = tmpAllowanceAH_2
                                          doc.totalAH_1 = doc.CarriedOverAH_1(0) + doc.AllowanceAH_1(0)
                                          doc.totalAH_2 = doc.CarriedOverAH_2(0) + doc.AllowanceAH_2(0)
                                          Goto SaveIt
                                    End If
                              End If
                        End If
                  End If
            End If
            
            If note.type(0) = "Per" Then
                  tmpPersonalDaysAH_2 =doc.PersonalDaysAH_2(0) - note.NewDaysTotal(0)
                  tmpPersonalDaysAH_1 = note.NewDaysTotal(0)
                  doc.PersonalDaysAH_2 = tmpPersonalDaysAH_2
                  doc.PersonalDaysAH_1 = tmpPersonalDaysAH_1
                  Goto SaveIt
            End If
            
            If note.type(0) = "WFH" Then
            End If
            
SaveIT:
            doc.ComputeWithForm True, False  
            doc.save True, False
      Else
            Msgbox "No leave document found for this employee"
      End If
End Sub

0
Comment
Question by:adspmo
  • 3
  • 2
6 Comments
 
LVL 24

Accepted Solution

by:
HemanthaKumar earned 125 total points
ID: 9767088
There is nothing here to sweeten it as you are doing some calc...But anyway if you want to sweeten it up then add some remarks on top of each if condition that why you are doing that check and

~Hemanth
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9767113
Also in this if condition

 If note.HasItem("RequesterName") Then
          Set doc = view.GetDocumentByKey(note.RequesterName(0)) ' KEY Value passed to view
 End If

You don't accomodate the failure condition like this

 If note.HasItem("RequesterName") Then
          Set doc = view.GetDocumentByKey(note.RequesterName(0)) ' KEY Value passed to view
 ELse
          Msgbox "Required field RequesterName missing"
          Exit sub
 End If
0
 
LVL 31

Assisted Solution

by:qwaletee
qwaletee earned 125 total points
ID: 9768165
Well, as I'ev said before, more descriptive names than note and doc... those woudl be fine if there was only one of them.
You could take each block in teh IF and make it a subroutine, so that it is more readable and the logic flows easily, e.g.,


if note.type(0) = "vac" and month(note,startdate(00) >= 6 Then
  assignDaysInoringCarryOver
Else
....

Sub assignDaysIgnoringCarryOver
               tmpNewDaysTotal = note.NewDaysTotal(0)    
               tmpAllowanceAH_1 = tmpNewDaysTotal + doc.AllowanceAH_1(0)
               tmpAllowanceAH_2 = doc.allowanceAH_2(0) - tmpNewDaysTotal
               doc.AllowanceAH_1 = tmpAllowanceAH_1
               doc.AllowanceAH_2 = tmpAllowanceAH_2
               doc.totalAH_1 = doc.CarriedOverAH_1(0) + doc.AllowanceAH_1(0)
               doc.totalAH_2 = doc.CarriedOverAH_2(0) + doc.AllowanceAH_2(0)
End Sub
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!

 

Author Comment

by:adspmo
ID: 9770707
I was thinking about subroutines or would it functions as from what I understand functions return a value.WOuld thta value be singular or could it be multiple.


Thanks for the other ideas

James
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9771408
Yes, functions return values and  mostly replace all repetitive tasks. But in your case each condition lead to a different set of calculations. If you were using same kind of calculations all over the place then you can write a function and call it accordingly.
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9773219
HemanthaKumar,
> If you were using same kind of calculations all over the place then you can write a function
I soetimes write subs or fnctions even if they get called once, if it helps make the code readabke.  That's what I was suggesting here.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
I need to install a client Lotus Domino in MAC BOOK AIR 4 96
Domino Lotus Notes Client 4 73
Migration Lotus to Exchange 2016 4 221
DNS error assumed 8 87
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…
This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
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…

730 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