NetTalk Central

Author Topic: Another use for Browse record validation  (Read 4356 times)

ccordes

  • Sr. Member
  • ****
  • Posts: 384
    • View Profile
    • Email
Another use for Browse record validation
« on: October 19, 2007, 08:11:10 AM »
Hi
I didn't know whether to post this as a question - Is there a better place to do this ...
or as a feature request - Please don't change the way you validate browse records...
or as a Tip/Trick - Here is a way to make a file loaded browse from a Queue . . .

So I'll opt for the 'Maybe there is a better place to do this -
I'm displaying a distribution of some data. So I run through my file and load all the values into a queue so I can aggregate the values and calculate the cumulative counts and percents to total, etc.
I n order to do that without creating a memtable, a pre-process and a separate procedure for the result browse, I put some code like this into the Validate Record embed.
========================
      !Load the queue and cycle. When it breaks it will display the queue
          PerfRecord :=: Per:Record
          rg :=: WorkGroup     
          x# = CalcFactors(PerfRecord,rg)     
          WorkGroup :=: rg

          Clear(ResultQ)
          ResultQ.dValue = WorkGroup.dValue
          get(ResultQ,ResultQ.dValue)
          if error()
              clear(ResultQ)
              ResultQ.dValue = WorkGroup.dValue
              Add(ResultQ,ResultQ.dValue)
              get(ResultQ,ResultQ.dValue)
          end
          Resultq.dCount+=1
          totrecs += 1
          put(ResultQ,ResultQ.dValue)
      END !Loop - This processes the next record from the file
!=================================================================
      !Now our own display Loop
      sort(ResultQ,ResultQ.dValue)
      CumCount=0
      loop Rqi# = 1 to (records(ResultQ)+1)
        If RQi# > Records(ResultQ)  !ErrorCode()   !Simulate an end of file error
            if loc:rowstarted
              packet = clip(packet) & '</tr>'&CRLF
              do AddPacket
              loc:rowstarted = 0
            End
            Break
        END
          get(ResultQ,RQi#)
          CumCount += ResultQ.dCount
          Resultq.dCumCount = CumCount
          Resultq.dCumPercent = round(100*CumCount/TotRecs,.01)
          put(ResultQ)
      !This loop is completed by the template which has the Resultq fields to display
 
=========================================
This works like a charm since the Browse is file-loaded and there is no going backward to worry about.

Of course, if Bruce decides to use a record validator method call rather than some embedded code here, I'm may be sunk!

If anyone knows of a better solution, I'm open to suggestions.

Thanks,
Chris C.
Real programmers use copy con newapp.exe

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Another use for Browse record validation
« Reply #1 on: October 21, 2007, 11:30:06 PM »
Hi Chris,

There is, alas, a reason I don't support queues. In this example of your code, you'll get very strange happenings if multiple people request this page at the same time, because Queues are not thread safe.

Of course I mention this as a warning, not a prohibition. I'd recommend a memory-file instead of a queue though, as that _is_ thread safe.

cheers
Bruce

ccordes

  • Sr. Member
  • ****
  • Posts: 384
    • View Profile
    • Email
Re: Another use for Browse record validation
« Reply #2 on: October 22, 2007, 06:49:30 AM »
If it were a global queue I would agree but is a local queue still not thread safe?
Aren't global queues used to manage the session values?  ???

chris
Real programmers use copy con newapp.exe