🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.vdbase.forms
Article #53

Re: Calculate fields in a grid

#53
From: Peter Rorlick
Date: Fri, 12 Mar 1999 00:00
86 lines
3800 bytes
This is a multi-part message in MIME format.
--------------582860273D0CED10A31FB0BA
Content-Type: text/plain; charset=us-ascii
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Transfer-Encoding: 7bit

Calciotel wrote:

> It's possible insert in a grid of a form a column with the result of a
>
> function calculated??

Yes.  See the attached file.

-------------------------
Peter Rorlick
Montreal Business Software


--------------582860273D0CED10A31FB0BA
Content-Type: text/plain; charset=us-ascii; name="calcfiel.how"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="calcfiel.how"

CalcFiel.How  -  How to put a calculated field onto a grid

Visual dBase 7 HOW file

Author: Peter Rorlick
Date: Dec 16 1997
*----------------------------------------------------

Here's a step-by-step example of how to create a calculated field and
how to get that field to show up on a grid.
(Note: a similar technique can be used to get calculated fields onto
reports.)

Begin designing a new form.

Using the navigator, switch to the \Samples\Fleet\Tables directory.

Click on the Tables tab and drag and drop Aircraft.dbf onto your form.
This will create a query object on the form, called Aircraft1.

Using the inspector, go the Events tab for the query object and click on
the tool button of the OnOpen event.
In the function called Aircraft1_OnOpen, type:
      oField=new Field()
      oField.FieldName := "Make and model"
      This.Rowset.Fields.Add(oField)
      oField.BeforeGetValue := {; Return Trim(This.Parent["Make"].Value)
+ space(1) + This.Parent["Model"].Value }

You have just instructed the query to add a calculated field, showing
Make and Model in a single column.

Note that you can sometimes create calculated fields more simply, in the
SQL "SELECT...FROM..." statement.  But the way we're doing it here is
much more powerful, because the .BeforeGetValue is handled by VdB rather
than by the SQL engine. This means that you can use xbase functions and
UDFs to construct your calculated fields - and this is a vital
difference. SQL is nice but it is sometimes not flexible enough.

From the Component Palette, drop a grid onto the form, and enlarge it.
Select the grid, and using the inspector, click on the dropdown button
of the DataLink property, and set it to Aircraft1.
As soon as you do this, you'll notice that the grid becomes populated
with rows from the table.

Now, our goal is to get the calculated field onto the grid. To do this
you will need to run the query again so that "Make and model" will be
available in the Column Selector tool.  Unfortunately, if you try to set
the query's Active property to false and then back to true, you'll get
an error.  But you can effectively run the query again by saving the
form (call it MyGrid.WFM) and then open it again with the designer.
Once you have done that, click on the grid, bring up the inspector, and
click on the tool button of the Columns property.  Double-click on the
"Make and model" field, and then double-click on the "Layout Image"
field. Click on the OK button.

Save the form and run it.  Voila!



--------------582860273D0CED10A31FB0BA--
Technical Details
Message-ID: <36E92320.325B3054@InjuryTracker.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7ca9ph$mjk19@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 15bdfb,f1171a0f30edfd71
X-Google-Attributes: gid15bdfb,public
From: Peter Rorlick <peter@InjuryTracker.com>
Subject: Re: Calculate fields in a grid
Date: 1999/03/12
Message-ID: <36E92320.325B3054@InjuryTracker.com>
X-Deja-AN: 454202394
References: <7ca9ph$mjk19@forums.borland.com>
X-Priority: 3 (Normal)
Content-Type: multipart/mixed; boundary="------------582860273D0CED10A31FB0BA"
Organization: MBS
Mime-Version: 1.0
Newsgroups: borland.public.vdbase.forms