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

date as as variable in a filter. Why is this so hard?

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

    date as as variable in a filter. Why is this so hard?

    I have such trouble with the syntax of date variables in filters. How does one get the character date variable to filter a table date field value? I've spent hours reading threads and trying to get this one silly thing to work. It drives me NUTS!!!!!

    Code:
    [B]? a5_get_records_in_query("comp","comp_date = {11/24/2008}")
    = 3[/B]
    
    dim vcdNow as C
    dim vddNow as D
    dim vfilter as C
    
    vcdNow = dtoc(date())
    ? vcdNow
    = "11/24/2008"
    
    vddNow = ctod(vcdNow)
    ? vddNow
    = {11/24/2008}
    
    vfilter = "comp_date = {11/24/2008}"
    ? a5_get_records_in_query("comp",vfilter)
    = 0
    
    vfilter = "comp_date = "+var->vddNow
    ? a5_get_records_in_query("comp",vfilter)
    = 0
    
    ? a5_get_records_in_query("comp","comp_date = vddNow)")
    = 0
    
    >>>>> and many, many others
    Mike W
    __________________________
    "I rebel in at least small things to express to the world that I have not completely surrendered"

    #2
    Re: date as as variable in a filter. Why is this so hard?

    Mike, long ago I put together a set of examples for the help file. Read the docs on Tablecount(). -- tom

    Comment


      #3
      Re: date as as variable in a filter. Why is this so hard?

      Mike

      ? a5_get_records_in_query("comp","comp_date = {11/24/2008}")
      = 3

      dim vcdNow as C
      dim vddNow as D
      dim vfilter as C

      vcdNow = dtoc(date())
      ? vcdNow
      = "11/24/2008"

      vddNow = ctod(vcdNow) ' this changed vcdnow from a character variable to a date variable
      ? vddNow
      = {11/24/2008}


      vfilter = "comp_date = {11/24/2008}" ' this filter is all character - that is what a5_get_records in query is looking for.



      ? a5_get_records_in_query("comp",vfilter)
      = 3


      vfilter = "comp_date = "+"{"+dtoc(vddNow)+"}" 'this changes the vddnow to a character variable - again that is what the function is looking for


      ? a5_get_records_in_query("comp",vfilter)
      = 3


      ? a5_get_records_in_query("comp","comp_date = vddNow)")
      The above is from my interactive window.

      I changed one of the vfilter's expression. It is in red.

      The last one won't work as it is, it could be stated as the one in red.

      I don't know if this is what you are after -

      Tom Baker

      Comment


        #4
        Re: date as as variable in a filter. Why is this so hard?

        Tom C,
        I could not for the life of me remember where that was, thank you, again. It has a been a while since I have worked with dates.

        Tom B,
        I cannot decipher that syntax and have it make any sense to me which is why it is one that I will likely never remember. So, I just have to remember -tablecount().

        Thanks again.
        Mike W
        __________________________
        "I rebel in at least small things to express to the world that I have not completely surrendered"

        Comment


          #5
          Re: date as as variable in a filter. Why is this so hard?

          Originally posted by Mike Wilson View Post
          I cannot decipher that syntax and have it make any sense to me
          Code:
          vfilter = "comp_date = {11/24/2008}"
          The filter portion on the right is a literal string. You want to "drop in" a date variable with a net no change to the string

          Code:
          [COLOR="Red"]vfilter = "comp_date = {"[/COLOR][COLOR="Green"][SIZE="4"]+[/SIZE][/COLOR]11/24/2008[COLOR="green"][SIZE="4"]+[/SIZE][/COLOR][COLOR="Blue"]"}"[/COLOR]
          I ended the first part (red) with a quote and began the second part (blue) with a quote. I used plus signs (green) to add the parts together.

          Now replace the literal date with a variable (magenta).

          Code:
          [COLOR="Red"]vfilter = "comp_date = {"[/COLOR][COLOR="Green"][SIZE="4"]+[/SIZE][/COLOR][COLOR="Magenta"]somevariable[/COLOR][COLOR="green"][SIZE="4"]+[/SIZE][/COLOR][COLOR="Blue"]"}"[/COLOR]
          Almost there but since the variable is a date type and we need character parts to add together, use dtoc() (dark orchid) to change the date to character.

          Code:
          [COLOR="Red"]vfilter = "comp_date = {"[/COLOR][COLOR="Green"][SIZE="4"]+[/SIZE][/COLOR][COLOR="Magenta"][COLOR="DarkOrchid"]dtoc([/COLOR]somevariable[COLOR="darkorchid"])[/COLOR][/COLOR][COLOR="green"][SIZE="4"]+[/SIZE][/COLOR][COLOR="Blue"]"}"[/COLOR]
          There can be only one.

          Comment


            #6
            Re: date as as variable in a filter. Why is this so hard?

            Mike, just to expand on Stan's example (I only changed the spacing to make it more readable).


            vfilter = "comp_date={" + dtoc(somevariable) + "}"

            Translation:
            vfilter = string1 in quotes PLUS a date variable converted to a character PLUS string2 in quotes



            Putting it all into the I.E., this is what you get"
            Code:
            somevariable = date()
            ?somevariable
            = {11/24/2008}
            
            vfilter = "comp_date={" + dtoc(somevariable) + "}"
            ?vfilter
            = "comp_date={11/24/2008}"
            Peter
            AlphaBase Solutions, LLC

            [email protected]
            https://www.alphabasesolutions.com


            Comment


              #7
              Re: date as as variable in a filter. Why is this so hard?

              Thank you all.
              Really!

              The hardest part for me to conceptualize is why there is a requirement to generate character values from the date values when the field values are date and the variable is scoped as date. Logically, for my mind, it should flow directly. But it doesn't seem to be that.... it seem to flow through a character value interlace. Why this interlace is a requirement for a date variable to be converted to a character value and manipulated into a character string in order to resolve a date field value is just beyond my scope of appreciation/conceptulization. I get it now that date needs to be converted to character and strung with character rules..... but Goodness sakes..... why a variable scoped as date does not directly equal a field date value????? I guess I am just plainly too simple for this game.
              Mike W
              __________________________
              "I rebel in at least small things to express to the world that I have not completely surrendered"

              Comment


                #8
                Re: date as as variable in a filter. Why is this so hard?

                If you are creating a filter in the expression builder for a layout, it is pretty simple, right?

                comp_date = {11/24/2008} or comp_date = somedatevariable

                is all you need.

                But that is not what is happening.You are writing a script and creating a line that assigns a value to a variable holding a filter string. Anything inside a pair of quotes is "literal".

                Code:
                ? "my name is mud"
                = "my name is mud"
                
                somevar = "Joe"
                
                ? "my name is somevar"
                = "my name is somevar"
                Alpha has no idea that we really wanted it to substitute the value Joe in the "my name is ..." string.

                The filter string can be written "whole" or it can be built from parts that are strings.

                vfilter = "comp_date = {11/24/2008}" or
                vfilter = "co"+"mp"+"_d"+"at"+"e = {"+"11/24/20"+"08}"

                Try those in the interactive editor....

                Code:
                ? "comp_date = {11/24/2008}" 
                = "comp_date = {11/24/2008}"
                
                ? "co"+"mp"+"_d"+"at"+"e = {"+"11/24/20"+"08}"
                = "comp_date = {11/24/2008}"
                
                'or even
                v1 = "co"
                v2 = "mp"
                v3 = "_d"
                v4 = "at"
                v5 = "e = {"
                v6 = "11/24/20"
                v7 = "08}"
                ? v1+v2+v3+v4+v5+v6+v7
                = "comp_date = {11/24/2008}"
                All yield the same result....the second two are made up of multiple string parts. No numeric values, no date values, no any data types except character.
                Last edited by Stan Mathews; 11-25-2008, 09:35 AM.
                There can be only one.

                Comment


                  #9
                  Re: date as as variable in a filter. Why is this so hard?

                  Just need to watch out for Alpha's auto type conversion when concatenating non character to character.
                  Code:
                  vfilter = "date = {16/01/2007}"  [COLOR=Blue]'here a date formatted string in side curly brackets is a date type value[/COLOR]
                  
                  ? a5_get_records_in_query("invoice_header",vfilter)  [COLOR=Blue]'as you can see it works here.[/COLOR]
                  = 2
                  
                  ?vfilter
                  = "date = {16/01/2007}"
                  
                  qq = {16/01/2007}  [COLOR=Blue]' here we assign a date to qq[/COLOR]
                  ?typeof(qq)            [COLOR=Blue]' test the type here, it is still a date[/COLOR]
                  = "D"
                  
                  ?qq
                  = {16/01/2007}    [COLOR=Blue]'it is still  a date[/COLOR]
                  
                  [COLOR=Blue]' However now we go and build a filter[/COLOR]. [COLOR=Blue]
                  'Too easy we say. Just need to concatenate the variable to the 
                  constant part.  The trouble is we now have two pieces. The first part, [/COLOR] 
                  "date = "[COLOR=Blue]  is a string and according to Alpha's auto type conversion the
                   date value is converted to a string[/COLOR] [COLOR=Blue]before concatenation and voila
                   the date value is no more[/COLOR]
                  vfilter = "date = " + qq  
                  ?vfilter
                  = "date = 16/01/2007"
                  [COLOR=Blue]
                  I usually use s_quote like so[/COLOR]
                  vfilter = "date = " + s_quote(qq)
                  ?vfilter
                  = "date = {16/01/2007}"
                  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: date as as variable in a filter. Why is this so hard?

                    Thank you Stan,

                    So, I guess what is needed then is a function s_curlys() for date variables similar to s_quote() for character variables. What do you think.... a valid wish list item?

                    LATER: Oh, egg on my face... again. Thanks Tim. So s_quote() does fulfill this situation with dates as it does with character. I believe I have it, golly be!
                    Last edited by Mike Wilson; 11-25-2008, 11:24 AM.
                    Mike W
                    __________________________
                    "I rebel in at least small things to express to the world that I have not completely surrendered"

                    Comment


                      #11
                      Re: date as as variable in a filter. Why is this so hard?

                      Originally posted by Mike Wilson View Post
                      Thank you Stan,

                      So, I guess what is needed then is a function s_curlys() for date variables similar to s_quote() for character variables. What do you thing.... a valid wish list item?

                      I don't think s_curlys() would be needed. That is actually the whole point of the s_quote() function. If you want to quote a character variable then quote() will suffice even though s_quote() also works. S_quote is meant to take care of char, num, date, and logical types.


                      Oh, egg on my face... again.
                      I here that is good for the complexion :D We can save s_curlys() for another purpose.
                      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


                        #12
                        Re: date as as variable in a filter. Why is this so hard?

                        S_quote() is great, once you understand the principle. In Mike's original thread we have a fairly simple single date to variable comparison. What if we wanted to concoct a filter string combining character, numeric, and date comparison. How about using dates in a between() expression in a date filter string.

                        I don't mean to prolong this thread if you're done Mike but try turning

                        between(datefield,var->date1,var->date2) into a filter string like

                        vFilter = "between(datefield,var->date1,var->date2)"

                        making the necessary alteratiions so that Alpha recognizes the date variables.

                        When you get the hang of this you have a very powerful tool to employ.
                        There can be only one.

                        Comment


                          #13
                          Re: date as as variable in a filter. Why is this so hard?

                          Funny you should mention that Stan, because I could not get between() to work. I keep getting an error (see pic). I got between_date() to work.
                          Mike W
                          __________________________
                          "I rebel in at least small things to express to the world that I have not completely surrendered"

                          Comment


                            #14
                            Re: date as as variable in a filter. Why is this so hard?

                            ahem...

                            So why wouldn't you check TABLECOUNT() there's a perfectly good example waiting for you?

                            Comment


                              #15
                              Re: date as as variable in a filter. Why is this so hard?

                              I could not get between() to work. I keep getting an error
                              Stay after class and write on the blackboard 500 times....

                              In Alpha a string is enclosed in quotes.

                              Not

                              vfilter = between(comp_date,{01/01/2008},{12/31/2008}

                              should be

                              vfilter = "between(comp_date,{01/01/2008},{12/31/2008}"
                              There can be only one.

                              Comment

                              Working...
                              X