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

Using xDialog to build filter-string

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

    Using xDialog to build filter-string

    Hi all,

    (Please forgive, if the problem's description seems a bit longish..)

    I plan on using an xDialog box to construct a filter string which in turn could be used 'in front' of a report/Letter/label document (kind of a wrapper).

    For an xDialog I have adopted an example from the xDialog tutorial in "A Genie Style Dialog with Tabs" which describes a tabbed dialog using embedded dialogs to show the various tabs containing text box controls where a user can enter filter criteria for the report to be run after the dialog closes.

    It's about filtering records from an address table.
    On the first tab, there is a key list where the user must first select an 'Instutution' for which he wants to list addresses. This field is a required field and activates the 'Run' button of the dialog after a valid entry is made.
    On the second tab, there are two text boxes where the user can enter an 'Organisation' or a 'Name' and
    On the third tab, there are text boxes for 'ZIP-Code', 'City' and 'Country' to filter after.

    The intention is to add just filled in fields to the filter and to ignore the others, resp. set these parameters to .T.
    E.g assuming that the user filled in "Miller" in the name field, plus "4050" in the ZIP-Code field, the resulting filter-string would read "Institution = 'EC' .and. Name = 'Miller' .and. ZIPCode = '4050' "

    The dialog as such works.
    Where I am stuck is with what to do with the variables, once the user clicks on 'Run'. Even after RTFM I am unsure about which function(s) to use. I got lost somewhere in the quotings :o
    How would you tackle this problem? I plan on keeping this xDialog as 'generic' as possible.

    Each and every tip very welcome!!

    TIA
    SwissCharles
    Between the Alps and a comfy place

    #2
    This should not be too difficult. Can you post the code for the xdialog.
    Bill Hanigsberg

    Comment


      #3
      Charles

      I do precisely what you have asked for.

      1. Button on form to an action script (Swiss-1) to:

      a. Diisplay an x-dialog box to gather your variables (Swiss-2 & 3).

      b. Set certain variables to constants based on user input e.g. if end date is blank set to beg date. (Uncomplicates future record select criteria). (Swiss-1)

      c. Print a report(s) based on the user input.

      1. In the case of many variables I place part of the filter in this record selection. (Swiss-4)

      2. The remainder of the filter I have on the called report record selection. (Swiss-5)

      Hope this helps. See attached screen shots. (Swiss-1-5)

      John

      Comment


        #4
        Using xDialog...

        John,
        Many thanks for your outstanding post!

        Since I am using an xDialog with embedded dialogs, I did code it outside of ActionScripting. Although I did try to 'incorporate' this xDialog into an ActionScript by calling it with an 'Run a script' action, but I wasn't able to see the variables of my xDialog inside the ActionScript environment in order to use your approach. But I will never the less ponder over your solution some more.


        Bill,
        OK, here is what I did so far:

        Code:
        'Date Created: 17-Nov-2005 04:58:08 PM
        'Last Updated: 14-Feb-2006 03:45:53 PM
        'Created By  : CUS_
        'Updated By  : CUS_
        
        'First specify the tab names.
        dim lv as P 
        
        dim ShowAll as C
        ShowAll = "Alle"    'this means 'all' records...
        
        lv = local_variables() 
        
        'Specify the List of Tab Names for the Genie 
        panes = <<%a% 
        Institution
        Name
        Adresse
        %a%	
        
        'Next, specify the Xdialog code (dialog body and event code) for each Genie page.
        dim code_pages[1] as P 
        
        code_pages[1].name = "Institution" 
        code_pages[1].dialog_body = <<%dlg%
        Hier k�nnen Sie nach einer Institution filtern:;  'this means please filter for an Institution
        {lf};
        [%K=keylist%.10Ins_selected!change];
        {lf};
        {text=10,1Ins_selected};
        {lf};
        %dlg% 
        tbl = table.reset("Institution")
        tbl.query_detach_all()
        query.order = "Ins_ID"
        query.filter = ".t."
        query.description = "Keylist"
        indx = tbl.query_create()
        
        code_pages[1].dialog_events = <<%code% 
        1=1 
        if a_dlg_button = "change" then
           a_dlg_button = ""
           flag_finish = .T. 
        end if
        %code% 
        
        code_pages.insert(1,1) 
        code_pages[1].name = "Name" 
        code_pages[1].dialog_body = <<%dlg% 
        Hier k�nnen Sie nach einem Namen filtern:;  
        {lf};
        Organisation beginnt mit:|[70.72Organisation];
        {lf};
        Name beginnt mit:|[30.32Name];
        {lf};
        {lf};
        {text=72,1Organisation};
        {lf};
        {text=32,1Name};
        %dlg% 
        code_pages[1].dialog_events = <<%code% 
        1=1 
        %code% 
        
        code_pages.insert(1,1) 
        code_pages[1].name = "Adresse" 
        code_pages[1].dialog_body = <<%dlg% 
        Hier k�nnen Sie nach einem Adressfeld filtern;
        {lf};
        Postleitzahl zwischen:|[6.8VonPLZ] und [6.8BisPLZ]; 'that's ZIP code on your side of the pond  ;-)
        {lf};
        Ort beginnt mit:|[40.42Ort];          'that's City
        {lf}; 
        Land:|[3.5Land];    ' thats country
        {lf}; 
        %dlg% 
        code_pages[1].dialog_events = <<%code% 
        1=1 
        %code%	
        
        'Next, display the dialog box.
        
        current_pane = 1  
        
        dim flag_finish as L 
        
        flag_finish = .f. 
        
        ui_dlg_box("Datens�tze filtern",<<%dlg% 
        {startup=init} 
        [%R=1%.144,19current_pane^^panes!current_pane_*] 
        {embedded=142,13embedded1} 
        {line=1,0}; 
        {justify=right}<10&Cancel> <10&Finish?flag_finish>; 
        %dlg%,<<%code% 
        
        if a_dlg_button = "init" then  
        	a_dlg_button = "" 
        	show_page(lv) 
        end if  
        
        if left(a_dlg_button, 13) = "current_pane_" then  
        	if a_dlg_button = "current_pane_change" then  
        		show_page(lv) 
        	end if  
        	a_dlg_button = "" 
        end if 
        
        ' The following does not work to assign "ShowAll" to blank fields - dont know why...
        if a_dlg_button = "&Finish" then 
        	iif(isnull(Organisation) ,Organisation = ShowAll , Organisation = Organisation)
        end if
        
        %code%)
        
        'The show_page() function swaps the embedded dialog boxes as the user clicks the tabs.
        
        function show_page as v (vars as P) 
        
        	with vars 
        	dim page_to_show as C  
        	dim dlg_body_embedded as C  
        	dim dlg_event_embedded as C  
        	
        	page_to_show = word(panes,current_pane,crlf()) 
        	
        	dim tempIndx as N  
        	
        	tempIndx = code_pages.find(ut(page_to_show), "ut(name)") 
        	
        	if tempIndx > 0 then  
        		dlg_body_embedded = code_pages[tempIndx].dialog_body 
        		dlg_event_embedded = code_pages[tempIndx].dialog_events 
        	else 
        		dlg_body_embedded = "Code for this page not found" 
        		dlg_event_embedded = "1=1" 
        	end if 
        	ui_modeless_dlg_box("embedded1", dlg_body_embedded, dlg_event_embedded) 
        	
        	end with 
          	
        end function
        As indicated in the comments above, I couldn't manage to assign a default value to empty fields of the dialog.
        Besides this problem, I would like to build a result variable with the correct filter syntax to be used in reports and the like.

        This is one of my first xDialogs and it looks like I am in a little bit over my head :o

        Thanks for each and every input!
        SwissCharles
        Between the Alps and a comfy place

        Comment


          #5
          Charles,

          I'm trying to understand your objective and not try to infer it from your code.

          What precisely are you trying to filter? Is it a list displayed on the xdialog or a form, or table.?

          Thanks,
          Bill
          Bill Hanigsberg

          Comment


            #6
            String containing a Filter Expression

            Bill,
            Many thanks for taking this up!

            I would like to use this xDialog to build a filter expression which I can then use everywhere where there can be given a filter expression as an argument. This could in principle be anything (form/table/report/labels/etc..) although I am planning it to use with labels.

            For this I would have to fill a result variable (inside my xDialog and not yet declared in my code sample) with a filter expression which in turn is built depending on what criteria the user entered in the xDialogs field(s) as soon as the user clicks on 'Finish'.

            All criteria entered are understood to be combined (.and.) while fields left blank are considered to either not being a part of the filter string or as being true (.t.)

            So:
            From a button (this could be an ActionScript or pure xBasic, no problem) I would first call my xDialog, which delivers a result variable containing this filter expression which I want to feed into a report/label/what have you...

            I hope that I make some sense here (please forgive my rusty english :( - it's been quite some time since my last stay in your beautyful country...)

            Thanks in advance
            SwissCharles
            Between the Alps and a comfy place

            Comment


              #7
              Charles

              Am unable to assist you with X-Greek, however if you use Action Scripting, you can convert it to X-Basic. This will allow you to view & modify the code generated.

              John

              Comment


                #8
                Hello again Charles,

                Since I find your example xdialog complex let me start over and concentrate on how I approach this problem. I don't claim to have the only or even best approach. It is just what I do and I hope someone else chimes in with an alternative approach so I can learn

                -I use the xdialog to create filter and order expressions based on user actions on its fields;
                -I place these expressions in variables (vFilter, vOrder) that can be passed around the application as necessary.

                For example, I run an xdialog from a button on a form. The dialog fills in vFilter and vOrder.
                and finally:
                '----------------
                nrecs=topparent.QueryRun(vFilter,vOrder)

                if nrecs=0 then
                ui_msg_box("Report","No records found; displaying all records")
                parentform.Index_Set("name")
                end if
                '----------------

                The example's first line is obviously what you want but you need the rest in case there are no records.


                I would start with a simple example and build up the complexity level gradually. Manually give values to the vFilter and vOrder and see if you can do what you need. Once you are certain of the expressions' form move back a step and see if you can use the dialog to generate the expressions.

                You can generate filters step by step and use xbasic methods to combine them which simplifies matters considerably:

                vFilter = a5_combine_filters(vFilter_ingreds,vFilter_cats)


                Looking back at your example I see a problem where you say you will "set empty parameters to .t.". I do not think you want to do this.

                That is, if the user does *not* specify an organization but does give a zip code you want to say (in pseudocode)
                name=Jones and Zip=123445.
                You do *not* want to say
                organization = .t. and name=Jones and Zip=123445.
                because there is no organization named ".t."

                The hard part is messaging the return values of controls on the xdialog into the format required by the query syntax. This is all about string handling methods and the way to do it is trial and error. Use the debugger or the interactive window to view the result: that is, the values of the variables.

                I hope this is of some help. If you get stuck try posting a brief example. I'll try to look in on the board but I have to travel for a few days.
                Bill Hanigsberg

                Comment


                  #9
                  Food for thought!

                  John,
                  Thanks for your thoughts anyway!
                  I did try something along the lines you propose, but could not find a way to access the xDialogs field/vars from the outside - which is probably not possible the way I tried it.

                  Bill,
                  Many thanks for your input - much appreciated!
                  I am newly impressed by the almost unlimited pool of functions in Alpha Five!
                  I suppose, the function you mention a5_combine_filters() - never seen before :o - will go a long way to what I am trying to do! Many thanks for that.

                  Re .T. :
                  I may not have expressed myself very cler on that, sorry.
                  I thought of using a construct along these lines:

                  Code:
                  (if(var->vcOrganisation = 'ShowAll' , .T. , Organisation = var->vcOrganisation )) .and. (if(var->vcName = 'ShowAll' , .T. , Name = var->vcName) )
                  But, as said before, the function you suggested seems to point to the right direction and I will try to whack something up along these lines.

                  Thanks for your time!

                  Regards
                  SwissCharles
                  Between the Alps and a comfy place

                  Comment


                    #10
                    Charles,

                    In your reply to John you write, "...but could not find a way to access the xDialogs field/vars from the outside - which is probably not possible the way I tried it."

                    Did you change the scope of the variables to global? You see this option on the (I think) last screen of the xdialog genie.
                    Bill Hanigsberg

                    Comment


                      #11
                      Variable Scope in xDialogs

                      Bill,

                      Thanks for your input!

                      Silly me! Your hint caused me to go and again have a look and lo and behold I completely misunderstood this dialog. I somehow took this for only being applicable to the result variable varC_result. Only now did I notice that it says there '..and all of the variables that are prompted for..'

                      Now, if there would be a way to combine my sooo fancy xDialog with an ActionScript!

                      What I tried, is to first declare the variables inside my xDialog:
                      Code:
                      dim shared Organisation
                      and then to define the edit box with it's variable like:
                      Code:
                      {lf};
                      Organisation beginnt mit:|[70.72Organisation];
                      {lf};
                      But this does not work. :(

                      A message box put after my xDialog and all inside an actionScript did show a blank value. Looks like the variable defined in the first code snippet is not the same as the one defined in the second one.

                      Anyway, again I have got enough food for thought for now.

                      Thanks again and for every additional tip that might come along :)

                      Regards
                      Last edited by SwissCharles; 02-16-2006, 03:50 PM.
                      SwissCharles
                      Between the Alps and a comfy place

                      Comment


                        #12
                        Charles,

                        You do not need to declare variables as the genie does it for you.

                        Each control really shows the contents of a variable because--remember--an xdialog is unbound whereas a form is bound and displays values from the table to which it is bound.

                        So when an xdialog runs, it read values from somewhere--such as a table--into a variable and displays it in a control.

                        Since xdialog makes the variable as a component of the control you do not have to declare it. You are doing this on the first page of the xdialog genie where you define the control.

                        You can manage the scope of the variable(s) on the last page of the genie but the variable has already been defined on the first page.

                        Is this a help?
                        Bill Hanigsberg

                        Comment


                          #13
                          Bill,

                          Yes this is of help - thanks for these clarifications.

                          I am now on to trying to assign a default value to such a field/variable? E.g. set fields/varibles to a default value in case the user did not enter something there by himself before hitting 'Finish'.

                          Many thanks for going this far with me!

                          Kind regards from Switzerland!

                          Charles
                          SwissCharles
                          Between the Alps and a comfy place

                          Comment

                          Working...
                          X