hello experts,
i need someone to knows Xbasic to help me get this script (attached and listed below) working. this is my first attempt to write a script.
i am just trying to update a field in a child table one table by searching for the matching record in the parent table.
the is a very simple task and should be easy to code. it can be done very easily using FoxPro (see below).
i will pay for consulting services if anyone is interested in helping me on this and my Alpha Anywhere forms as well.
' _________________________________________________________________________________________
' This xbasic script file updates the custcode field in WarrReg table from custcode field in Customers
' The custcode field will be used to link these two tables together.
' Garth Groft 2015.4.2
' Program - WarrReg.custcode update script by Garth Groft.
' This program is based on example found in Alpha Anywhere Xbasic Workshop by Dr. Peter Wayne, Chapter 20.
' Date Created: 2015.3.6
' Last Updated: 2015.4.2
' Created By : Garth Groft
' Updated By : Garth Groft
' This program scans the WarrReg table from first to last record.
' For each WarrReg record, a query is run on the Customer table where RTRIM(customer.companynam) = RTRIM(WarrReg.customer_i)
' If the query finds the matching record, WarrReg.custcode is set to Customer.custcode.
' If not found, WarrReg.custcode is set to "no match".
' It is possible there are WarrReg.customer_i not present in Customer.companynam.
option strict
dim cust as p
dim warrreg as p
dim warrregCustname as c
dim query.options as c
dim shared query as p
dim shared query.filter as c
dim cnt as n
cust = table.open("customers",FILE_RW_SHARED)
'not used - query.filter = "RTRIM(customers.companynam) = RTRIM(warrreg.customer_i)"
' this filter contains warrregCustname (defined below as warrregCustname = warrreg.customer_i).
' the query will result in just one record.
'query.filter = "RTRIM(customers.companynam) = warrregCustname"
query.filter = "RTRIM(cust.companynam) = warrregCustname"
query.options = "T"
warrreg = table.open("warrreg",FILE_RW_SHARED)
warrreg.fetch_first()
while .not. warrreg.fetch_eof()
warrregCustname = warrreg.customer_i
cnt = cust.query_create()
warreg.change_begin()
if cnt > 0
'warrreg.custcode = customers.custcode
warrreg.custcode = cust.custcode
else
warrreg.custcode = "no match"
end if
warreg.change_end()
warrreg.fetch_next()
end while
warrreg.close()
cust.close()
end
' Working simple FoxPro Version ...
'USE c:\actwarrregvfp\customers.dbf IN 0 SHARED
'SET ORDER TO customerid IN Customers
'USE c:\actwarrregvfp\warrreg.dbf IN 0 SHARED
'SET RELATION TO Warrreg.customerid INTO Customers ADDITIVE
'*!* Note WarrReg cusstomerid needs meaning numbers entered.
'SELECT WarrReg
'SCAN
' REPLACE IN WarrReg custcode WITH Customers.custcode
'ENDSCAN
'*!* alternate coding method:
'*!* SELECT Customers
'*!* REPLACE ALL custcode WITH LEFT(customername,4) + STR(customerid,4)
i need someone to knows Xbasic to help me get this script (attached and listed below) working. this is my first attempt to write a script.
i am just trying to update a field in a child table one table by searching for the matching record in the parent table.
the is a very simple task and should be easy to code. it can be done very easily using FoxPro (see below).
i will pay for consulting services if anyone is interested in helping me on this and my Alpha Anywhere forms as well.
' _________________________________________________________________________________________
' This xbasic script file updates the custcode field in WarrReg table from custcode field in Customers
' The custcode field will be used to link these two tables together.
' Garth Groft 2015.4.2
' Program - WarrReg.custcode update script by Garth Groft.
' This program is based on example found in Alpha Anywhere Xbasic Workshop by Dr. Peter Wayne, Chapter 20.
' Date Created: 2015.3.6
' Last Updated: 2015.4.2
' Created By : Garth Groft
' Updated By : Garth Groft
' This program scans the WarrReg table from first to last record.
' For each WarrReg record, a query is run on the Customer table where RTRIM(customer.companynam) = RTRIM(WarrReg.customer_i)
' If the query finds the matching record, WarrReg.custcode is set to Customer.custcode.
' If not found, WarrReg.custcode is set to "no match".
' It is possible there are WarrReg.customer_i not present in Customer.companynam.
option strict
dim cust as p
dim warrreg as p
dim warrregCustname as c
dim query.options as c
dim shared query as p
dim shared query.filter as c
dim cnt as n
cust = table.open("customers",FILE_RW_SHARED)
'not used - query.filter = "RTRIM(customers.companynam) = RTRIM(warrreg.customer_i)"
' this filter contains warrregCustname (defined below as warrregCustname = warrreg.customer_i).
' the query will result in just one record.
'query.filter = "RTRIM(customers.companynam) = warrregCustname"
query.filter = "RTRIM(cust.companynam) = warrregCustname"
query.options = "T"
warrreg = table.open("warrreg",FILE_RW_SHARED)
warrreg.fetch_first()
while .not. warrreg.fetch_eof()
warrregCustname = warrreg.customer_i
cnt = cust.query_create()
warreg.change_begin()
if cnt > 0
'warrreg.custcode = customers.custcode
warrreg.custcode = cust.custcode
else
warrreg.custcode = "no match"
end if
warreg.change_end()
warrreg.fetch_next()
end while
warrreg.close()
cust.close()
end
' Working simple FoxPro Version ...
'USE c:\actwarrregvfp\customers.dbf IN 0 SHARED
'SET ORDER TO customerid IN Customers
'USE c:\actwarrregvfp\warrreg.dbf IN 0 SHARED
'SET RELATION TO Warrreg.customerid INTO Customers ADDITIVE
'*!* Note WarrReg cusstomerid needs meaning numbers entered.
'SELECT WarrReg
'SCAN
' REPLACE IN WarrReg custcode WITH Customers.custcode
'ENDSCAN
'*!* alternate coding method:
'*!* SELECT Customers
'*!* REPLACE ALL custcode WITH LEFT(customername,4) + STR(customerid,4)
Comment