Home > Archive > Programming with dBASE > December 2005 > Adding Columns









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 Adding Columns
Chris33

2005-12-24, 3:23 am

Pretty new to Dbase ... All help will be greatly apreciated.
I have a table with a column for Qty of an item and a column for price. i need to Multiply the 2 columns row by row to get a total for each row. I was wondering what the best way to do this was.

Thanks again
Chris
Chris33

2005-12-24, 3:23 am

Chris33 Wrote:

> Pretty new to Dbase ... All help will be greatly apreciated.
> I have a table with a column for Qty of an item and a column for price. i need to Multiply the 2 columns row by row to get a total for each row. I was wondering what the best way to do this was.
>
> Thanks again
> Chris



Sry Just want to make wure i made it clear the TOTAL needs to be stored in a column in the table called TOTAL (original i know).
Robert Bravery

2005-12-24, 7:23 am

HI Chriss,
Because this is a calculation, it make no sense to store it in the table,
just create a calculated field in your query
Have a look at the Online help for the new fieds class
Basically in your querys onopen method, create a new field, then in the new
fields beforgetvalue method you put the calculation you want.
Or you copuld do the same in a sql file
dbase query:
if file('x_temp.dbf')
drop table x_temp
endif

create table x_temp ( ;
emp_id smallint, ;
hours numeric(5,2))


// Add some data
cTypes = "ABCDEFGHIJK"
use x_temp
for i=1 to 50
append blank
replace emp_id with mod(i,10)+1, ;
hours with iif(mod(i,2)=0,1,2)
next i
use
close tables
** END HEADER -- do not remove this line
//
// Generated on 24/12/2005
//
parameter bModal
local f
f = new UntitledForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif

class UntitledForm of FORM
with (this)
onOpen = class::FORM_ONOPEN
height = 14.0909
left = 30.5714
top = 6.5455
width = 61.5714
text = ""
endwith

this.X_TEMP1 = new QUERY()
this.X_TEMP1.parent = this
with (this.X_TEMP1)
onOpen = class::X_TEMP1_ONOPE
N
left = 54.0
top = 0.2727
sql = 'select * from "x_temp.DBF"'
active = true
endwith

this.GRID1 = new GRID(this)
with (this.GRID1)
height = 12.1818
left = 1.4286
top = 0.5455
width = 57.7143
endwith

this.rowset = this.x_temp1.rowset

function form_onOpen
form.grid1.dataLink = form.x_temp1.rowset
return

function x_temp1_onOpen
c = new Field()
c.fieldName := "Total"
c.length = 10
form.X_TEMP1.rowset.fields.add(c)
c.beforeGetValue := {||this.parent["emp_id"].value *
this.parent["hours"].value}

return

endclass

Or a SQL file or command
SELECT emp_id, hours, (emp_id * hours) as Total FROM X_temp

so perhaps the previous form could be something like:

if file('x_temp.dbf')
drop table x_temp
endif

create table x_temp ( ;
emp_id smallint, ;
hours numeric(5,2))


// Add some data
cTypes = "ABCDEFGHIJK"
use x_temp
for i=1 to 50
append blank
replace emp_id with mod(i,10)+1, ;
hours with iif(mod(i,2)=0,1,2)
next i
use
close tables
** END HEADER -- do not remove this line
//
// Generated on 24/12/2005
//
parameter bModal
local f
f = new UntitledForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif

class UntitledForm of FORM
with (this)
height = 14.0909
left = 30.5714
top = 6.5455
width = 61.5714
text = ""
endwith

this.X_TEMP1 = new QUERY()
this.X_TEMP1.parent = this
with (this.X_TEMP1)
left = 54.0
top = 0.2727
sql = "SELECT emp_id, hours, (emp_id * hours) as Total FROM X_temp"
active = true
endwith

this.GRID1 = new GRID(this)
with (this.GRID1)
dataLink = form.x_temp1.rowset
height = 12.1818
left = 1.4286
top = 0.5455
width = 57.7143
endwith

this.rowset = this.x_temp1.rowset

endclass


Hope this helps

Robert






"Chris33" <cr6825@hotmail.com> wrote in message
news:$UkoKQFCGHA.1488@news-server...
> Pretty new to Dbase ... All help will be greatly apreciated.
> I have a table with a column for Qty of an item and a column for price. i

need to Multiply the 2 columns row by row to get a total for each row. I
was wondering what the best way to do this was.
>
> Thanks again
> Chris



Chris33

2005-12-25, 3:23 am

Thanks again Robert

What you said worked perfect.

Chris
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