Home > Archive > Getting Started with dBASE > July 2005 > Reluctant field changes









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Reluctant field changes
Norman Snowden

2005-07-23, 8:24 pm

When I make a change to a field from the form run screen the change shows on the form but does not take efect in calculations even if I move next and move back before I run the Form for calculated new fields.

The change is reflected in Browse and I have tried form.rowset.flush(), form.rowset.refreshControls() and form.rowset.Save() to no avail.

Somettimes after running Browse and repeating Form run 2 or 3 times the calculated changes do take place.

I can't understand this. Thanks for any comments.

Norman
John Marshall

2005-07-24, 7:24 am


try a form.rowset.requery() in the db in question. That will place the data in the rowset into the db and other form controls will reflect/calculate as expected.

JM


Norman Snowden Wrote:

> When I make a change to a field from the form run screen the change shows on the form but does not take efect in calculations even if I move next and move back before I run the Form for calculated new fields.
>
> The change is reflected in Browse and I have tried form.rowset.flush(), form.rowset.refreshControls() and form.rowset.Save() to no avail.
>
> Somettimes after running Browse and repeating Form run 2 or 3 times the calculated changes do take place.
>
> I can't understand this. Thanks for any comments.
>
> Norman


Roland Wingerter

2005-07-24, 7:24 am

Norman Snowden wrote:
> When I make a change to a field from the form run screen the change
> shows on the form but does not take efect in calculations even if I
> move next and move back before I run the Form for calculated new
> fields.
>
> The change is reflected in Browse and I have tried
> form.rowset.flush(), form.rowset.refreshControls() and
> form.rowset.Save() to no avail.

-------
Perhaps the Browse component is the cause of the problem. Most people here
will agree that it is better to forget the browse component and use a grid
instead.

Try the sample below. Note that the calculated field is updated whenever the
quantity or price of an item is changed. This is done in a method that is
called in the onChange event of both fields.

Roland

// Demo: Update a calculated field in a grid
close all
if file("test.dbf")
drop table "test.dbf"
endif

if not file("test.dbf")
create table "test.dbf" (;
qty numeric(4,0),;
item char(30),;
price numeric(8,2))
endif
** END HEADER -- do not remove this line
//
// Generated on 24.07.2005
//
parameter bModal
local f
f = new calcGridForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif

class calcGridForm of FORM
with (this)
height = 18.2727
left = 6.7143
top = 0.0
width = 94.5714
text = ""
endwith

this.QUERY2 = new QUERY()
this.QUERY2.parent = this
with (this.QUERY2)
left = 59.0
top = 0.5
sql = "select sum(qty*price) as totalsum from test"
active = true
endwith

this.QUERY1 = new QUERY()
this.QUERY1.parent = this
with (this.QUERY1)
onOpen = class::QUERY1_ONOPEN

left = 49.0
top = 0.5
sql = "select * from test.dbf"
active = true
endwith

with (this.QUERY1.rowset)
fields["qty" ].onChange = {; class::fields_onChan
ge()}
fields["price"].onChange = {; class::fields_onChan
ge()}
fields["calctotal"].beforeGetValue = {||this.parent["qty"].value *
this.parent["price"].value}
endwith

this.GRID1 = new GRID(this)
with (this.GRID1)
dataLink = form.query1.rowset
columns["COLUMN1"] = new GRIDCOLUMN(form.GRID1)
columns["COLUMN1"].dataLink = form.query1.rowset.fields["qty"]
columns["COLUMN1"].editorType = 1 // EntryField
columns["COLUMN1"].width = 8.8571
columns["COLUMN2"] = new GRIDCOLUMN(form.GRID1)
columns["COLUMN2"].dataLink = form.query1.rowset.fields["item"]
columns["COLUMN2"].editorType = 1 // EntryField
columns["COLUMN2"].width = 40.1429
columns["COLUMN3"] = new GRIDCOLUMN(form.GRID1)
columns["COLUMN3"].dataLink = form.query1.rowset.fields["price"]
columns["COLUMN3"].editorType = 1 // EntryField
columns["COLUMN3"].width = 17.1429
columns["COLUMN4"] = new GRIDCOLUMN(form.GRID1)
columns["COLUMN4"].dataLink = form.query1.rowset.fields["calctotal"]
columns["COLUMN4"].editorType = 1 // EntryField
columns["COLUMN4"].width = 17.1429
with (columns["COLUMN1"].editorControl)
validErrorMsg = "Ungültige Eingabe "
endwith

with (columns["COLUMN1"].headingControl)
value = "qty"
endwith

with (columns["COLUMN2"].editorControl)
validErrorMsg = "Ungültige Eingabe "
endwith

with (columns["COLUMN2"].headingControl)
value = "item"
endwith

with (columns["COLUMN3"].editorControl)
validErrorMsg = "Ungültige Eingabe "
endwith

with (columns["COLUMN3"].headingControl)
value = "price"
endwith

with (columns["COLUMN4"].headingControl)
value = "calctotal"
endwith

bgColor = "white"
height = 12.5
left = 2.0
top = 3.5
width = 90.0
endwith

this.ENTRYFIELD1 = new ENTRYFIELD(this)
with (this.ENTRYFIELD1)
dataLink = form.query2.rowset.fields["totalsum"]
height = 1.0
left = 71.0
top = 16.5
width = 18.0
endwith

this.TEXTLABEL1 = new TEXTLABEL(this)
with (this.TEXTLABEL1)
height = 1.0
left = 58.0
top = 16.5
width = 12.0
text = "Total:"
endwith

this.rowset = this.query1.rowset

function fields_onChange
// This method is called in the onChange event of
// the fields Qty and Price

// Calculate Qty * Price
this.parent["calctotal"].value = ;
this.parent["qty"].value * this.parent["price"].value

// Save new value before doing query2.requery()
this.parent.parent.save()

// this = field -> fields array -> rowset -> query -> form
this.parent.parent.parent.parent.query2.requery()
return

function query1_onOpen
// Create a calculated field
oFld = new field()
oFld.fieldName := "calctotal"
oFld.length := 10
oFld.value := 0
this.rowset.fields.add(oFld)
oFld.beforeGetValue := {||this.parent["qty"].value *
this.parent["price"].value}
return

endclass






Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com