Solved

The following works ,but it seems clumsy

Posted on 2003-11-17
6
263 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now