Question

LotusScript Error on For All statement

Asked by: jkee54

I have the following code code for calculating vacation days..  It is failing on ONLY the Forall loop, giving the error, Object Variable not set.  I looked through it and thought it was holiday not declared, but when I add Dim holiday as NotesDateTime, the code won't save because it says "alias variable was previously declared'.  Designer help says "You cannot declare a reference variable outside a ForAll statement. ".  When I rem out the Forall loop, the code runs but it doesn't calculate the days taken.

I can paste the rest of the code in if you want, but I'm only pasting in here the part that I know is failing and the declaration that applies.  Again there is no Dim for holiday, but when I put it in the code won't save, saying Data not saved due to script error, and the error is:  FORALL alias variable was previously declared: HOLIDAY

It's not DIM'd in this object or any other.  The variable TotalDays at the end is what I need.

Dim counter As Integer
Dim flag As Integer
Dim days As Integer
Dim duration() As String
Dim TotalDays As Integer
Dim count As Integer
Dim hookdoc As NotesDocument
Dim startdate As NotesDateTime
Dim enddate As NotesDateTime
      
Do While startdate.TimeDifference(enddate) <= 0   'Once we check the end date we're done!!
      flag = 0
      days = Weekday(startdate.LSLocalTime)
If days <> 1 And days <> 7 Then '                 'check for holidays
                  
      Forall holiday In hookdoc.AllHolidays
         If Cdat(holiday) = startdate.LSLocalTime Then flag=1
      End Forall
                  
      If flag =0 Then
            Redim Preserve duration(0 To counter)
            duration(counter) = startdate.LSLocalTime
            counter = counter +1
      End If
End If
Call startdate.AdjustDay(1)
Loop
  doc.TotalDays = counter
  doc.Duration = duration
  Call uidoc.Refresh
End If      

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-05-18 at 08:02:11ID21855388
Tags

lotusscript

Topic

Lotus Notes

Participating Experts
3
Points
200
Comments
21

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. EditDocument  on NotesDocument
    Hi! I'm new to Notes, and have recently come upon a very stubborn problem: I want to find a specific NotesDocument in the database (I do this via LotusScript in an Action-button - no problem there) and then let the user edit this document DIRECTLY. -Like I can do with the s...
  2. Sampling using LotusScript
    I have to do the "Sampling" to find out the degree of similarities between two or more Email(in %). I find that I can use the "doc.body" in LotusScript to find out the body text in each Email. But, I cannot separate the words into array list, such as, for ...
  3. VB collections as LotusScript collections
    This sample will go ok using VB's For Each statement). Why does LotusScript return error: Not a collection object !? Dim coll As Variant Set coll = CreateObject( "Scripting.Dictionary" ) coll.Add "a",1 coll.Add "b",2 Forall x In col...
  4. LotusScript
    Hi, I got few question to aks. 1) To convert notestime date to string is like below: Set item = isdoc.GetFirstItem( "docCreatedDate" ) Set datLotusScript = item.DateTimeValue Dim dateTime As New NotesDateTime( "04/16/96 05:36 PM" ) strDatTime = da...
  5. I am having trouble accessing embedded objects in a Notes…
    I am developing a system in which users submit information from a web browser, along with one or more file attachments. I would ideally like these files to be contained in Rich Text Fields, but with the web client & the FileUpload control, this is not possible (is it?). A...
  6. SendTo on Email with LotusScript
    I have a database that needs to send an email to a supervisor for review. I have 4 supervisors that would like to have the email sent to their administrative assistant. The other supervisors would like to get the notification. I have tried the following code and it will fail....

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: sjef_bosmanPosted on 2006-05-18 at 08:18:54ID: 16709591

Whatever the reason is, be it a globally defined variable holiday or anything else, you can't declare a foral-variable. Why not change the code to
     Forall hol In hookdoc.AllHolidays
        If Cdat(hol) = startdate.LSLocalTime Then
            flag=1
            Exit Forall
         End If
     End Forall

PS Your calculation is effective but rather crude, wouldn't you say?

 

by: sjef_bosmanPosted on 2006-05-18 at 08:43:39ID: 16709852

Here's some code you might be interested in:

    http:Q_21382610.html "Calculating Time Difference"

 

by: jkee54Posted on 2006-05-18 at 09:10:09ID: 16710148

I don't get it, it looks like youare "Exit Forall" -ing twice - isn't that the same code I sent except for that flag = 1 is on the next line and  the extra Exit Forall?

Do you have a better suggestion?

 

by: jkee54Posted on 2006-05-18 at 09:18:34ID: 16710231

I have looked at similar code, but I only have to calculate days, not hours, and I have to accomodate for holidays, which are stored in an array on a form.

 

by: sjef_bosmanPosted on 2006-05-18 at 09:24:46ID: 16710300

There's an Exit Forall and an End Forall. As soon as you have found that it's a holiday, and you set flag=1, there's no point in continuing the search. Hence the Exit Forall, to break the loop (like a break-statement in C).

You like NotesDateTime objects? I don't, and theres hardly ever any reason to use them. A Variant variable will do, by definition the integral part of the double value indicates the day, whereas the fraction indicates the hours/minutes/seconds on the day itself. Somewhat rewritten, one gets this:

    Dim counter As Integer
    Dim IsHoliday As Integer
    Dim days As Integer
    Dim duration() As String
    Dim TotalDays As Integer
    Dim count As Integer
    Dim hookdoc As NotesDocument
    Dim startdate As NotesDateTime
    Dim enddate As NotesDateTime
    Dim tday As Variant ' or Double
    Dim eday As Variant ' or Double
         
    tday= startdate.LSLocalTime
    eday= enddate.LSLocalTime
    Do While tday<=eday   'Once we check the end date we're done!!
         IsHoliday= False
         days = Weekday(tday)
        If days <> 1 And days <> 7 Then '                 'check for holidays
                       
             Forall holiday In hookdoc.AllHolidays
                If Cdat(holiday) = tday Then
                    IsHoliday= True
                    Exit Forall
                End If
             End Forall
                       
             If Not IsHoliday Then
                  Redim Preserve duration(0 To counter)
                  duration(counter) = tday
                  counter = counter +1
             End If
        End If
        tday= tday + 1
    Loop
    doc.TotalDays = counter
    doc.Duration = duration
    Call uidoc.Refresh

 

by: marilyngPosted on 2006-05-18 at 09:33:55ID: 16710387


Hi jkee54.. I don't see anywhere where hookdoc is instantiated.  I assume that it's supposed to be a document containing the holidays, so it's going to be in a non-existant view that you didn't instantiate either.    At any rate, I'm not at a computer with Notes on it, so I did this in Notepad.. if you get errors,  post them here, and I'm sure the EE masses will reply and trounch on the solution to make it their own :)  (Or you can wait until later today, and I will fix)


'I assume you are instantiating
Dim session as New NotesSession
Dim ws as New NotesUiWorkspace
Dim db as NotesDatabase
set db = session.currentdatabase
Dim uidoc as Notesuidocument
set uidoc = ws.currentdocument
set doc = uidoc.document

Dim counter As Integer
Dim flag As Integer
Dim days As Integer
Dim duration() As String
Dim TotalDays As Integer
Dim count As Integer
'What is Hookdoc?  Is this the same as Doc?
Dim hookdoc As NotesDocument
Dim startdate As NotesDateTime
Dim enddate As NotesDateTime

'Somewhere in here you have to declare the view and document lookup.

Dim view as NotesView
set view = db.getview("This View Name")
if not view is nothing then
  set hookdoc = view.getdocumentbykey("Whateverthisholidaykeyis",true)
  if hookdoc is nothing then
    set hookdoc = view.getfirstdocument
  end if
else
  msgbox "Sorry, lookup view cannot be found for hookdoc"
  exit sub
end if

     
Do While startdate.TimeDifference(enddate) <= 0   'Once we check the end date we're done!!
     flag = 0
     days = Weekday(startdate.LSLocalTime)

If days <> 1 And days <> 7 Then '                 'check for holidays

if not hookdoc is nothing then
  if hookdoc.hasItem("AllHolidays") then
   if len(hookdoc.AllHolidays(0)) > 0 then
    Forall holiday In hookdoc.AllHolidays
        If Cdat(holiday) = startdate.LSLocalTime Then flag=1
     End Forall
    end if
 end if
else
  msgbox "Sorry, can't find the holidays document, will skip holidays"
end if
               
     If flag =0 Then
          Redim Preserve duration(0 To counter)
          duration(counter) = startdate.LSLocalTime
          counter = counter +1
     End If
End If

Call startdate.AdjustDay(1)

Loop

  doc.TotalDays = counter
  doc.Duration = duration
  Call uidoc.Refresh

End If  

 

by: HemanthaKumarPosted on 2006-05-18 at 10:37:16ID: 16710976

jkee54,

Ther error says everything...

Post the entire code where forall section is present , so that we can get a better idea.

Second global variables doesn't matter with forall...it is always private as far as 'forall' is concerned

~Hemanth

 

by: jkee54Posted on 2006-05-18 at 10:53:55ID: 16711122

OK, it is long, so I tried to shortcut.  Here is the entire code:

Sub CalculateDays
      Dim session As New NotesSession
      Dim workspace As New NotesUIWorkspace
      Dim doc As NotesDocument
      Dim uidoc As NotesUIDocument
      Dim startdate As NotesDateTime
      Dim enddate As NotesDateTime
      Dim startitem As NotesItem
      Dim enditem As NotesItem
      Dim counter As Integer
      Dim flag As Integer
      Dim days As Integer
         Dim hookdoc As NotesDocument
      Dim hookview As NotesView
      Dim db As NotesDatabase
      Dim duration() As String
      Dim TotalDays As Integer
      Dim count As Integer
      
      Set db = session.CurrentDatabase
      Set uidoc = workspace.CurrentDocument
      Set doc = uidoc.Document
      If workspace.DialogBox("EDChange", True, True, False, False, False, False, "Please Select the Beginning and Ending Dates.") Then
            doc.Counter = 2
            
          'if either field is empty don't do calculations and blank out days field.
            If doc.StartDate(0) = "" Or doc.EndDate(0) = "" Then
                  doc.TotalDays = ""
                  End
            End If
            Set startitem = doc.GetFirstItem("StartDate")
            Set startdate = startitem.DateTimeValue
            Set enditem = doc.GetFirstItem("EndDate")
            Set enddate = enditem.DateTimeValue
            counter = 0
            
          'Make sure that the start date is before the end date
      If startdate.TimeDifference(enddate) > 0 Then
            Messagebox "The Start Date cannot come after the End Date.", 16, "Incorrect Dates"
            Call uidoc.GoToField("StartDate")
            End
      End If
            
          'Get the list of Holidays
            Set hookview = db.GetView("Holidays")
            Set hookdoc = hookview.GetDocumentByKey("Holidays",True)
            
            
Do While startdate.TimeDifference(enddate) <= 0   'Once we check the end date we're done!!
            flag = 0
            days = Weekday(startdate.LSLocalTime)
      If days <> 1 And days <> 7 Then '                 'check for holidays
                        
            Forall holiday In hookdoc.AllHolidays
                  If Cdat(holiday) = startdate.LSLocalTime Then flag=1
            End Forall
                        
            If flag =0 Then
            Redim Preserve duration(0 To counter)
            duration(counter) = startdate.LSLocalTime
            counter = counter +1
      End If
                                      End If
            Call startdate.AdjustDay(1)
Loop
            doc.TotalDays = counter
            doc.Duration = duration
            Call uidoc.Refresh
      End If
End Sub

 

by: marilyngPosted on 2006-05-18 at 12:40:12ID: 16712191

Set hookview = db.GetView("Holidays")
          Set hookdoc = hookview.GetDocumentByKey("Holidays",True)

You need to check if hookdoc is something.. see my code for this..

if hookdoc is  nothing then
  ' do something.. declare a default, or exit, or skip over the stuff that depends on hookdoc.
else
 'Continue with hookdoc
end if

I'm guessing either the view doesn't exist, or the view first column isn't sorted, or the first column is "holidays" rather than "Holidays."

 

by: sjef_bosmanPosted on 2006-05-18 at 14:27:44ID: 16713180

Or there is no field AllHolidays in that document.

    If Not(hookdoc Is Nothing) Then
        If hookdoc.HasItem("AllHolidays") Then
             Forall holiday In hookdoc.AllHolidays
                If Cdat(holiday) = tday Then
                    IsHoliday= True
                    Exit Forall
                End If
             End Forall
        End If
    End If

If there's only one document in the Holidays-view, ever, then just a GetFirstDocument would do. Better still, make a it ProfileDocument and get rid of the view.

 

by: marilyngPosted on 2006-05-18 at 19:50:33ID: 16714814

Ok, confused... I feel like I'm talking but everyone is skipping over me.. sjef, I said that in my first post when you didn't see that hookdoc or hookview might throw an error.

At any rate, here is  my suggested changes implemented in your code:

Dim session As New NotesSession
      Dim workspace As New NotesUIWorkspace
      Dim doc As NotesDocument
      Dim uidoc As NotesUIDocument
      Dim startdate As NotesDateTime
      Dim enddate As NotesDateTime
      Dim startitem As NotesItem
      Dim enditem As NotesItem
      Dim counter As Integer
      Dim flag As Integer
      Dim days As Integer
      Dim hookdoc As NotesDocument
      Dim hookview As NotesView
      Dim db As NotesDatabase
      Dim duration() As String
      Dim TotalDays As Integer
      Dim count As Integer
      
      Set db = session.CurrentDatabase
      Set uidoc = workspace.CurrentDocument
      Set doc = uidoc.Document
      If workspace.DialogBox("EDChange", True, True, False, False, False, False, "Please Select the Beginning and Ending Dates.") Then
            doc.Counter = 2
            
          'if either field is empty don't do calculations and blank out days field.
            If doc.StartDate(0) = "" Or doc.EndDate(0) = "" Then
                  doc.TotalDays = ""
                  End
            End If
            Set startitem = doc.GetFirstItem("StartDate")
            Set startdate = startitem.DateTimeValue
            Set enditem = doc.GetFirstItem("EndDate")
            Set enddate = enditem.DateTimeValue
            counter = 0
            
          'Make sure that the start date is before the end date
            If startdate.TimeDifference(enddate) > 0 Then
                  Messagebox "The Start Date cannot come after the End Date.", 16, "Incorrect Dates"
                  Call uidoc.GoToField("StartDate")
                  End
            End If
            
          'Get the list of Holidays
            Set hookview = db.GetView("Holidays")
            'Added by mgl...............................................................................................
            If hookview Is Nothing Then
                  Msgbox "There is no hookview in this database.."
            Else
                  Set hookdoc = hookview.GetDocumentByKey("Holidays",True)      
            End If
            '.........................................................................................................end addition      
            
            Do While startdate.TimeDifference(enddate) <= 0   'Once we check the end date we're done!!
                  flag = 0
                  days = Weekday(startdate.LSLocalTime)
                  If days <> 1 And days <> 7 Then '                 'check for holidays
                        
                        'Added by mgl.........................................................................
                        If hookdoc Is Nothing Then
                              Msgbox "There is no holidays document in this database..."
                        Else
                              If hookdoc.HasItem("AllHolidays") Then
                                    If Len(hookdoc.AllHolidays(0))>0 Then
                                          Forall holiday In hookdoc.AllHolidays
                                                If Cdat(holiday) = startdate.LSLocalTime Then flag=1
                                          End Forall
                                    End If
                              End If                              
                        End If
                        '........................................................................................................Finished mgl.
                        If flag =0 Then
                              Redim Preserve duration(0 To counter)
                              duration(counter) = startdate.LSLocalTime
                              counter = counter +1
                        End If
                  End If
                  Call startdate.AdjustDay(1)
            Loop
            doc.TotalDays = counter
            doc.Duration = duration
            Call uidoc.Refresh
      End If

 

by: sjef_bosmanPosted on 2006-05-19 at 00:49:00ID: 16715925

:-$

 

by: marilyngPosted on 2006-05-19 at 15:37:08ID: 16722313

Oops, let's see... I summarized both sjef and my observations and made the corrections in the code.. sjef, feel free to jump in if I missed something.

 

by: sjef_bosmanPosted on 2006-05-19 at 16:01:20ID: 16722460

Wouldn't dare... Backdoor open?

 

by: HemanthaKumarPosted on 2006-05-22 at 11:52:24ID: 16736846

guys, are u and the questioner speaking the same !

He is getting forall error and you guys are talking about some field, which u are not even aware ! So what does that have to do with compile error ?

For me it looks like (usual) code corruption, Run compact and fixup on this database. If that doesn't correct the issue, recreate the form by pasting the fields and code's into this form and delete the old one. Before doing anything just take a backup for safety

 

by: sjef_bosmanPosted on 2006-05-22 at 14:16:52ID: 16737970

Read again:
> It is failing on ONLY the Forall loop, giving the error, Object Variable not set.

 

by: marilyngPosted on 2006-05-22 at 17:30:21ID: 16738964

Sorry, Heman.. not code corruption, I think.  Objects uninstantiated.

You will ALWAYS get an error on Forall d in doc.fieldname if:
         doc is nothing
         fieldname is nothing
         the contents of fieldname is empty.

The only way I know to avoid the error is:
    trap it with a handle_error
    check to see if doc is something
    check to see if doc has the field
    check to see if the field is not empty

 

by: HemanthaKumarPosted on 2006-05-23 at 11:55:21ID: 16745277

sorry , I was overlooking the question &  thought it was a compile issue.

 

by: marilyngPosted on 2006-05-23 at 15:38:57ID: 16747095

It happens :)

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...