Announcement

Collapse
No announcement yet.

Trying to find a solution for array is empty condition

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Trying to find a solution for array is empty condition

    I am retrieving events from my google calendar via a BLGdata function. I am trying to have a condition in case there are no events. But I am getting errors, looks like it doesn't like the = ""
    The code which generates the error must be
    If allEvents = ""

    This is the offending code (the part which generates the error)

    Code:
    Const ScriptName As String = "SendCalEvents"
     
        Dim allEvents As Object()
     
    allEvents = hs.PluginFunction("BLGData", "", "GetCalendarEventsForXDays", new Object(){"[EMAIL="xxx@gmail.com","xxx@gmail.com",7"]xxx@gmail.com","xxx@gmail.com",7[/EMAIL]})
     
        EmailBody = "Next calendar events " & VbCrLf & VbCrLf
    
     If allEvents = ""      ' I also tried  If allEvents = 0
     
        EmailBody =   "*** no events in this period ***"
     End If 
     
    For Each ev As Object In allEvents


    These are the errors in the log:

    Nov-06 16:03:24 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\SendCalEvents.vb: Operator '=' is not defined for types '1-dimensional array of Object' and 'Integer'.
    Nov-06 16:03:24 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\SendCalEvents.vb: Namespace or type specified in the Imports 'System.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
    Last edited by mikee123; November 6, 2017, 11:36 AM.

    #2
    You can try and test if the array boundaries are in existence, that's my preferred method but there are probably others. This works on the principle it is a single dimension array which I am sure it would be.

    Code:
    If allEvents.GetUpperBound(0) = 0 
        EmailBody =   "*** no events in this period ***"
     End If
    And see how you get on...

    Comment


      #3
      No error message with the change, but the result is

      Next calendar events

      ===End of report===


      So the condition is not triggering as events emoty


      Code:
      If allEvents.GetUpperBound(0) = 0
          
          EmailBody = "*** no events in this period ***"
      
      Else
      
          EmailBody = "Next calendar events " & VbCrLf & VbCrLf
      
      End If
      
              For Each ev As Object In allEvents
              
                 
                 'hs.writelog("Info", ev.StartDate & " " & ev.StartTime & " "& ev.Name)
      
                 EmailBody = EmailBody & ev.StartDate & " " & ev.StartTime & " " & ev.Name & VbCrLf
      
                 calevents = calevents  & ev.StartDate & " " & ev.StartTime & " " & ev.Name & "<br>"
      
      
          Next
      
      
                 EmailBody = EmailBody & VbCrLf & "===End of report==="

      Comment


        #4
        Originally posted by mikee123 View Post
        No error message with the change, but the result is
        OK well it shows that the array has something in it (however not running the plugin I don't know how it was written, you could get an item back saying no events which would report as having an entry. What does this do, test it for no events, one event and more than one and see what the log entry says.

        Code:
        hs.writelog("", "I have: " & allEvents.GetUpperBound(0))
        
        If allEvents.GetUpperBound(0) = 0
            
            EmailBody = "*** no events in this period ***"
        
        Else
        
            EmailBody = "Next calendar events " & VbCrLf & VbCrLf
        
                For Each ev As Object In allEvents
                
                   
                   'hs.writelog("Info", ev.StartDate & " " & ev.StartTime & " "& ev.Name)
        
                   EmailBody = EmailBody & ev.StartDate & " " & ev.StartTime & " " & ev.Name & VbCrLf
        
                   calevents = calevents  & ev.StartDate & " " & ev.StartTime & " " & ev.Name & "<br>"
        
        
            Next
        
        End If
        
                   EmailBody = EmailBody & VbCrLf & "===End of report==="

        Comment


          #5
          The result was I have -1

          Changing If allEvents.GetUpperBound(0) = 0 to If allEvents.GetUpperBound(0) = -1

          And it seems to work now

          Comment

          Working...
          X