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 variable for field name in filter expression

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

    Using variable for field name in filter expression

    Hello All,

    I have a filter expression as shown below.

    Code:
    (Display_name <> Var->vc_U_1  )  .and. (Display_name <> Var->vc_U_2  ) .and. (Display_name <> Var->vc_U_3  ) .and. Llsb_plate=.T.
    I have a variable vc_qualification which contains the value Llsb_plate

    I need to use the variable in the filter expression instead of the hard coded Llsb_plate.

    Does anyone know the proper syntax for accomplishing this?

    Thanks in advance.

    Louis

    #2
    Re: Using variable for field name in filter expression

    (Display_name <> Var->vc_U_1 ) .and. (Display_name <> Var->vc_U_2 ) .and. (Display_name <> Var->vc_U_3 ) .and. (var->vc_qualification=.T.)

    But this is not the actual filter is it? Usually a filter is double-quoted. And I assumed that the variable is also a logical
    Mike
    __________________________________________
    It is only when we forget all our learning that we begin to know.
    It's not what you look at that matters, it's what you see.
    Henry David Thoreau
    __________________________________________



    Comment


      #3
      Re: Using variable for field name in filter expression

      Mike,

      Thank you for responding.

      I must not have explained well enough. Your suggestion tests to see if the variable vc_qualification = .t.

      What I need to do is create a filter with the following characteristics:

      The Field Display_Name can not match the value of Var->vc_U_1
      The Field Display_Name can not match the value of Var->vc_U_2
      The Field Display_Name can not match the value of Var->vc_U_3

      That part is easy...

      The next thing I need to test for (and this is where I'm having a tough time) is:

      The LOGICAL field named Llsb_plate must be .t.

      However, in my filter expression I can not literally type (Llsb_plate = .t.) because the name of the field I am testing against will depend on the values of a couple of other fields on the form. This time I'm testing against Llsb_plate but next time I might be testing against Llxyx_plate.

      Instead, the value "Llsb_plate" exists as the value held in the variable named vc_qualification.

      So... I need to be able to use the variable in the filter expression IN THE PLACE OF the actual field name but I need the filter expression to understand that I want to test against the field in the table not the variable itself.

      Hope I haven't completely confused you at this point.

      As always, thank you for your help.

      Louis

      Comment


        #4
        Re: Using variable for field name in filter expression

        What is the context of the filter expression. Ie query genie, xbasic code?
        Tim Kiebert
        Eagle Creek Citrus
        A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

        Comment


          #5
          Re: Using variable for field name in filter expression

          Mike,

          You asked:

          But this is not the actual filter is it? Usually a filter is double-quoted. And I assumed that the variable is also a logical

          No, I suppose it isn't. The code you saw was copied from the filter builder.

          See attached screen shot.

          Louis

          Comment


            #6
            Re: Using variable for field name in filter expression

            Hey Tim,

            The filter is being used to limit the records displayed in a record list list box which is contained in an X-Dialog box.

            Thanks for jumping in on this one.

            Louis

            Comment


              #7
              Re: Using variable for field name in filter expression

              So vc_qualification actually represents a table field which can be any that it is set to prior to this filter....I have done this but cannot remember exactly how....very possible I needed either eval(var->vc_qualification) or evaluate_template(var->vc_qualification)

              Tim--you're the one who first brought evaluate_template() to my attention...am I on the right track??? :)
              Mike
              __________________________________________
              It is only when we forget all our learning that we begin to know.
              It's not what you look at that matters, it's what you see.
              Henry David Thoreau
              __________________________________________



              Comment


                #8
                Re: Using variable for field name in filter expression

                Mike,

                Yes, that's what I need to do.

                I will check out eval() and evaluate_template() to see if I can make some headway.

                Thanks again!

                Louis

                Comment


                  #9
                  Re: Using variable for field name in filter expression

                  To simplify a bit.... when testing a logical var or field you don't need to use '= .t.' as the var or field is inherently true or false. That just leaves resolving the variable to a field name. Not sure if this works in the context of the filter builder but try eval(var->vc_qualification).

                  As per MikeC

                  I am a bit behind you guys today. :)
                  Tim Kiebert
                  Eagle Creek Citrus
                  A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

                  Comment


                    #10
                    Re: Using variable for field name in filter expression

                    Mike & Tim,

                    I have tried using both eval() and evaluate_template as you suggested. I also gave evaluate_string() a shot, but no luck.

                    In the Interactive Window:

                    vc_field_name="ABC"

                    ?eval("vc_field_name")
                    = "ABC"

                    ?evaluate_string("{vc_field_name}")
                    = "ABC"


                    Evaluate_Template() appears to be used for executing commands and probably isn't used in this context.

                    Regardless, I can't seem to get eval() or evaluate_string() to work in my filter.

                    Maybe I just need to call it a night and start with a fresh mind tomorrow.

                    Thank you both for your help.

                    Louis

                    Comment


                      #11
                      Re: Using variable for field name in filter expression

                      possibly
                      eval(var->vc_qualification+".value")

                      Would be my next guess....

                      sample??? I'll have some time tomorrow to play with it if still at a dead end.
                      Mike
                      __________________________________________
                      It is only when we forget all our learning that we begin to know.
                      It's not what you look at that matters, it's what you see.
                      Henry David Thoreau
                      __________________________________________



                      Comment


                        #12
                        Re: Using variable for field name in filter expression

                        In my previous post I said that you do not need the "= .t.".
                        After doing some testing in the query genie against a form I have found that if the variable is declared as shared/session then you don't need it (but no problem if you include it) but if declared as global then you do. I don't know why. Lets call it a quirk. So for now ignore my advice and leave it in.

                        Have you tried eval(vc_field_name)? ie without the quotes.

                        As you have seen eval("vc_field_name") evaluates to the name(value) you assigned to vc_field_name. This is because eval() is evaluating the quoted expression which resolves to vc_field_name which contains "ABC"


                        Without the quotes, eval(vc_field_name), the eval() function evaluates the string contained in vc_field_name which is "ABC". Which would be the same as having eval("ABC").

                        Code:
                        ABC = .t.
                        
                        vc_field_name="ABC"
                        
                        ?eval("vc_field_name")
                        = "ABC"
                        
                        ?eval(vc_field_name)
                        = .T.
                        
                        ?eval("ABC")
                        = .T.
                        So I would be trying eval(var->vc_qualification) = .t.
                        Tim Kiebert
                        Eagle Creek Citrus
                        A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

                        Comment


                          #13
                          Re: Using variable for field name in filter expression

                          Tim and Mike,

                          No luck with your suggestions.

                          I will piece together a working example and post it to this thread. I'm off to work right now so it will be later this afternoon before I have the time to put this together.

                          Thank you both for your help!

                          Louis

                          Comment


                            #14
                            Re: Using variable for field name in filter expression

                            Maybe this seems old-school, but I am coming from a lot of code in ver 5 and ver 9, and this method works for me every time.

                            If this is actually in x-basic, then the code:

                            Code:
                            (Display_name <> Var->vc_U_1 ) .and. (Display_name <> Var->vc_U_2 ) .and. (Display_name <> Var->vc_U_3 ) .and. (var->vc_qualification=.T.)
                            should look something like this:

                            Code:
                            DIM filt as C
                            filt = replace_parameters("Display_name <> [Var->vc_U_1] ) .and. (Display_name <> [Var->vc_U_2] ) .and. (Display_name <> [Var->vc_U_3] ) .and. ([var->vc_qualification]=.T.",local_variables())
                            then use "Filt" as the filter part of the expression.

                            Tom

                            Comment


                              #15
                              Re: Using variable for field name in filter expression

                              Tim,
                              I missed that Louis had quoted the variables instead of using what I had shown (no quotes)--nice explanation.

                              Tom,
                              I have not used the replace_parameters function except when left as a remnant of Action Scripting when converting scripts....but the help file stipulates the var-> has to have the variable type included...does it work without this being used?
                              The parameters in the expression must be enclosed in square brackets ( [ ] ) and are preceded with varC->, varN->, varD-> or varL->, depending on the type of the variable.
                              Note : You must use Version 6 or higher to support varT->.

                              Louis,
                              Looking forward to your sample.
                              Mike
                              __________________________________________
                              It is only when we forget all our learning that we begin to know.
                              It's not what you look at that matters, it's what you see.
                              Henry David Thoreau
                              __________________________________________



                              Comment

                              Working...
                              X