home *** CD-ROM | disk | FTP | other *** search
- /*
- SetField.QuickFile
-
- Sets a field in all selected records to a constant value
- Prompts user for field and value and includes checking that
- the requested field name is valid
-
- Author: Alan Wigginton
- Date: March 1995
- */
-
- options results
-
- if ~open(console,"con:20/40/460/120/SetField","W") then
- do
- say "Could not open window"
- exit(20)
- end
-
- "query field fld" /* get all the field names in stem fld. */
-
- "setindex" /* get the current index name */
- ixname = result
-
- "query index ixfld '"ixname"'" /* get the index field names */
- if rc > 0 then
- call ErrorProc "Error getting index details"
-
- call writeln(console, "Set field to a constant value")
- call writeln(console, "- will update all records in the current index")
- call writeln(console, "Press RETURN with no value to exit")
-
- /*
- Get the field name. Keep trying until the user gets it right
- or they give up (RETURN with no data)
- */
-
- err = "Y"
- do while err = "Y"
- call writeln(console, "What is the field to be changed?")
- ReqFld = upper(readln(console))
- if ReqFld = "" then
- exit
- call CheckFld
- end
-
- /*
- Get the value to set the field to
- */
-
- call writeln(console, "Set" ReqFld "to what value")
- ReqVal = readln(console)
-
- /*
- Confirm operation and number of records to be updated
- */
-
- "numrecs" /* ask quickfile for the number of records */
- numrecs = result
-
- call writeln(console, "About to set" ReqFld "to" ReqVal)
- call writeln(console, "in" numrecs "records")
- call writeln(console, "Enter Y to continue")
- ans = upper(readln(console))
- if ans ~= "Y" then
- do
- call writeln(console, "Request cancelled - press any key")
- ans = readln(console)
- exit
- end
-
- "next -32000" /* This goes to top of file */
-
- /*
- Change all the records
- */
-
- count = 0
- eof = "N"
- do while eof = "N"
- "putfield '"ReqFld"' '"ReqVal"'"
- if rc > 0 then
- do
- call writeln(console, "Error from putfield after")
- call ErrorProc count "records updated"
- end
- "updrec" /* commit the update record */
- if rc > 0 then
- call ErrorProc "Error updating record"
- count = count + 1
- "next"
- if rc > 0 then
- eof = "Y"
- end
-
- /*
- Tell the user that we completed it OK
- */
-
- call writeln(console, count "records updated")
- call writeln(console, "Press RETURN to continue")
- ans = readln(console)
- exit
-
-
- /*
- Check that the field name is valid
- */
-
- CheckFld:
-
- do i = 1 to fld.0
- if ReqFld = fld.i then
- do
- err = "N"
- return
- end
- end
-
- call writeln(console, ReqFld "is unknown")
-
- return
-
-
- /*
- Display error message and exit
- ------------------------------
- */
-
- ErrorProc:
-
- arg errmsg
-
- call writeln(console, errmsg)
- call writeln(console, "Press RETURN to continue")
- ans = readln(console)
- exit(10)
-
-