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

Help with code

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

    Help with code

    I have been troubeshooting the following code for two days now. It's pretty simple but I am missing something 'cause it won't do what I want. I think I have looked at it too long I can no longer figure out what the heck I am missing. Any help would be appreciated so I can move on to other modules. This code is part of a OnTimer routine set to every 1 seconds. It is polling for a time event based on a field entry into a database--the value is a C and is either 0, 30 or 60. If it is "0", it does not trigger--if it is "30" it (is supposed to set the trigger_tripped variable to .T.) if the number of seconds after midnight (VSecAftMid) is equal to the current number of seconds after midnight--that is what is not working. That would be the very last commented part of the code. What am I not seeing? Thanks in advance!


    'Set Trigger_Tripped variable to .F. and AAA_Ack to .T.
    AAA_Ack = a5_eval_expression("=.T.")
    Trigger_Tripped = a5_eval_expression("=.F.")

    'Define VSecAftMid as N
    DIM GLOBAL VSecAftMid AS N
    VSecAftMid = a5_eval_expression("=TOSECONDS(TIME())")

    'Create a new variable called 'AAA_DOW' and set its value to '=ALLTRIM(STR(DOW(Date()),1))
    dim Global AAA_DOW AS C
    AAA_DOW = convert_type(a5_eval_expression("=ALLTRIM(STR(DOW(Date()),1))",local_variables()),"C")

    'Find the Current Time Block based on VSecAftMid
    IF VSecAftMid >= 0 .AND. VSecAftMid < 3600
    VTB = 0
    Elseif VSecAftMid >= 3600 .AND. VSecAftMid < 7200
    VTB = 1
    Elseif VSecAftMid >= 7200 .AND. VSecAftMid < 10800
    VTB = 2
    Elseif VSecAftMid >= 10800 .AND. VSecAftMid < 14400
    VTB = 3
    Elseif VSecAftMid >= 14400 .AND. VSecAftMid < 18000
    VTB = 4
    Elseif VSecAftMid >= 18000 .AND. VSecAftMid < 21600
    VTB = 5
    Elseif VSecAftMid >= 21600 .AND. VSecAftMid < 25200
    VTB = 6
    Elseif VSecAftMid >= 25200 .AND. VSecAftMid < 28800
    VTB = 7
    Elseif VSecAftMid >= 28800 .AND. VSecAftMid < 32400
    VTB = 8
    Elseif VSecAftMid >= 32400 .AND. VSecAftMid < 36000
    VTB = 9
    Elseif VSecAftMid >= 36000 .AND. VSecAftMid < 39600
    VTB = 10
    Elseif VSecAftMid >= 39600 .AND. VSecAftMid < 43200
    VTB = 11
    Elseif VSecAftMid >= 43200 .AND. VSecAftMid < 46800
    VTB = 12
    Elseif VSecAftMid >= 46800 .AND. VSecAftMid < 50400
    VTB = 13
    Elseif VSecAftMid >= 50400 .AND. VSecAftMid < 54000
    VTB = 14
    Elseif VSecAftMid >= 54000 .AND. VSecAftMid < 57600
    VTB = 15
    Elseif VSecAftMid >= 57600 .AND. VSecAftMid < 61200
    VTB = 16
    Elseif VSecAftMid >= 61200 .AND. VSecAftMid < 64800
    VTB = 17
    Elseif VSecAftMid >= 64800 .AND. VSecAftMid < 68400
    VTB = 18
    Elseif VSecAftMid >= 68400 .AND. VSecAftMid < 72000
    VTB = 19
    Elseif VSecAftMid >= 72000 .AND. VSecAftMid < 75600
    VTB = 20
    Elseif VSecAftMid >= 75600 .AND. VSecAftMid < 79200
    VTB = 21
    Elseif VSecAftMid >= 79200 .AND. VSecAftMid < 82800
    VTB = 22
    Else VSecAftMid >= 82800 .AND. VSecAftMid =< 86399
    VTB = 23
    End if

    'Find the current day and time block and store the field value to V->V_AAA_Interval_Factor.
    dim tbl as p
    tbl = table.open("aaa_intervals")
    query.filter = "dow_num = AAA_DOW .and. time_block = Var->VTB"
    query.order = ""
    query.flags = ""
    dim i_tbl as p
    i_tbl = tbl.query_create()
    dim recs as n
    recs = i_tbl.records_get()
    if recs = 0 then
    ui_msg_box("Error","No records satisfy the query '" + query.filter + "'.",UI_STOP_SYMBOL)
    end
    end if
    tbl.fetch_first()

    DIM Global V_Aaa_Interval_Factor AS C
    V_Aaa_Interval_Factor = tbl.eval("Aaa_Interval_Factor")

    tbl.close()

    DIM VCounter as N = -1


    'Check for Time event every 30 minutes on the hour and half hour

    if V_Aaa_Interval_Factor = "30"
    while VCounter<=48
    VCounter = VCounter + 1
    If VCounter*1800 = VSecAftMid
    Trigger_Tripped = .T.
    AAA_Ack = .F.
    exit while
    end if
    wend
    elseif V_Aaa_Interval_Factor = "60"

    'Check for time event overry hour on the hour
    while VCounter<=24
    VCounter = VCounter + 1
    If VCounter*3600 = VSecAftMid
    Trigger_Tripped = .T.
    AAA_Ack = .F.
    exit while
    else
    exit while
    end if
    wend
    end if

    #2
    Re: Help with code

    VSecAftMid will seldom be exactly vCounter times either 1800 or 3600. You need some sort of between values test.

    Code:
    VSecAftMid = toseconds(time())
    ? VSecAftMid
    = 39621.000000
    vCounter = 0
    ? between(VSecAftMid,1800*vCounter,1800*(vCounter+1))
    = .F.
    
    vCounter = 20
    ? between(VSecAftMid,1800*vCounter,1800*(vCounter+1))
    = .F.
    
    vCounter = 21
    ? between(VSecAftMid,1800*vCounter,1800*(vCounter+1))
    = .F.
    
    vCounter = 22
    ? between(VSecAftMid,1800*vCounter,1800*(vCounter+1))
    = .T.
    There can be only one.

    Comment


      #3
      Re: Help with code

      So that's why it's not trapping it huh? I had a feeling it was in the math...

      Comment


        #4
        Re: Help with code

        Yes but I am trapping for specific time events, i.e., on the hour and on the half hour--not just random times. If the Vcounter times 1800 = seconds past midnight, it's supposed to trap the Trigger_Tripped variable and change it to .T. It's not doing that...

        Comment


          #5
          Re: Help with code

          It's more the logic than the math. Minor adjustments. (same for the hours test)

          Code:
          while VCounter<48 [COLOR="#0000FF"]'note now just less than --- vcounter+1 tests the upper limit[/COLOR]
          VCounter = VCounter + 1
          If Between(VSecAftMid,VCounter*1800,(VCounter+1)*1800)
          Trigger_Tripped = .T.
          AAA_Ack = .F.
          exit while
          end if
          wend
          There can be only one.

          Comment


            #6
            Re: Help with code

            Stan, I appreciate your help but are we atlking about the same issue? If my OnTimer is polling every second, I wouldn't have a value "range" would I? My applicaation is a security log with a built in feature to trigger a required response event every 30 or 60 minutes on the hour and half hour. The OnTimer polls every second and reads the seconds after minute value into the variable VSecAftMid. The loop tests for whether the value (VCounter*1800 for every half hour or VCounter*3600 if polling for every occurance on the hour) to see if it's an exact match for VSecAftMid. For some reason, and it may be what you are referring to, it's not seeing the match-up of VCounter result and the value of VSecAftMid--I am stumped because this is programming 101. I won't bug you if you've had enough of this issue--I'll figure it out in a couple days I hope. Thanks again--BTW, I discovered/learned a new function today (Between()) thanks to your help! Best, Dean

            Comment


              #7
              Re: Help with code

              By the time I finished examining the code I apparently forgot about the ontimer.

              I just tested an abbreviated version and it fired for me at 12:30 local. (Fired again at 1 PM local)

              Perhaps there's an issue with

              Code:
              DIM Global V_Aaa_Interval_Factor AS C
              'V_Aaa_Interval_Factor = tbl.eval("Aaa_Interval_Factor")
              ??

              My test code.

              Code:
              'Set Trigger_Tripped variable to .F. and AAA_Ack to .T.
              AAA_Ack = a5_eval_expression("=.T.")
              Trigger_Tripped = a5_eval_expression("=.F.")
              
              'Define VSecAftMid as N
              DIM GLOBAL VSecAftMid AS N
              VSecAftMid = a5_eval_expression("=TOSECONDS(TIME())")
              
              'Create a new variable called 'AAA_DOW' and set its value to '=ALLTRIM(STR(DOW(Date()),1))
              dim Global AAA_DOW AS C
              AAA_DOW = convert_type(a5_eval_expression("=ALLTRIM(STR(DOW(Date()),1))",local_variables()),"C") 
              
              DIM VCounter as N = -1
              V_Aaa_Interval_Factor = "30" 'no table to supply value, try hard coding it
              
              'Check for Time event every 30 minutes on the hour and half hour
              
              if V_Aaa_Interval_Factor = "30"
              while VCounter<=48
              VCounter = VCounter + 1
              If VCounter*1800 = VSecAftMid
              	ui_msg_box("Note:","vCounter is "+alltrim(str(vCounter))+crlf()+"vSecaftmid is "+alltrim(str(vSecaftmid)))
              'Trigger_Tripped = .T.
              'AAA_Ack = .F.
              exit while
              end if
              wend
              elseif V_Aaa_Interval_Factor = "60"
              
              'Check for time event overry hour on the hour
              while VCounter<=24
              VCounter = VCounter + 1
              If VCounter*3600 = VSecAftMid
              	ui_msg_box("Note:","vCounter is "+alltrim(str(vCounter))+crlf()+"vSecaftmid is "+alltrim(str(vSecaftmid)))
              'Trigger_Tripped = .T.
              'AAA_Ack = .F.
              exit while
              else
              exit while
              end if
              wend
              end if
              Last edited by Stan Mathews; 09-23-2011, 02:13 PM. Reason: (Fired again at 1 PM local)
              There can be only one.

              Comment


                #8
                Re: Help with code

                Hey Stan, Looks like you nailed it! I am burnt out for today and will modify your code with fresh and rested eyes tomorrow to try it out. I REALLY appreciate your help! Thanks, Dean

                Comment


                  #9
                  Re: Help with code

                  Dean,
                  The equation being tested is vcounter*1800. This will yield only 48 exact values. The VSecAftMid will have to be exactly one of those 48 values or a match is not made. Your cutting it too close with the exactness of the number being 1 second and a time of firing every second. I think the span idea is correct to establish a little tolerance so the exact match is not required. I would make it be a 2 second tolerance range with the following:
                  Code:
                  while VCounter<48            'note now just less than --- vcounter+1 tests the upper limit
                         VCounter = VCounter + 1
                         If between(VSecAftMid,(vcounter*1800)-1,(vcounter*1800)+1)
                              Trigger_Tripped = .T.
                              AAA_Ack = .F.
                              sleep(3)            'delay so next timer event won't possibly produce a match
                              exit while
                         end if
                  wend
                  I also could not get it to work without changing the filter to
                  Code:
                  query.filter = "dow_num = "+quote(AAA_DOW) + " .and. time_block="+Var->VTB
                  Mike W
                  __________________________
                  "I rebel in at least small things to express to the world that I have not completely surrendered"

                  Comment


                    #10
                    Re: Help with code

                    Okay, now I'm really stumped. I used info from the two replies to create the attached code. The V_Aaa_Interval_Factor seems to be reading properly from the table (I globalized the value and pasted it onto the runtime screen), however, it only evaluates the "30" loop not the "60" loop. I just don't understand why this isn't working...I must be having a major brain fart or something! The hardcoded V_Aaa_Interval_Factor variable seemed to work fine...I am using the Quote() feature to evaluate the table field.

                    'Set Trigger_Tripped variable to .F. and AAA_Ack to .T.
                    AAA_Ack = a5_eval_expression("=.T.")
                    Trigger_Tripped = a5_eval_expression("=.F.")

                    'Define VSecAftMid as N
                    DIM GLOBAL VSecAftMid AS N
                    VSecAftMid = a5_eval_expression("=TOSECONDS(TIME())")

                    'Check for Time event every 30 minutes on the hour and half hour
                    DIM VCounter as N = -1
                    while VCounter<=48 .and. V_Aaa_Interval_Factor = "30"
                    VCounter = VCounter + 1
                    If VCounter*1800 = VSecAftMid then
                    Trigger_Tripped = .T.
                    AAA_Ack = .F.
                    ui_msg_box("Note:","vCounter is "+alltrim(str(vCounter))+crlf()+"vSecaftmid is "+alltrim(str(vSecaftmid)))
                    exit while
                    end if
                    wend

                    'Check for time event every hour on the hour
                    while VCounter<=24 .and. V_Aaa_Interval_Factor = "60"
                    VCounter = VCounter + 1
                    If VCounter*3600 = VSecAftMid then
                    Trigger_Tripped = .T.
                    AAA_Ack = .F.
                    ui_msg_box("Note:","vCounter is "+alltrim(str(vCounter))+crlf()+"vSecaftmid is "+alltrim(str(vSecaftmid)))
                    exit while
                    else
                    exit while
                    end if
                    wend

                    Comment


                      #11
                      Re: Help with code

                      'Store Interval_Factor field to V_AAA_Interval_Factor
                      dim tbl as p
                      tbl = table.open("aaa_intervals")
                      query.filter = "dow_num = "+quote(AAA_DOW) + " .and. time_block="+Var->VTB
                      query.order = ""
                      query.flags = ""
                      dim i_tbl as p
                      i_tbl = tbl.query_create()
                      dim recs as n
                      recs = i_tbl.records_get()
                      if recs = 0 then
                      ui_msg_box("Error","No records satisfy the query '" + query.filter + "'.",UI_STOP_SYMBOL)
                      end
                      end if
                      tbl.fetch_first()

                      DIM Shared V_Aaa_Interval_Factor AS C
                      V_Aaa_Interval_Factor = tbl.eval("Aaa_Interval_Factor")
                      tbl.close()

                      Comment


                        #12
                        Re: Help with code

                        Thanks for the help--I found the culprit!

                        exit while
                        else
                        exit while
                        end if
                        wend

                        It was a simple loop error--the "else" and "exit while" were not only not needed, they were causing the program not to execute properly. Problem solved!

                        Comment

                        Working...
                        X