Announcement

Collapse
No announcement yet.

Trying to Create Variable

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

  • Rvtravlr
    replied
    Thanks, everyone. Appreciate it!

    Leave a comment:


  • ewkearns
    replied
    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.

    Leave a comment:


  • paul
    replied
    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

    Leave a comment:


  • Guest
    Guest replied
    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.

    Leave a comment:


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

    Leave a comment:


  • ewkearns
    replied
    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?

    Leave a comment:


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

    Leave a comment:


  • BME
    replied
    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).

    Leave a comment:


  • BME
    replied
    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...

    Leave a comment:


  • Rvtravlr
    replied
    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.

    Leave a comment:


  • Rvtravlr
    replied
    I want to store a decimal to PT.

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

    Leave a comment:


  • Uncle Michael
    replied
    Do you declare 'PT'? (Dim PT As Object)

    Leave a comment:


  • Rvtravlr
    started a topic Trying to Create Variable

    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.
Working...
X