The following works ,but it seems clumsy

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

adspmoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HemanthaKumarCommented:
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
qwaleteeCommented:
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
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

adspmoAuthor Commented:
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
HemanthaKumarCommented:
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
qwaleteeCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.