Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

$10,000 Question ~ "The foo variable"

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

  • #46
    Re: $10,000 Question ~ "The foo variable"

    Hi Cal,

    Just too funny!

    Originally posted by CALocklin View Post
    Ira, I'm shocked![ATTACH=CONFIG]30908[/ATTACH] Isn't this simpler: (and at least 200 times faster according to my tests)
    Code:
    ui_msg_box( "Fieldlist", a5_get_fieldnames( "tablename" ) ))
    As it turns out in reality, no. But 200 times faster than tbl.field_name_get()? Or did you mean the loop version? a5_get_fieldnames() is an Xbasic wrapper that will return set fields as well as table fields, so you have a function and some decision code as overhead.

    Faster is the direct function (actually a method to be 100% clear) table.external_field_name_get(). If the table referenced is already open, it runs about 10 times faster.

    Using something like table_pointer.field_name_get() is even just a bit faster than table.external_field_name_get(). Obviously you have to open the table 1st, but when you include that and a table.close(), it is still faster than table.external_field_name_get(). If the table was already open for both, it still wins by a hair.

    See comparative execute time to run code for 3 types below with and without table initially open

    Code:
    ' Init code
    dim tablename as c
    tablename="your_tablename"
    dim x as c
    
    ' Table is not open prior to running code
    x=a5_get_fieldnames(tablename)	' .00712
    
    x=table.external_field_name_get(tablename)	' .00648
    
    ' .00666 time for the next 4 lines
    dim tbl as p
    tbl=table.open(tablename)
    x=tbl.field_name_get()
    tbl.close()
    
    ' versus below if table is open already
    dim tbl as p
    tbl=table.open(tablename)
    
    x=a5_get_fieldnames(tablename)	' .00123
    
    x=table.external_field_name_get(tablename)	' .000605
    
    x=tbl.field_name_get()	' .000441
    
    tbl.close()
    So in conclusion, based upon my timings and analysis, no it is not simpler if you already have the table open, and is faster even if you have to open the table (albeit with slightly more code).

    These were all tested in V8, specific versions could vary a bit, but not likely.
    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


    Comment


    • #47
      Re: $10,000 Question ~ "The foo variable"

      Yeah, my 200 times faster was based on a loop that opened and closed the table each time through the loop. I assumed that was the same thing the a5_get_fieldnames() was doing.

      HOWEVER, based on your times, I tried it again this morning and the time was slightly longer to run the loop with a5_get_fieldnames() - which makes more sense. Obviously I did something different (wrong!) last night but I deleted the test script so I have no idea what it was. Even opening the table before running the a5_get_fieldnames() loop only results in running it about 10 times faster - nowhere close to the 200 times I got with whatever I did last night.

      FWIW, I thought maybe I ran the tests last night in one of the other versions. So I also tried it in v8 and v9 just now and, compared to v10, both methods take about 30-40% longer in v8 and about 300% longer in v9.

      Comment


      • #48
        Re: $10,000 Question ~ "The foo variable"

        The "thingy" saga continues... I'm wondering whether I've found a bug in X-basic?

        Could someone try and explain this to me, and whether or not it may be a bug?:

        Using Alpha Sports (desktop)
        Set a few session variables in the Products form. (define them in either the "V" or OnInit of the form)
        Now, on the Items form, add a button & the following code to the button's OnPush event.

        For code below, define these session vars in Products: vc_ShareAfterClose & vc_InvoiceItem

        When you run the Items form, click on this button and see what happens.....


        Code:
        dim vp_Form as P
        dim vn_Session as N
        dim vp_SessionVars as P
        dim vc_List as C
        dim vc_String as C
        dim vc_String1 as C
        dim vc_String2 as C
        
        vp_Form= Form.view("Products")
        vn_Session= vp_Form.SessionHandle()
        vp_SessionVars= session_variables(vn_Session)
        vc_List= user_Variables_enum(vp_sessionVars)
        'vc_List= Variables_enum(vp_sessionVars) ' -BREAKS THE FOR EACH CONSTRUCT.  (issue #2)
        
        msgbox(vc_List) '-COOL, WE HAVE THE ENUMERATED LIST.....  (INCLUDING THE SESSION VARIABLES)
        
        ui_msg_box("UserSessionVars:",USER_VARIABLES_ENUM(vp_SessionVars))  ' -AND BOTH THESE LINES RETURN SAME VALUES IN LIST  (issue #2)
        ui_msg_box("AllSessionVars:",VARIABLES_ENUM(vp_SessionVars))
        
        msgbox("VARIABLES:" + chr(10) + "vc_InvoiceItem=" + vp_SessionVars.vc_InvoiceItem + chr(10) + "vc_ShareAfterClose=" 
        +  vp_SessionVars.vc_ShareAfterClose)
        
        'NOTE HOW THE SESSION VARIABLES (DEFINED ON OTHER FORM) RESOLVE PROPERLY IN MSGBOX ABOVE!
        'NOW HERE'S THE PROBLEM:  IN THIS LOOP, WHEN THINGY GETS TO THE VARIABLES,
        'eval(thingy) fails.....  'thingy.value (or just thingy) works fine though......
        '(When debugger pops up, skip and continue to the end)......
        
        for each thingy in vc_List
        	'x = eval("thingy.value") ' -doesn't work because it's not in the same frame?????
        	vc_String= vc_String + thingy.value + chr(10) ' THIS LINE OF CODE WORKS FINE
        	vc_String1= vc_String1 + thingy.value + "= " + eval(thingy) + chr(10) ' BUT EVAL(THINGY) WON'T RESOLVE....
        	vc_String2= vc_String2 + thingy + "= " + eval(thingy) + chr(10) ' Same problem here......
        next
        
        ui_msg_box("User Variables:",vc_String1 + chr(10) + vc_String2)
        vp_Form.close()
        I haven't worked on issue #2 yet.....
        As for the primary problem, all I can think of is that maybe eval() is the wrong function to be using here...
        (I can get the variable names, but not the variable values)

        ~The debugger pops up and warns that these session variables are not found, (vc_ShareAfterClose & vc_InvoiceItem )so the line of code must be "skipped."

        I'm also wondering exactly what the difference is between these two functions... (second one entirely breaks the construct)
        vc_List= user_Variables_enum(vp_sessionVars)
        vc_List= Variables_enum(vp_sessionVars)

        ... And why is A_DB_CURRENT & A_DB_CURRENT_PATH being returned here by user_Variables_enum()?
        Last edited by SNusa; 02-25-2012, 07:41 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."

        Comment


        • #49
          Re: $10,000 Question ~ "The foo variable"

          Hi Robert,

          One session's variables are not available in another session unless you prefix the variable from the other session with the session variable pointer.

          Or if you enclose some code with a With .. End With construct, then Alpha will try that pointer as a default until it resolves the variable.
          Last edited by csda1; 02-25-2012, 07:06 PM. Reason: Forgot with .. end with
          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


          Comment


          • #50
            Re: $10,000 Question ~ "The foo variable"

            Originally posted by csda1 View Post
            Hi Robert,

            One session's variables are not available in another session unless you prefix the variable from the other session with the session variable pointer.
            Or if you enclose some code with a With .. End With construct, then Alpha will try that pointer as a default until it resolves the variable.
            Got it.... :
            vc_String1= vc_String1 + thingy.value + "= " + eval("vp_SessionVars." + thingy.value) + chr(10)
            vc_String1= vc_String1 + thingy + "= " + eval("vp_SessionVars." + thingy) + chr(10)
            ~Both work here...

            My thingy doesn't grab the pointer to the variable, only it's name. ~It was that special case thingy pointer again throwing me off......
            I'm now wondering whether I could optionally use the "Context" parameter with =EVAL( Expression as C [, Context as C ] ) ???

            Thanks again Ira!
            Last edited by SNusa; 02-25-2012, 08:39 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."

            Comment


            • #51
              Re: $10,000 Question ~ "The foo variable"

              Hi Robert,

              Originally posted by SNusa View Post
              I'm now wondering whether I could optionally use the "Context" parameter with =EVAL( Expression as C [, Context as C ] ) ???
              No you can't. Context is a tablename text string, and does not have any way to reference a variable space. If you use WITH .. END WITH, the eval() will use that variable space as it's default (but will search local, shared and global if not found for that variable space)
              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


              Comment


              • #52
                Re: $10,000 Question ~ "The foo variable"

                Originally posted by csda1 View Post
                Hi Robert,

                No you can't. Context is a tablename text string, and does not have any way to reference a variable space. If you use WITH .. END WITH, the eval() will use that variable space as it's default (but will search local, shared and global if not found for that variable space)
                Thanks Ira;

                The wiki actually specifies otherwise. (Thus, this is a very confusing example).......
                Context Argument (Optional): The context in which the expression should be evaluated. This can be a list of tables in a CR-LF delimited list. It can also be the name of an open form (suffixed by ".this"), which would evaluate the expression in the context of the form.
                I first saw it appear when placing a button on the Alpha Invoice browse using a genie for code creation to open the products form:
                (actual code is at bottom)

                :Form.viewqueried("Products",eval("\"product_id=\"+s_quote(product_id)",this.Name(16)+".this"),"","Normal","","",.t.)

                Which I re-wrote as: vp_FormPtr = :Form.viewqueried("Products","product_ID='"+description.value+"'","","Normal","","",.F.)
                (with a bit of help from the debugger to resolve what the parameter was actually "doing")

                ~The original a5 A/S code is still a little elusive in my mind.......
                I know that this.Name(16)+".this" refers to the browse via #16 which means the Fully qualified object name returned is :invoice:browse1....????? (which is thus designated as the "context" for this line of code.)

                ~And that in this context, the .this has a "special" different 3rd usage. (I know that "this" can refer back to an object, or when used as "object.this" typically returns a pointer to the object.) But here the ".this" suffix merely refers to the the objects name (which according to the help file should be the name of a form)... But in this case "this.name().this" actually seems to refer to the name of the browse object and returns a value of type character (as indicated by the eval() context parameter......... ~ STRANGE!!!!!!


                Alpha Sports Invoice (Browse1 button) "event" event (code originally created by wizard).....
                Code:
                function Actions_ButtonClick as v( event as C,data as C, row as N)
                	this.Set_Viewport_row(row)
                	if this.Table_Get().Mode_Get() > 0 then
                		this.Commit()
                	end if
                
                dim vp_FormPtr as P
                
                
                'ui_msg_box("EVAL:",eval(this.Name(16)+".this"))
                ui_msg_box("EVAL1:",eval("\"product_id=\"+s_quote(product_id)",this.Name(16)+".this"))
                ui_msg_box("EVAL2:",this.Name(16)+".this")
                ui_msg_box("eval3:",eval(this.Name(16)+".this"))
                
                ':Form.viewqueried("Products",eval("\"product_id=\"+s_quote(product_id)",":browse1.this"),"","Normal","","",.t.) - ERROR
                ':Form.viewqueried("Products","product_ID='"+Invoice:Tables:product.PRODUCT_ID+"'","","Normal","","",.t.) - ERROR
                'Invoice:Tables:product.PRODUCT_ID   Invoice:browse1:description.value description.value - ERROR
                ':Form.viewqueried("Products",eval("\"product_id=\"+s_quote(product_id)",this.Name(16)+".this"),"","Normal","","",.t.) ' - ORIGINAL CODE (WORKS FINE) MADE BY A/S WIZARD
                
                ':Form.viewqueried("Products",eval("\"product_id=\"+s_quote(product_id)",this.Name(16)+".this"),"","Normal","","",.t.) '- OK
                ':Form.viewqueried("Products",eval("\"product_id=\"+s_quote(product_id)",":invoice:browse1.this"),"","Normal","","",.t.) '- OK
                ':Form.viewqueried("Products","product_ID='"+Invoice:browse1:description.value+"'","","Normal","","",.t.) '- OK
                vp_FormPtr = :Form.viewqueried("Products","product_ID='"+description.value+"'","","Normal","","",.F.) '- OK (my cleaned up code)
                'ui_msg_box("desc.txt:",description.text + chr(10) + description.value)
                
                
                end function
                Last edited by SNusa; 02-27-2012, 08: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."

                Comment


                • #53
                  Re: $10,000 Question ~ "The foo variable"

                  Yet another couple of oddities:

                  Within a form based on a set:

                  Code:
                  dim vn_price as N = price.value
                  dim vp_Table as P = parentform.table_get()
                  dim vc_ChildTable as C = alltrim(vp_Table.child_get()) ' - Alltrim() needed to "fix" function or code below fails!
                  'WITHOUT alltrim() vc_ChildTable gets the char value of PRODUCT¶ and not PRODUCT in the debugger.....
                  dim vp_ChildTable as P = table.get(vc_ChildTable) ' - Woohoo!  Found a way to get pointer to child table....
                  
                  dim vc_FieldVal as C = ChildTable.COST ' -this works....
                  dim vc_FieldVal as C = str(eval(topparent.name() + ":Tables:" + vc_ChildTable + ".COST"),10,2,",(") ' -this works to..
                  'dim vc_FieldVal as C = str(eval(vc_ChildTable + ".COST"),10,2,",(") ' -but this DOES NOT WORK,
                  ' (as a5 can't presumably resolve the short name here)....
                  
                  ui_msg_box("",vp_ChildTable.COST)
                  Footnote: child_get() method returns type C
                  Seems strange that you need alltrim() to remove the ¶ character which is appended to vp_Table.child_get()...
                  (A debugger watch showed a value I hadn't expected which kept causing my code to fail.)
                  Last edited by SNusa; 02-27-2012, 08:55 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."

                  Comment

                  Working...
                  X