Get a Jumpstart with our Sample Apps
Results 1 to 6 of 6

Thread: Help - Looping through namespace (global) variables...

  1. #1
    Member SNusa's Avatar
    Real Name
    Robert Tupper
    Join Date
    Dec 2007
    Location
    Northeast, USA
    Posts
    893

    Default Help - Looping through namespace (global) variables...

    As a learning project, am working with variables & scope.
    Can anyone tell me what is wrong with this function?
    (I assume problem is in red text area, but thus far have been unable to fix)

    FUNCTION ShowGlobalVars AS C ( )

    dim pGlobalVars as p = global_variables()
    dim cGlobalValues as c
    cGlobalValues = ""

    for each foo in pGlobalVars
    cGlobalValues = cGlobalValues + " " + *GlobalVars.value
    next


    ShowGlobalVars = cGlobalValues
    END FUNCTION

    *Amongst many other small mods, I tried substituting foo for GlobalVars here.

    I am trying to dislpay all the global variables on a forms field using the "Set 'value' property of field" action script.
    (and trying to specify the function as the expression)

    The initial creation of the function, saves without any problem. But upon attaching the function to a buttons on_push event, I run into a problem, and Alpha won't let me finish.

    When I try to close the parentheses on the function I immediately get an error and the action script won't save. The debugger opens and an error is immediately displayed. (Before I even save or run the form.)

    Here is the error:
    Property not found (& debugger stops @ the "next" statement in the code.)

    After exiting the debugger, I receive a second warning that the expression does not evaluate to a character value.
    I can't tell if the error is due to improper use of the for statement, improper reference to the global variable pointer, or the possibility of the global variables not being instantantiated during action script building. (since the form is only being created)

    Any help would be appreciated.
    Last edited by SNusa; 02-19-2009 at 05:40 PM. Reason: clarification
    Robert T. ~ "I enjoy manipulating data... just not my data."
    It's all about the "framework." (I suppose an "a5-induced" hard drive crash is now in order?)
    RELOADED: My current posting activity here merely represents a "Momentary Lapse Of Reason."

  2. #2
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    24,695

    Default Re: Help - Looping through namespace (global) variables...

    You can get a character list of global_variables with

    GlobalValues = strtran_multi(PROPERTY_TO_STRING(global_variables()),"<"+crlf()+">","")
    ? globalvalues
    = showglobalvars=
    test="ABC"

    Note that it also returns the names of user defined functions.

    Just found another way....

    Code:
    ? user_variables_enum(global_variables() )
    = test
    Last edited by Stan Mathews; 02-19-2009 at 06:10 PM.

  3. #3
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    24,695

    Default Re: Help - Looping through namespace (global) variables...

    The problem with your function is that the

    for each ..... next control structure requires a CR-LF delimited list, an array, or a collection.. You were feeding it a pointer variable.

    Code:
    FUNCTION showglobalvars AS C ( )
    dim pGlobalVars as p = global_variables()
    dim cGlobalValues as c
    cGlobalValues = ""
    cGlobalValues = properties_enum(pGlobalVars)
    ShowGlobalVars = cGlobalValues
    END FUNCTION

  4. #4
    "Certified" Alphaholic G Gabriel's Avatar
    Real Name
    G. Gabriel
    Join Date
    Oct 2004
    Posts
    7,182

    Default Re: Help - Looping through namespace (global) variables...

    Quote Originally Posted by SNusa View Post
    I can't tell if the error is due to improper use of the for statement, improper reference to the global variable pointer, or the possibility of the global variables not being instantantiated during action script building.
    The whole darn thing is improper! but I don't fault you, it's a subtle difference.
    Those variables are POINTERS.... even though they are spitted out by alpha as a list, they are not. They POINT to the variables, i.e. for instance when you type ?global_variable() in your IW, you are asking alpha to go and find what global variables are out there and what are their values.
    Your function is attempting to process a list:
    dim pGlobalVars as p = global_variables()
    dim cGlobalValues as c
    cGlobalValues = ""
    for each foo in pGlobalVars 'No way! in order to make this work, you need to take the "list" presented by alpha and make alpha understand that you want to reference the variables. In other words, you need to use something like eval()
    cGlobalValues = cGlobalValues + " " + *GlobalVars.value 'this is immaterial, but if cGlobalValues="", then this part:cGlobalValues + " " + will add up to blank.
    GlobalVars.value you can't use .value here. ".value" is a property of an object on a form, not a property of a variable.

    ShowGlobalVars = cGlobalValues
    END FUNCTION
    I am trying to dislpay all the global variables on a forms field using the "Set 'value' property of field" action script.
    I am not sure what do you mean?

  5. #5
    Member SNusa's Avatar
    Real Name
    Robert Tupper
    Join Date
    Dec 2007
    Location
    Northeast, USA
    Posts
    893

    Default Re: Help - Looping through namespace (global) variables...

    Thanks everyone.
    I have learned much via this thread - gained much insight.
    Had it not been for the quirks in the a5 gui, I never would have asked.
    In retrospect, I'm glad I did.
    Robert T. ~ "I enjoy manipulating data... just not my data."
    It's all about the "framework." (I suppose an "a5-induced" hard drive crash is now in order?)
    RELOADED: My current posting activity here merely represents a "Momentary Lapse Of Reason."

  6. #6
    Member SNusa's Avatar
    Real Name
    Robert Tupper
    Join Date
    Dec 2007
    Location
    Northeast, USA
    Posts
    893

    Default Re: Help - Looping through namespace (global) variables...

    UPDATE:

    Much relevant information re" FOR EACH constructs, lists and ENUM methods found here: http://msgboard.alphasoftware.com/al...ble-quot/page2
    Robert T. ~ "I enjoy manipulating data... just not my data."
    It's all about the "framework." (I suppose an "a5-induced" hard drive crash is now in order?)
    RELOADED: My current posting activity here merely represents a "Momentary Lapse Of Reason."

Similar Threads

  1. global variables
    By Mark Lucas in forum Alpha Five Version 5
    Replies: 5
    Last Post: 04-09-2004, 11:12 PM
  2. where are my global variables?
    By Marion Wiffen in forum Alpha Five Version 5
    Replies: 5
    Last Post: 12-07-2003, 06:42 AM
  3. Global Variables
    By Bob Whitaker in forum Alpha Five Version 5
    Replies: 2
    Last Post: 10-08-2002, 10:31 AM
  4. Global variables - can't see them
    By Lowell Wardlow in forum Alpha Five Version 4
    Replies: 7
    Last Post: 09-15-2001, 11:02 AM
  5. Variables variables global, session or layout?
    By Greg Fong in forum Alpha Five Version 4
    Replies: 4
    Last Post: 07-11-2001, 03:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •