Announcement

Collapse
No announcement yet.

Exception has been thrown by the target of an invocation.

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

    Exception has been thrown by the target of an invocation.

    I am running the following stratightfoward script and the result is a Running script timer.vb :Exception has been thrown by the target of an invocation.
    The file extension is VB
    Any thoughts

    Thanks

    Will

    Code:
    Sub Main(ByVal Parms As Object)
    'Sub Main(parm as object)
    
    dim GrillTemp1
    dim GrillTemp2
    dim GT1_Time
    dim GT2_Time
    dim timeleft
    dim CookTime
    dim GetCookTime
    dim parse1
    dim FinalCookTime
    
    GetCookTime=hs.Devicestring(2571)
    parse1=InStrRev(GetCookTime,"is")
    FinalCookTime=Mid(GetCookTime,parse1+3,len(GetCookTime)-parse1)
    CookTime=cdbl(FinalCookTime)*3600
    TimeLeft=Cooktime-hs.TimerValue("Cook Time")
    hs.speak(cstr(Timeleft))
    GrillTemp1=cstr(hs.Devicevalue(2624))
    GrillTemp2=FinalCooktime
    hs.speak(GrillTemp1)
    
    End Sub

    #2
    Hi Will, my thoughts... I'm amazed how people just throw the piece of their code without any details and expect somebody to analyse every line of code and tell you what's wrong, like mum with little baby... Did you even search the forum? The internet?

    https://forums.homeseer.com/forum/de...atmo-in-vb-net

    If you have an exception - the answer is obvious - add exception handler....

    Sorry if I sound rude, but...

    Comment


      #3
      Also is this on Linux, Windows?

      Please add your system & O/S details to the forum setup (as shown on the left panel under my forum name).

      https://forums.homeseer.com/forum/ho...-in-your-posts
      Jon

      Comment


        #4
        Alex and Jon,

        Thanks for the feeback. I added the error catching and it was an immense help. Does any one know when calling the value of a timer ie hs.TimerValue("Cook Timer") it restarts the timer? Thanks

        Will

        Comment


          #5
          Originally posted by wkrasner View Post
          Thanks for the feeback. I added the error catching and it was an immense help. Does any one know when calling the value of a timer ie hs.TimerValue("Cook Timer") it restarts the timer? Thanks
          Will
          I hope you weren't offended, I seriously mean that you should always have exception and error handling - you can't expect that it always goes the way you expect.
          Also, for parsing I strongly recommend using regex. If you don't have regex experience - https://regex101.com/ is great - you enter your string, your regex and experiment to make it work.
          Code:
          parse1=InStrRev(GetCookTime,"is")
          FinalCookTime=Mid(GetCookTime,parse1+3,len(GetCookTime)-parse1)

          Comment


            #6
            In my plugins I even have - sounds funny - "unhandled exception handler" - beauty of .NET

            Comment


              #7
              No offense taken, thanks for the regex suggestion

              Comment

              Working...
              X