1

can I set and use global variables ?

for example i go to the option panel of my database (admin mode) and i type :

let pn := 110;
void

and then i would use pn (how to call "pn" back btw ? just use pn ?) anywhere in my tables

is it possible and what is the syntax ?

thanks all

16 replies

null
    • Sean
    • 5 yrs ago
    • Reported - view

    I assume you put it in "Global script definitions". I know a couple of us tried that when release 2.5 came out and didn't have any luck.

     

    One option is to create a table for persistent variables. For example, if you had a table named GV and you wanted to access a field named pn you would access it using...

     

    record(GV, 1).pn

    • Laurent
    • 5 yrs ago
    • Reported - view

    thanks a lot sean, that's a nice alternative idea !!

    • Sean
    • 5 yrs ago
    • Reported - view

    You’re welcome Laurent. I don’t mind a work around as long as it isn’t too cumbersome and this one isn’t bad.

    • Gunther.1
    • 5 yrs ago
    • Reported - view

    Hi, you can define a user function

    function pn() do

    110

    end;

    Now you can uses this like let XX := pn() + ...

    • Laurent
    • 5 yrs ago
    • Reported - view

    thanks günther ! this is what i was looking for and i'm going to test that real soon… the question that comes next is : can i use that function to FILTER views ???

    • Sean
    • 5 yrs ago
    • Reported - view

    Günther,

    This would be considered a global constant since it is hardcoded, but I really like the possibilities of this approach.

    • Sean
    • 5 yrs ago
    • Reported - view

    Laurent,

    Why ask? Test!! 😉

    • Laurent
    • 5 yrs ago
    • Reported - view

    lol sean, i will, i just was doing something else !! here i go for it now…

    • Sean
    • 5 yrs ago
    • Reported - view

    Here's what I meant about the possibilities...

     

    function myVar(operation : text,num : number) do
    switch operation do
    case "+=":
    record(GV,1).(Number := record(GV,1).Number + num)
    case "-=":
    record(GV,1).(Number := record(GV,1).Number - num)
    case "*=":
    record(GV,1).(Number := record(GV,1).Number * num)
    case "/=":
    record(GV,1).(Number := record(GV,1).Number / num)
    end;
    record(GV,1).Number
    end

     

    This is a combination of both.

    • Laurent
    • 5 yrs ago
    • Reported - view

    and the result is… NO, can't filter columns by a function !! (i thought =pn() would have done the job, but nope)

    • Sean
    • 5 yrs ago
    • Reported - view

    Yeah, it looks like filter will not accept any kind of proxy.

    • Gunther.1
    • 5 yrs ago
    • Reported - view

    You have to take a calculated Field with pn() <compareOperation> .

    Then use yes/no in this field to select the valid entries.Bildschirmfoto 2019-03-20 um 11.01.01

    • Laurent
    • 5 yrs ago
    • Reported - view

    yes günther, that could be a work around for me, i'll think it over — thanks!

    • Choices_Software_Dean
    • 5 yrs ago
    • Reported - view

    It seems like record(GV, 1).pn is best for a single user environment. In a simultaneous multi-user environment, user two could write to the same global variable as user one, causing unexpected results.

    What would be a good way to make the the GV table per user, so each user would have their own global variables, based on their email address?

    • Laurent
    • 5 yrs ago
    • Reported - view

    you're right westy !

    • Sean
    • 5 yrs ago
    • Reported - view

    I haven't tried this, but if you add a User field to the GV table and you gave each user their own record in the GV table you could use the select statement to get the value you want. @Westy, it looks like a good modification for your user-defined function.

Content aside

  • 1 Likes
  • 5 yrs agoLast active
  • 16Replies
  • 6268Views