Alpha Video Training
Page 1 of 2 12 LastLast
Results 1 to 30 of 53

Thread: $10,000 Question ~ "The foo variable"

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

    Default $10,000 Question ~ "The foo variable"

    Why does the "foo" variable keep showing up in the X-basic explorer when you least expect it?
    Where does it come from?

    You can sometimes find it in Alpha Sports, and I've seen it in other training applications too.
    I'll be working in the X-basic explorer and all of a sudden it appears. I've never been able to find out where it is actually defined.

    This has been "bugging me" for years. As I write this, I can't find it anywhere. Go figure....
    I saw it last week running the same version of a5. And I'm sure I will see it tomorrow, providing of course I conscientiously look for it.....
    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 Keith Hubert's Avatar
    Real Name
    Keith Hubert
    Join Date
    Jul 2000
    Location
    London, UK
    Posts
    6,930

    Default Re: $10,000 Question ~ "The foo variable"

    Hi Robert,

    See threads below.
    Regards
    Keith Hubert
    Alpha Guild Member
    London.
    KHDB Management Systems
    Skype = keith.hubert


    For your day-to-day Needs, you Need an Alpha Database!

  3. #3
    "Certified" Alphaholic Ted Giles's Avatar
    Real Name
    Ted Giles
    Join Date
    Aug 2000
    Location
    In the Wolds, Louth, Lincolnshire, UK
    Posts
    4,358

    Default Re: $10,000 Question ~ "The foo variable"

    And which threads would they be Keith?
    Ted Giles
    Example Consulting - UK
    .

    http://ec12.example-software.com//
    See our site for Alpha Support, Conversion and Upgrade.

  4. #4
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,310

    Default Re: $10,000 Question ~ "The foo variable"

    Ted, you gave up too easily. Keep scrolling, scrolling, scrolling.

    The message board will supply a list of threads that discuss terms in the subject line.... a handy feature that most are unaware of.

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

    Default Re: $10,000 Question ~ "The foo variable"

    FOO
    FOO Fighters?...not.
    FOO: Conventional name in programming languages for a variable that is used once and discarded.. just to serve one purpose.. a placeholder.
    Stands for: For Once Only.
    But.. you are not restricted to FOO.. you could name your variable anything you want..just as you would your kids or dogs.
    Last edited by G Gabriel; 02-01-2012 at 09:42 AM.

  6. #6
    "Certified" Alphaholic Ted Giles's Avatar
    Real Name
    Ted Giles
    Join Date
    Aug 2000
    Location
    In the Wolds, Louth, Lincolnshire, UK
    Posts
    4,358

    Default Re: $10,000 Question ~ "The foo variable"

    Quote Originally Posted by Tom Cone Jr View Post
    Ted, you gave up too easily.
    In my defense, I am suffering from logitis, caused by splitting 1½ tonnes of Ash logs with a proper lumberjack axe.
    It affected my scrolling finger.
    Thanks Tom, I have never noticed or used this before.
    Good call.
    Ted Giles
    Example Consulting - UK
    .

    http://ec12.example-software.com//
    See our site for Alpha Support, Conversion and Upgrade.

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

    Default Re: $10,000 Question ~ "The foo variable"

    Wow, "now I know & glad I asked"... Years past, I searched and searched for the variables declaration and/or usage in the Alpha database. I never did find it anywhere in the code.

    I even went as far (years ago) to ask Selwyn about the mysterious variable. ~FYI: This was the only instance I ever contacted Alpha5 regarding a non-bug issue. (I'm sure I initially made the inquiry because I suspected the "freak appearance" of this variable that "seemingly appeared from nowhere", was somehow bug related.) Long story short: He didn't have any answers for me, and indicated it probably was of little importance. After reading this thread, I guess he was right about that!


    ~From that day on, it's always "bugged me" whenever it pops up. Oddly enough, even when I was at school for Pascal programming (I know, this shows my age) not once did I run across material making reference to using a variable named "FOO!" I was thinking that "FOO" was an acronym for "FOOBAR" or "FUBAR"


    Since it doesn't appear to "come from anywhere", I suspect it must be both internally defined, and internally used by A5 program code. ~Maybe either the "Database Documentor" which I now have, or the "CDSA code utility" could reveal it's origins......
    Last edited by SNusa; 02-01-2012 at 11:59 AM.
    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."

  8. #8
    "Certified" Alphaholic MoGrace's Avatar
    Real Name
    Robin
    Join Date
    Mar 2006
    Location
    Los Angeles
    Posts
    3,683

    Default Re: $10,000 Question ~ "The foo variable"

    Thanks GG for finally explaining what FOO means! It was from the *FOR EACH() help that I finally understood what this variable was doing. Those programming techies just can't help themselves...from showing off!
    Last edited by MoGrace; 02-01-2012 at 02:53 PM. Reason: Edited to show it was a FUNCTION
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

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

    Default Re: $10,000 Question ~ "The foo variable"

    Quote Originally Posted by MoGrace View Post
    Thanks GG for finally explaining what FOO means! It was from the *FOR EACH...NEXT help that I finally understood what this variable was doing. Those programming techies just can't help themselves...from showing off!
    MoGrace: Now that I'm curious, could you point me to that link, and elaborate on you comment? ~ Thanx in advance!
    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."

  10. #10
    "Certified" Alphaholic MoGrace's Avatar
    Real Name
    Robin
    Join Date
    Mar 2006
    Location
    Los Angeles
    Posts
    3,683

    Default Re: $10,000 Question ~ "The foo variable"

    Saw it used in a script in here somewhere and so I looked it up in the Wiki I corrected my first post to show it was a function.
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

  11. #11
    Volunteer Moderator
    Real Name
    Alan Buchholz
    Join Date
    Oct 2000
    Location
    Delavan, Wisconsin
    Posts
    9,618

    Default Re: $10,000 Question ~ "The foo variable"

    Quote Originally Posted by Ted Giles View Post
    And which threads would they be Keith?
    This.... (for those who travel here again...)

    similiarthreads.PNG
    Al Buchholz
    Bookwood Systems, LTD
    Weekly QReportBuilder Webinars Thursday 1 pm CST

    Occam's Razor - KISS
    Normalize till it hurts - De-normalize till it works.
    Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
    When we triage a problem it is much easier to read sample systems than to read a mind.

  12. #12
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default Re: $10,000 Question ~ "The foo variable"

    Hi Robert,

    For the most part Alpha uses a variable named "foo" in

    • For Each foo in variablename
    • property name for a pointer variable that is assigned a value. Before any property is assigned to a pointer, it sort of can be an undefined type of pointer (as opposed to a collection, array, variable space, type). Once you assign a property to it, it becomes a variable space. So pointer.foo will often be set to a value (typically "Dummy Value") to force it to the correct type. Then other functions that work on property pointers will work.
    • event name of an XDialog button or a watch variable - this is poor programming practice IMHO
    • dummy event name of an XDialog event - Probably for Listview objects that does nothing
    • temporary variable - again poor programming practice IMHO


    Essentially, it is just a variable name they use for a variety of purposes. In general, names should be indicative of it's purpose, unless the purpose is to obfuscate what is being done, which might be for code that you don't want anyone to understand (which includes yourself).

    Using foo goes back to at least the earliest roots of the C language, and was typically used in the context of examples to mean "use the name of a variable of your choosing here"

    As I have said many times, if you want to have the least collisions with variables names that Alpha uses internally, DIM every variable and use local variables except when they need a larger scope. For others, see Variable tips here.
    Regards,

    Ira J. Perlow
    Computer Systems Design


    CSDA A5 Products
    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
    CSDA Barcode Functions

    CSDA Code Utility
    CSDA Screen Capture



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

    Default Re: $10,000 Question ~ "The foo variable"

    Hi Ira. (I was wondering whether yo were going to chime in here. - Seriously!)


    I'm understanding that the best usage of the "infamous foo variable" is for:
    • When looping through an "array of elements in an object?" ie: "For Each foo in VariableName"
      (So could I optionally use: "For Each foobar in VariableName"?)
    • For temporarily assigning a value to a pointer when you know an actual value has not yet been assigned but still need to use it's methods.

    • And I'm occasionally running into it because of this: XDialong event, probably for the Listview objects that does nothing


    PS: I'm going to place an order for your code utility this evening or tomorrow. I've never requested a trial thus far, but I know your stuff is good.... ~ Your online help documents alone provided me with a great a5 foundation/starting point. (and insight as to how a5 works from the "inside-out"

    Thank You!
    Last edited by SNusa; 02-01-2012 at 05:10 PM.
    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."

  14. #14
    "Certified" Alphaholic Clunes's Avatar
    Real Name
    Mark Pearson
    Join Date
    Jan 2010
    Location
    Brisbane, Queensland, Australia
    Posts
    1,001

    Default Re: $10,000 Question ~ "The foo variable"

    My two bobs worth (Australian for 20c) Foo was a iconic grafiti type symbol when I was growing up. see http://en.wikipedia.org/wiki/Foo_was_here It depicted the top part of a head with nose and fingers hanging over a fence while the eyes could just see over the it. It gave the impression someone was watching you or watching out for you. Dare I say that there is some sort od Ockerism in "C" that creeped into other programs like Alpha. Everytime I see foo in alpha he seems to be doing some sort of watching in the code. If you put a debug in teh events after him you see what he does for that particular code. I think he hasd been put in places to help with capturing the event as an example of what can be done.
    -----------------------------------------------
    Regards
    Mark Pearson
    mark.pearson@onestopsolutions.com.au
    Youtube channel
    Website

  15. #15
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default Re: $10,000 Question ~ "The foo variable"

    Hi Robert,

    Quote Originally Posted by SNusa View Post
    I'm understanding that the best usage of the "infamous foo variable" is for:.....
    No. Don't use foo, foobar or anything else like that. That is just a programming convention for "Fill in the Blank here"

    Use a variable name that has meaning!. Don't reuse a variable in any single piece of code unless it is a temporary variable. By using different names, when you have a program bug, it is much easier to find.

    And, if you happen to use the same name as an Alpha variable name in the same variable space, you or Alpha could overwrite the variable with different data, so it is a bad idea
    Regards,

    Ira J. Perlow
    Computer Systems Design


    CSDA A5 Products
    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
    CSDA Barcode Functions

    CSDA Code Utility
    CSDA Screen Capture



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

    Default Re: $10,000 Question ~ "The foo variable"

    Quote Originally Posted by csda1 View Post
    .......Don't use foo, foobar or anything else like that. That is just a programming convention for "Fill in the Blank here"

    Use a variable name that has meaning!. Don't reuse a variable in any single piece of code unless it is a temporary variable. By using different names, when you have a program bug, it is much easier to find.

    And, if you happen to use the same name as an Alpha variable name in the same variable space, you or Alpha could overwrite the variable with different data, so it is a bad idea
    Understood.....

    Let me rephrase my question: In Alpha, when using the FOR EACH to cycle through a collection, any variable name could conceivably work as the placeholder. In the v9 help file example, (after reviewing the FOR EACH operator)..... I noticed that Alpha ironically just happened to chose the variable foo in their example!

    My point (or question actually) was, they could have just as well used the variable foobar or widget in this example, (even though it's a bad idea) right?

    Code:
    for each foo in list if foo = "c" continue end if ui_msg_box("", foo.value) next
    Consequently, I could conceivably construct X-basic code as follows to extract field names from a table:
    (using any good name for the placeholder)

    Code:
    '***LOOP THROUGH TABLE FIELDS AND OUTPUT NAMES IN STRING
    
    FieldName as P
    vp_Table as P
    vc_AllFieldNames as C
    
    vp_Table=Table.current()
    'vp_TableName.fetch_first()
    
    FOR EACH FieldName in vp_Table
       vc_AllFieldNames = vc_AllFieldNames + chr(32) + this.Field_Name_Get()
    NEXT
    
    showvar(alltrim(vc_AllFieldnames))
    
    'NOTE:  vp_FieldName is possibly dimmed incorrectly, but regardless I could have technically used any variable
    '         name in it's place, providing it's not used elsewhere / violates scope?????
    Last edited by SNusa; 02-02-2012 at 03:05 AM.
    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."

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

    Default Re: $10,000 Question ~ "The foo variable"

    Quote Originally Posted by SNusa View Post
    My point (or question actually) was, they could have just as well used the variable foobar or widget in this example
    And then you would, or someone else would , have asked the question: why didn't they use FOO?

    FOO started in the olden days..and programmers (monkey see monkey do).. continued to use it for that purpose. Same as "Hello World"..
    This doesn't mean you can't break that mold whenever you wish.

    for each foo in list ... is the same as:
    for each Felicia in list.. or
    for each Lamat in list.. or
    for each my_dog_dingo in list
    ..
    etc.

    I don't want to pick up a fight with Ira here..and I don't see anything wrong with what he is saying as far as dimming the variable and so on..all that is fine and dandy. It's a deviation from the FOO concept and convention and I don't see any problem with that either. It will serve the purpose just fine and in Ira's mind and contentions, it's a better practice, and that's fine too.. but your question (and I want to know where is that $10,000? Or is that just a Romney bet?) has to do with FOO..who is FOO? where did he or she come from? where does he live? and why?

    FOO, or any substitute name is a unique type of "variable". It's best described as a placeholder"..it is a "variable" on the fly. In other words, alpha (or any other application for that matter) will recognize it as a placeholder, something to hold a value for a one time process with no intention of being used subsequently. Once the process is done, this placeholder is wiped out..In other words, FOO is a "Pawn".. a "punk"...a "goefer" ..doesn't even have the status of a legitimate variable..even though it is a "variable" but it is a one-time variable only meant as a placeholder.
    Last edited by G Gabriel; 02-02-2012 at 08:34 AM.

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

    Default Re: $10,000 Question ~ "The foo variable"

    Quote Originally Posted by G Gabriel View Post
    This doesn't mean you can't break that mold whenever you wish.

    for each foo in list ... is the same as:
    for each Felicia in list.. or
    for each Lamat in list.. or
    for each my_dog_dingo in list
    ..
    etc.
    Got it! Thanks.

    PS: As for the $10,000 question ~ It's an election year here in the US. You know, with false promises & all! (Seriously though, I am surprised this post received all the responses it did. As I mentioned previously, Selwyn's only response to me was he didn't know anything about it. ~ And he seems to know almost everything!)

    Funny thing is: I kept thinking (all these years after looking at the Alpha Sports database time and time again before finally "getting this down) the following:


    "What kind of company would write code and leave weird things like a "foo" variable to pop up without explanation." ~ Seeing it appear was never a confidence builder. And Selwyn's response actually scared me with regards to the actual solidness of the a5 platform. (I had encountered / documented / & reported so many legitimate bugs over the years, that after seeing this "foo" variable pop seemingly for no reason, I became wary of a5.) ~ As usual, it turns out it was just my ignorance.

    NOTE: When you learn a tool like a5 as I did, from the ground up.... You run into all sorts of oddities, bugs, and unexpected behaviors that a seasoned user would never uncover. I'm sure that's why I was turning up all these bugs, even 6 months after the version releases. (and this goes all the way back to version 8) ~ I have versions back to the mid 90's on floppy, but didn't have time / opportunity to pursue and really use them way back when.

    All my life, I've been a "bug magnet." (It's just the way it is. If there's a bug, I run into it. ~ Or is that the other way around?)


    What's really surprising is: This "foo" concept wasn't referenced once in the hundreds of hours of training videos I watched numerous times. (and took notes on) I guess I shouldn't be overly surprised, because I have yet to run into a single training video that even brushes on the concept of holding down the <shift><control> keys while launching a database to disable "auto-starts!"
    Last edited by SNusa; 02-02-2012 at 09:04 AM.
    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."

  19. #19
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default Re: $10,000 Question ~ "The foo variable"

    Quote Originally Posted by SNusa View Post
    Understood.....

    Let me rephrase my question: In Alpha, when using the FOR EACH to cycle through a collection, any variable name could conceivably work as the placeholder.
    Any variable name of the appropriate data type can be used. E.g. if stepping through an array with 10 elements, if a numeric values in the array, the placeholder must be numeric. If 10 character values, then it better be character type. 10 dates, it would need to be date type. If undefined previously at any scope level, there is an implicit dimensioning at the local level of the data type.

    Quote Originally Posted by SNusa View Post
    In the v9 help file example, (after reviewing the FOR EACH operator)..... I noticed that Alpha ironically just happened to chose the variable foo in their example!
    It's not ironic, it's as I said, a programming convention to say "fill in the blank with your own name here". As to whether you should use a professional programming convention for most non-programmers using Alpha, I'd say no, unless you said that up front.

    Quote Originally Posted by SNusa View Post
    My point (or question actually) was, they could have just as well used the variable foobar or widget in this example, (even though it's a bad idea) right?
    Yes they could have, or they could have said "Fill_in_a_name_of_your_choosing" or anything else as well. The point is to convey to a reader that they need to use their own value. I always would say clarity is preferred in naming, and foo is not it. Your fieldname variable is in the right direction, although the code is not concatonating the next value. For a character type, for each returns each line sequentially as a value for each loop

    Quote Originally Posted by SNusa View Post
    Code:
    for each foo in list if foo = "c" continue end if ui_msg_box("", foo.value) next
    The bolded part should be foo, not foo.value

    Quote Originally Posted by SNusa View Post
    Consequently, I could conceivably construct X-basic code as follows to extract field names from a table:
    (using any good name for the placeholder)

    Code:
    '***LOOP THROUGH TABLE FIELDS AND OUTPUT NAMES IN STRING
    
    FieldName as P
    vp_Table as P
    vc_AllFieldNames as C
    
    vp_Table=Table.current()
    'vp_TableName.fetch_first()
    
    FOR EACH FieldName in vp_Table
       vc_AllFieldNames = vc_AllFieldNames + chr(32) + this.Field_Name_Get()
    NEXT
    
    showvar(alltrim(vc_AllFieldnames))
    
    'NOTE:  vp_FieldName is possibly dimmed incorrectly, but regardless I could have technically used any variable
    '         name in it's place, providing it's not used elsewhere / violates scope?????
    You never used Fieldname in the loop above. The code above will not work as presented.

    In *for_each() function, I typically use X for unknown as the placeholder (This actually has no dimension and is run in a private variable space within the *for_each() execution), and is simply used as a substitution of a variable with a value for each line or array element as it is processed.
    Regards,

    Ira J. Perlow
    Computer Systems Design


    CSDA A5 Products
    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
    CSDA Barcode Functions

    CSDA Code Utility
    CSDA Screen Capture



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

    Default Re: $10,000 Question ~ "The foo variable"

    Quote Originally Posted by csda1 View Post
    You never used Fieldname in the loop above. The code above will not work as presented.

    In *for_each() function, I typically use X for unknown as the placeholder (This actually has no dimension and is run in a private variable space within the *for_each() execution), and is simply used as a substitution of a variable with a value for each line or array element as it is processed.
    Thanks Ira;

    So in order to make my code work, I still need to find a way to reference the table's "fields collection"....
    Is there a way to do this using the FOR EACH construct? ( or must you do it another way, like this?):
    I can't find any way to "grab a pointer" to reference this collection using X-basic.
    (looking at the X-basic Explorer for reference)

    Code:
    '**  IS THIS THE ONLY WAY TO DO THIS WITH TABLE FIELDS??
    
    for i = 1 TO tbl.fields_get()
        fld = tbl.field_get(i)
        fnames[i] = fld.name_get()' square brackets required in version 6 and above
    next i
    Bear with me, I'm almost there........ PS: Just ordered CDSA code utility (PRO) moments ago.....
    Last edited by SNusa; 02-02-2012 at 09:53 AM.
    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."

  21. #21
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default Re: $10,000 Question ~ "The foo variable"

    Hi Robert,

    Quote Originally Posted by SNusa View Post
    Code:
    '**  IS THIS THE ONLY WAY TO DO THIS WITH TABLE FIELDS??
    
    for i = 1 TO tbl.fields_get()
        fld = tbl.field_get(i)
        fnames[i] = fld.name_get()' square brackets required in version 6 and above
    next i
    for each is normally used where you don't know the number of items, nor do you care what position it is, just that you want to iterate through values and have some variable that for each can iterate through. For, Next as you used above is kind of OK, except, you are recalculating the field count for every iteration of the loop, you didn't DIM variables, and the loop can be simplified to 1 line as below.

    shown below is best when you have the exact count and works better for this case

    Code:
    dim tblptr as p
    tblptr=table.open("tablename")
    dim fldcnt as n
    fldcnt=tblptr.fields_get()
    dim i as n
    dim fldlst as c
    fldlst=""
    for i=1 to fldcnt
    	fldlst=fldlst+tblptr.field_get(i).name_get()+crlf()
    next
    tblptr.close()
    ui_msg_box("Fieldlist",fldlst)
    But don't use a sledge hammer when a hammer will do. This is the simplest way

    Code:
    dim tblptr as p
    tblptr=table.open("tablename")
    dim fldlst as c
    fldlst=tblptr.field_name_get()
    tblptr.close()
    ui_msg_box("Fieldlist",fldlst)
    Regards,

    Ira J. Perlow
    Computer Systems Design


    CSDA A5 Products
    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
    CSDA Barcode Functions

    CSDA Code Utility
    CSDA Screen Capture



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

    Default Re: $10,000 Question ~ "The foo variable"

    Quote Originally Posted by csda1 View Post
    But don't use a sledge hammer when a hammer will do. This is the simplest way

    Code:
    dim tblptr as p
    tblptr=table.open("tablename")
    dim fldlst as c
    fldlst=tblptr.field_name_get()
    tblptr.close()
    ui_msg_box("Fieldlist",fldlst)
    I knew the code I pasted (prior post above) was sloppy. It's a direct cut/past from the a5 .chm (v9/10) help file. (to expedite)

    And I was thinking the exact same thing regarding not needing a "sledgehammer." (I knew I could do it via your second code example, having seen the field_name_get() method in the XBE.) ~ I was just learning / looking for an alternative using the FOR EACH. (The a5 documentation indicates it can loop through lists, arrays, and collections, and in my mind, the field names are a collection.

    (Apparently, there's just no way to reference this "collection" as a collection for use in a FOR EACH construct.)

    "My mind is like a sponge right now."


    PS: I never would have started this thread had I found this, and others: http://msgboard.alphasoftware.com/al...Please-explain I searched for foo here and found nothing meaningful, until the thread (along with others) appeared in a different search while searching for "ghost"!
    Last edited by SNusa; 02-09-2012 at 12:37 AM.
    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."

  23. #23
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default Re: $10,000 Question ~ "The foo variable"

    Hi Robert,

    Quote Originally Posted by SNusa View Post
    I was just learning / looking for an alternative using the FOR EACH. (The a5 documentation indicates it can loop through lists, arrays, and collections, and in my mind, the field names are a collection.

    (Apparently, there's just noway to reference this "collection" as a collection for use in a FOR EACH construct.)
    What made you think the table is a collection?

    A collection is a data type in Alpha. You reference a value by a "Key". So keys Robert, Ira and Sally might have gender as Male, Male and Female respectively. The key is like an index or array indice number, except it is a character key value.

    A table pointer returns a class of objects that include a variety of methods (basically same as a function) and values and pointers which could include a collection type, but as far as I know, does not. If there was a collection pointer in a property of the table, then yes, you could iterate through that collection.

    Based on my experience on V8, collections at that time started to become unstable when the number of keys got large (maybe 5000 or more). I haven't really tested to see if later versions were more reliable with large collections.
    Regards,

    Ira J. Perlow
    Computer Systems Design


    CSDA A5 Products
    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
    CSDA Barcode Functions

    CSDA Code Utility
    CSDA Screen Capture



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

    Default Re: $10,000 Question ~ "The foo variable"

    Quote Originally Posted by csda1 View Post
    What made you think the table is a collection?
    "In my mind" (here we go, right?) ~ The actual fields within the table collectively make up a "collection of table fields." (That's what I was thinking.)

    I'm pretty sure that in years gone by, in visual basic maybe, as I know it wasn't "Apple Basic" (again, showing my "age").... I was using FOR EACH statements on an access database, table to grab field names and their respective values. ~ I could be wrong though, it was many years ago.
    Last edited by SNusa; 02-02-2012 at 02:13 PM.
    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."

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

    Default Re: $10,000 Question ~ "The foo variable"

    Further research has prompted a few more questions here, relative to my "incorrect assumption" that the fields in a table were considered a "collection."

    Where can I review a definitive list of "collections" (a5 objects) upon which:


    1.) The for...next[i] loop can be applied?
    2.) The for each loop could be used?*

    NOTE: Having now been "introduced" to the *FOR_EACH() function... I presume it could be optionally used (instead of the for each loop) in some situations, right?


    Quote Originally Posted by csda1 View Post
    In *for_each() function, I typically use X for unknown as the placeholder (This actually has no dimension and is run in a private variable space within the *for_each() execution), and is simply used as a substitution of a variable with a value for each line or array element as it is processed.
    * After thinking about your response, I'm inclined to believe that the for each loop "technically" could be used in my example, although knowing the number in the collection makes the for...next[i] the method of choice?
    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."

  26. #26
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default Re: $10,000 Question ~ "The foo variable"

    Quote Originally Posted by SNusa View Post
    Where can I review a definitive list of "collections" (a5 objects) upon which:....
    There is no list of A5 objects. I don't think any Alpha Five function returns a collection (data type U), but I could be wrong. Most return a list, and a few return an array. If it returns a pointer, some of the properties can be a list, array or collection. If the function or method or other code returns a character type, array or a collection (data type U), then you can process it as follows (basic info only below).

    • FOR EACH ... NEXT processes each element of the object (it knows the number)
      each element of an array (I'm not sure what happens with multi-dimensional array)
      each line of list (CRLF delimited)
      each key of a collection (Type U)
    • FOR ... NEXT can process the same types as the FOR EACH ... NEXT except you must know the size of the array, number of lines of a list, or the number of keys in a collection, and initialize the index to the initial value and loop count based upon the # of items you want processed
    • *for_each() can process a list or array, 1 item at a time, but the result is always a character string that is a concatonation of an expression of each line or array element. The result may be directly used, or may be making a long piece of text to be used with eval() or evaluate_template() or similar


    There are a number of array functions that can process all of the array as well, but they only work with an array, although when much faster, it can be worth the conversion time from other data types to use a fast array function. Regex_Grep() and regex_Merge() can process text strings extremely fast, but take a while to learn to use to advantage. And there are a variety of text string functions that work very fast on lists, *for_each() and Filter_String_Smatch() and a few others.

    See also my Speed Tips here
    Regards,

    Ira J. Perlow
    Computer Systems Design


    CSDA A5 Products
    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
    CSDA Barcode Functions

    CSDA Code Utility
    CSDA Screen Capture



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

    Default Re: $10,000 Question ~ "The foo variable"

    Your speed tips are invaluable, (just like everything else). I've spent much time on your site already!
    Your reply above clarified more concepts (in my mind) than you could ever imagine! ~ Thank you Ira, for making things "click!"

    I had been thinking that possibly all of the a5 System Objects (displayed within the XbE) were in fact all the "objects" upon which the for...next and for each constructs could be used. ~ Seems/Seemed plausible at least....

    PS: Ira, I ran across this code in the wiki, while analyzing your last post: Wiki Code Example
    (I never new that Alpha was communicating with you directly via code examples)....



    ~Hey Neo, are you still parsing data from The Matrix? ~ "I'm beginning to believe."

    Code:
    dim cc as C
    cc = <<%a%
    My house has 3 doors
    and 26 windows
    I don't miss Windows 3.1
    Who does?
    Ira, did you leave the window open?
    %a%
    txt = regex_grep(cc, "(W|w)indow", "$(offset): $(LINETEXT)" + crlf() )
    ? txt
    = 30: and 26 windows
    52: I don't miss Windows 3.1
    99: Ira, did you leave the window open?
    ~ My "phone" is ringing...... I'm in!
    Last edited by SNusa; 02-10-2012 at 01:54 PM.
    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."

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

    Default Re: $10,000 Question ~ "The foo variable"

    OK, I've got all the other stuff working except this:

    When placed on a on_Push button event (on a form):

    Code:
    dim vc_String as C = ""
    dim vp_Form as P = parentform.this
    
    for each thingy in vp_Form 'vp_Form.Fields_Enum()
    	ui_msg_box("This thingy value:",this.object.name) 'thingy.object.name
    	vc_String = vc_String + this.object.name
    Next
    ui_msg_box("ALL FORM OBJECTS:",vc_String)
    The debugger errors with: Variable "thingy" not found (on first loop).
    Also, this.object.name always refers to the "calling button" name. (understandable, since the for...each loop isn't working)

    I've also tried substituting (see blue remarks) to no avail.....
    (Then I get the "unexpectd expression type in FOR EACH Type is '\' Expression is 'Invoice.Fields_Enum()' error)

    Must be something simple I'm not doing properly here...... ~ Let me guess, the form objects are not part of a "collection" either?
    (Even so, shouldn't the substitutions work? ~ "So close, yet so far".....)
    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."

  29. #29
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: $10,000 Question ~ "The foo variable"

    dim vp_Form as P = parentform.this

    establishes a pointer to the form. A pointer is not a list of the objects on the form.

    Try

    dim vc_String as C = ""
    dim vp_Form as P = parentform.this
    lst = vp_form.CHILD_ENUM()
    for each thingy in lst
    ui_msg_box("This thingy value:",thingy)
    vc_String = vc_String + thingy
    Next
    ui_msg_box("ALL FORM OBJECTS:",vc_String)

    Will be more readable if you use

    vc_String = vc_String + crlf() + thingy
    Last edited by Stan Mathews; 02-10-2012 at 04:54 PM.

  30. #30
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default Re: $10,000 Question ~ "The foo variable"

    Quote Originally Posted by SNusa View Post
    OK, I've got all the other stuff working except this:

    When placed on a on_Push button event (on a form):

    Code:
    dim vc_String as C = ""
    dim vp_Form as P = parentform.this
    
    for each thingy in vp_Form 'vp_Form.Fields_Enum()
    	ui_msg_box("This thingy value:",this.object.name) 'thingy.object.name
    	vc_String = vc_String + this.object.name
    Next
    ui_msg_box("ALL FORM OBJECTS:",vc_String)
    The debugger errors with: Variable "thingy" not found (on first loop).
    Also, this.object.name always refers to the "calling button" name. (understandable, since the for...each loop isn't working)

    I've also tried substituting (see blue remarks) to no avail.....
    (Then I get the "unexpectd expression type in FOR EACH Type is '\' Expression is 'Invoice.Fields_Enum()' error)

    Must be something simple I'm not doing properly here...... ~ Let me guess, the form objects are not part of a "collection" either?
    (Even so, shouldn't the substitutions work? ~ "So close, yet so far".....)
    for each thingy in vp_Form
    There is no thingy in vp_Form. vp_Form is a pointer. It must be an array, text or collection

    for each thingy in vp_Form.Fields_Enum()
    vp_Form.Fields_Enum() returns a list of fields
    each loop iteration returns a line of text from the list (without the CR-LF) in the variable thingy.
    You can use thing to display the text as in ui_msg_box("This thingy value:",thingy) or just compute something else in the loop. There is no thingy.value, thingy.object.name, or any thing else, unless thingy is a pointer, which it won't be for a list. (it might be for a collection or array value, but that would be an array or collection of other objects, who only use methods and properties of those objects)
    Regards,

    Ira J. Perlow
    Computer Systems Design


    CSDA A5 Products
    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
    CSDA Barcode Functions

    CSDA Code Utility
    CSDA Screen Capture



Similar Threads

  1. ms access "views" vs. dbf "sets" question
    By er2fan in forum Application Server Version 9 - Web/Browser Applications
    Replies: 5
    Last Post: 07-03-2009, 05:47 PM
  2. "foo" - Please explain
    By enstorms in forum Alpha Five Version 9 - Desktop Applications
    Replies: 5
    Last Post: 01-21-2009, 12:48 PM
  3. form.view("fName","","","center","center")
    By reynolditpi in forum Alpha Five Version 9 - Desktop Applications
    Replies: 5
    Last Post: 07-15-2008, 12:37 AM
  4. To "zoom to record" or to "open form" using action scripting, that is the question.
    By georgefurnel in forum Alpha Five Version 9 - Desktop Applications
    Replies: 4
    Last Post: 06-18-2008, 07:32 PM
  5. "Add" and "Save" buttons don't stay on "Self" page
    By Scholin in forum Application Server Version 8
    Replies: 2
    Last Post: 02-05-2008, 08:50 AM

Bookmarks

Posting Permissions

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