Announcement

Collapse
No announcement yet.

Trying to Create Variable

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

    Trying to Create Variable

    I'm using this code and the Catch never evaluates. Any suggestions?

    PHP Code:
    Try
    PT hs.GetVar("LRPT")
    hs.WriteLog("LR""GetVar Error")

    Catch 
    ex As Exception
    hs
    .CreateVar("LRPT")
    hs.SaveVar("LRPT"0)
    hs.WriteLog("LR""Exception" ex.ToString)

    End Try 

    The error I am getting is that LRPT is not defined



    I am trying to create a global variable and would appreciate any help.
    Michael

    #2
    Do you declare 'PT'? (Dim PT As Object)
    Mike____________________________________________________________ __________________
    HS3 Pro Edition 3.0.0.548, NUC i3

    HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | X10: XTB-232, -IIR | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

    Comment


      #3
      I want to store a decimal to PT.

      I’ve tried Dim PT as single but will try object.
      Michael

      Comment


        #4
        This is the error I am getting:

        Aug-05 6:47:20 PM Error A call was made to save a global variable (LRPT) but that global variable has not been defined.
        Aug-05 6:47:20 PM PT 0
        Aug-05 6:47:20 PM LR GetVar Error
        Aug-05 6:47:20 PM Warning A call was made to retrieve a global variable (LRPT) but that global variable has not been defined.

        Michael

        Comment


          #5
          It seems you are trying to get the global variable LRPT, which doesn't exist. Have you created this one elsewhere?

          I believe you need to create a global variable using hs.CreateVar, or within the HS GUI

          Edit: Just realized that is what you are trying to do within the catch...

          Comment


            #6
            I'm not very familiar with PHP, but more so other languages...

            Could it be that the catch isn't triggered because it "only" gives a warning?

            And that only the first line after the catch actually belongs to the catch, as you are not using brackets (try { something } catch { something }.

            The Save is called as the next line after the catch - and that throws an error (which is not catched).

            Comment


              #7
              I've experienced the same issue. I now create all varialbles that I use in scripts in my Startup.vb script.
              tenholde

              Comment


                #8
                Originally posted by tenholde View Post
                I've experienced the same issue. I now create all varialbles that I use in scripts in my Startup.vb script.
                ALL variables? Or does this create a global variable?
                HomeSeer Version: HS3 Pro Edition 3.0.0.500
                Operating System: Microsoft Windows 10 Pro - Work Station

                Enabled Plug-Ins:
                2.1.0.119: AmbientWeather | 3.0.21.0: BLLock | 2.0.24.0: BLUPS | 1.3.6.0: Device History | 3.0.0.56: EasyTrigger | 3.1.0.7: MeiHarmonyHub | 3.0.6681.34300: UltraCID3 | 3.0.6644.26753: UltraLog3 | 3.0.6554.33094: UltraMon3 | 3.0.0.91: weatherXML | 3.0.1.245: Z-Wave | 3.0.51: HS Touch Designer | 3.0.0.40 Z-Seer+

                Comment


                  #9
                  Any variable I intend to use in a script I create at startup instead of in each script
                  tenholde

                  Comment


                    #10
                    Originally posted by BME View Post
                    I'm not very familiar with PHP, but more so other languages...

                    Could it be that the catch isn't triggered because it "only" gives a warning?

                    And that only the first line after the catch actually belongs to the catch, as you are not using brackets (try { something } catch { something }.

                    The Save is called as the next line after the catch - and that throws an error (which is not catched).
                    I think you may be right on the warning vs exception (a warning won't throw an exception, so the "catch" stuff won't be run).

                    This code is typical Visual Basic, not PHP. It is not just the first line after the "catch" that is run, it is all the code between the "catch" and the "end try".

                    I also create all my globals in a startup script file, so that I do not have to deal with it later.

                    Comment


                      #11
                      Originally posted by tenholde View Post
                      Any variable I intend to use in a script I create at startup instead of in each script
                      The only issue I have with doing this is that it means you have to maintain two different scripts, for any script you work on - and if you give the script to someone they have to know to do the same. Here's what I do to create the global variable, if needed, at the start of a script:

                      Code:
                      'Setup Global Variable if needed
                      Dim Errst
                      Errst = hs.CreateVar('Foo')
                      If Errst = "" then
                          If Debug Then hs.WriteLog("MyTestScript", "DEBUG: Created Global Variable Foo")
                      End If
                      Basically I just go ahead and attempt to create it - if the variable didn't already exist it simply creates it, if it did exist, it returns something in the result (Can't recall offhand what it returns). But to make a long story short, you won't harm anything by simply attempting to create it each time you run the script - you won't re-initialize it or anything and won't lose what it holds. the if/then statement I provided is optional, that's just so you know what happened, in the log.

                      But doing this means that your script is completely self contained, that has value to me....

                      Paul

                      Comment


                        #12
                        Originally posted by tenholde View Post
                        Any variable I intend to use in a script I create at startup instead of in each script
                        Thanks.
                        HomeSeer Version: HS3 Pro Edition 3.0.0.500
                        Operating System: Microsoft Windows 10 Pro - Work Station

                        Enabled Plug-Ins:
                        2.1.0.119: AmbientWeather | 3.0.21.0: BLLock | 2.0.24.0: BLUPS | 1.3.6.0: Device History | 3.0.0.56: EasyTrigger | 3.1.0.7: MeiHarmonyHub | 3.0.6681.34300: UltraCID3 | 3.0.6644.26753: UltraLog3 | 3.0.6554.33094: UltraMon3 | 3.0.0.91: weatherXML | 3.0.1.245: Z-Wave | 3.0.51: HS Touch Designer | 3.0.0.40 Z-Seer+

                        Comment


                          #13
                          Thanks, everyone. Appreciate it!
                          Michael

                          Comment

                          Working...
                          X