Solved

The following works ,but it seems clumsy

Posted on 2003-11-17
6
268 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Only send email if contains "abcd" 3 147
LEI - MINUS/EXCEPT statement ability between Notes and SQL 1 93
IBM Domino web server 5 65
Lotus Notes Mailbox (Mail Forwarding) 9 49
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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…

770 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